eclipse-typescript
eclipse-typescript copied to clipboard
BadLocationException when 2 editors are open on the same file
Often I get exception below when trying to format file with Ctrl+Shift+F. What seems to help in such situation is to restart eclipse. After that it usually works OK. (not sure, but the problem might be related to having 2 editors open on the same file).
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.RuntimeException: org.eclipse.jface.text.BadLocationException) at org.eclipse.swt.SWT.error(SWT.java:4397) at org.eclipse.swt.SWT.error(SWT.java:4312) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4145) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3762) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:610) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591) at org.eclipse.equinox.launcher.Main.run(Main.java:1450) Caused by: java.lang.RuntimeException: org.eclipse.jface.text.BadLocationException at com.palantir.typescript.text.reconciler.PresentationReconciler.createPresentation(PresentationReconciler.java:228) at com.palantir.typescript.text.reconciler.PresentationReconciler.processEvent(PresentationReconciler.java:131) at com.palantir.typescript.text.reconciler.PresentationReconciler.access$0(PresentationReconciler.java:128) at com.palantir.typescript.text.reconciler.PresentationReconciler$MyTextListener.textChanged(PresentationReconciler.java:314) at org.eclipse.jface.text.TextViewer.updateTextListeners(TextViewer.java:2830) at org.eclipse.jface.text.TextViewer.invalidateTextPresentation(TextViewer.java:3501) at org.eclipse.jface.text.source.AnnotationPainter.invalidateTextPresentation(AnnotationPainter.java:972) at org.eclipse.jface.text.source.AnnotationPainter.updatePainting(AnnotationPainter.java:954) at org.eclipse.jface.text.source.AnnotationPainter.access$1(AnnotationPainter.java:948) at org.eclipse.jface.text.source.AnnotationPainter$1.run(AnnotationPainter.java:1087) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135) ... 23 more Caused by: org.eclipse.jface.text.BadLocationException at org.eclipse.jface.text.AbstractDocument.get(AbstractDocument.java:1038) at org.eclipse.core.internal.filebuffers.SynchronizableDocument.get(SynchronizableDocument.java:139) at com.palantir.typescript.text.reconciler.PresentationReconciler.classifyLines(PresentationReconciler.java:242) at com.palantir.typescript.text.reconciler.PresentationReconciler.createPresentation(PresentationReconciler.java:226) ... 34 more
Two editors open on the same file sounds like the likely culprit. How are you doing that? Eclipse + some other editor? Can you give some more specific repro steps?
menu - Window - New Editor
Oh interesting - two within eclipse. Just curious, what is the use case for doing that?
I have found how to reproduce it. It is quite easy:
- open bigger file
- open second editor on that file
- go to the middle of the file and add new line there (press Enter)
- after that Ctrl+click navigation is broken. This seems to be some related problem - some internal cursors (or something like that) become invalid.
Use cases:
- When writing some function similar to some other function in the same file
- When you want to see source of function/class you are using from the code you are just writing (e.g. what to pass as parameters, how to configure object). etc...
Cool, thanks for all the info. This will likely be fairly challenging to fix because it may require the language service to maintain separate information about the same file from each editor. That is tricky because the files are keyed by their file paths and those paths are used for resolution of imports when using AMD or CommonJS modules. So I'm not sure how one editor open on a specific file could communicate with the language service independent of another editor open on the same file (which I believe is part of the reason this is breaking currently).