Flutter-intellij: Autoformat causes an exception

Created on 7 May 2019  Â·  15Comments  Â·  Source: flutter/flutter-intellij

Steps to Reproduce

Pressed Ctrl + L to reformat the code in a freshly open project

Version information

Android Studio 3.4 • Flutter plugin io.flutter 35.2.1 • Dart plugin 183.6270

Error getting Flutter sdk information.

Exception

null

java.lang.IndexOutOfBoundsException: Index out of range: 5373
    at com.intellij.util.text.ImmutableText.findLeaf(ImmutableText.java:234)
    at com.intellij.util.text.ImmutableText.charAt(ImmutableText.java:226)
    at com.intellij.openapi.editor.impl.DocumentImpl$1.charAt(DocumentImpl.java:101)
    at io.flutter.editor.WidgetIndentsHighlightingPass.computeLocation(WidgetIndentsHighlightingPass.java:682)
    at io.flutter.editor.WidgetIndentsHighlightingPass.buildWidgetDescriptors(WidgetIndentsHighlightingPass.java:709)
    at io.flutter.editor.WidgetIndentsHighlightingPass.buildWidgetDescriptors(WidgetIndentsHighlightingPass.java:742)
    at io.flutter.editor.WidgetIndentsHighlightingPass.buildWidgetDescriptors(WidgetIndentsHighlightingPass.java:742)
    at io.flutter.editor.WidgetIndentsHighlightingPass.buildWidgetDescriptors(WidgetIndentsHighlightingPass.java:742)
    at io.flutter.editor.WidgetIndentsHighlightingPass.buildWidgetDescriptors(WidgetIndentsHighlightingPass.java:742)
    at io.flutter.editor.WidgetIndentsHighlightingPass.setOutline(WidgetIndentsHighlightingPass.java:547)
    at io.flutter.editor.WidgetIndentsHighlightingPass.run(WidgetIndentsHighlightingPass.java:523)
    at io.flutter.editor.WidgetIndentsHighlightingPassFactory.runWidgetIndentsPass(WidgetIndentsHighlightingPassFactory.java:299)
    at io.flutter.editor.WidgetIndentsHighlightingPassFactory.lambda$createHighlightingPass$4(WidgetIndentsHighlightingPassFactory.java:270)
    at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:315)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:435)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:419)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:403)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
    at java.awt.EventQueue.access$500(EventQueue.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:715)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:755)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:704)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:391)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
bug

Most helpful comment

Unfortunately the repro would need to be included on the github bug for me to be able to view it. Let me try creating a custom intellij plugin build with the likely fix and then you can test if the fix works.

All 15 comments

If you have a source code file that reproduces the issue that would be very helpful.

Sure, please provide some contact information, I can send it to you.

Unfortunately the repro would need to be included on the github bug for me to be able to view it. Let me try creating a custom intellij plugin build with the likely fix and then you can test if the fix works.

flutter-intellij.zip
Please try this IntelliJ plugin build for Android Studio. I believe it fixes the issue along with related cases where guides could look strange after a large code edit.

We should merge our issues, [3455], I've now got the same exception
bild

flutter-intellij.zip
Please try this IntelliJ plugin build for Android Studio. I believe it fixes the issue along with related cases where guides could look strange after a large code edit.

A different exception appears:

Version information

Android Studio 3.4 • Flutter plugin io.flutter SNAPSHOT • Dart plugin 183.6270

Error getting Flutter sdk information.

Exception

null

java.lang.Throwable: Incorrect offsets: startOffset=6142, endOffset=6143, text length=6000
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:137)
    at com.intellij.openapi.editor.impl.DocumentImpl.createRangeMarker(DocumentImpl.java:523)
    at com.intellij.openapi.editor.Document.createRangeMarker(Document.java:243)
    at io.flutter.editor.OutlineLocation.track(OutlineLocation.java:101)
    at io.flutter.editor.WidgetIndentGuideDescriptor.trackLocations(WidgetIndentGuideDescriptor.java:69)
    at io.flutter.editor.WidgetIndentsHighlightingPass$WidgetCustomHighlighterRenderer.<init>(WidgetIndentsHighlightingPass.java:111)
    at io.flutter.editor.WidgetIndentsHighlightingPass.createHighlighter(WidgetIndentsHighlightingPass.java:772)
    at io.flutter.editor.WidgetIndentsHighlightingPass.lambda$doApplyIndentInformationToEditor$2(WidgetIndentsHighlightingPass.java:659)
    at com.intellij.util.DocumentUtil.executeInBulk(DocumentUtil.java:48)
    at io.flutter.editor.WidgetIndentsHighlightingPass.doApplyIndentInformationToEditor(WidgetIndentsHighlightingPass.java:657)
    at io.flutter.editor.WidgetIndentsHighlightingPass.setOutline(WidgetIndentsHighlightingPass.java:555)
    at io.flutter.editor.WidgetIndentsHighlightingPass.run(WidgetIndentsHighlightingPass.java:526)
    at io.flutter.editor.WidgetIndentsHighlightingPassFactory.runWidgetIndentsPass(WidgetIndentsHighlightingPassFactory.java:307)
    at io.flutter.editor.WidgetIndentsHighlightingPassFactory.lambda$createHighlightingPass$4(WidgetIndentsHighlightingPassFactory.java:272)
    at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:315)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:435)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:419)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:403)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
    at java.awt.EventQueue.access$500(EventQueue.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:715)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:755)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:704)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:391)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

I really wish I could see a repro of this issue to understand why the outline we are generating is going past the end of the document.
Here's a new build that should fix your issue. Let me know whether the UI guides look right with this fix or if it seems like some indent guides are in the wrong location.
flutter-intellij.zip

Seems like the exception is resolved but some indent guides look weird:
изображение

Ah. Your code is using very non-standard formatting.
What you are seeing is actually intended.
Notice that child: Column is indented 2 more spaces than its properties which I assume isn't what you intended. Once you fix your indentation the guides will look good. You can either indent content until the guides are to the left of their content or use dartfmt.
I would suggest adding trailing commas after every closing ) in your build method and then run dartfmt. That should make your indenting look great without requiring any manual work on your part.

Thanks, I'll try your suggestions, but this is already the result of the automatic formatting (didn't expect it to rely on commas that much).

Screen Shot 2019-05-07 at 2 13 20 PM
Make sure you format with dartfmt instead of the IntelliJ code formatter which is much more limited in what it will try to do.

Screen Shot 2019-05-07 at 2 13 20 PM
Make sure you format with dartfmt instead of the IntelliJ code formatter which is much more limited in what it will try to do.

Thanks! Also no exception after reformatting with dartfmt.

How do the guides look now that your code has gone through dartfmt?

изображение
Everything looks fine.

Fix has landed in master and will be available in the next bug fix release.

Was this page helpful?
0 / 5 - 0 ratings