Skip to content

Commit 30a3b9e

Browse files
joaodinissfrubenporras
authored andcommitted
fix: catch expected BadLocationException in LSPFoldingReconcilingStrategy
A document may be modified concurrently by multiple threads. This can cause `BadLocationException`s, which should not be logged unless the log trace is enabled for the LanguageServerPlugin. Follows a similar pattern to: eclipse-tm4e/tm4e#888
1 parent 06147b3 commit 30a3b9e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerPlugin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class LanguageServerPlugin extends AbstractUIPlugin {
4545
public static final Object FAMILY_INITIALIZE_LANGUAGE_SERVER = new Object();
4646

4747
public static final String PLUGIN_ID = "org.eclipse.lsp4e"; //$NON-NLS-1$
48+
private static final String TRACE_ID = PLUGIN_ID + "/trace"; //$NON-NLS-1$
4849

4950
public static final boolean DEBUG = Boolean.parseBoolean(Platform.getDebugOption("org.eclipse.lsp4e/debug")); //$NON-NLS-1$
5051

@@ -138,4 +139,13 @@ public static void logWarning(final @Nullable String message, final @Nullable Th
138139
}
139140
}
140141

142+
/**
143+
* Returns whether log trace is enabled for this plugin.
144+
*
145+
* @return true if the trace debug option is enabled, false otherwise
146+
*/
147+
public static boolean isLogTraceEnabled() {
148+
return Boolean.parseBoolean(Platform.getDebugOption(TRACE_ID));
149+
}
150+
141151
}

org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/folding/LSPFoldingReconcilingStrategy.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ && switch (foldingRange.getKind()) {
215215
updateAnnotation(deletions, existing, additions, foldingRange.getStartLine(),
216216
foldingRange.getEndLine(), collapsByDefault);
217217
} catch (BadLocationException ex) {
218-
LanguageServerPlugin.logError(ex);
218+
// This is an expected state, only log when tracing is enabled.
219+
if (LanguageServerPlugin.isLogTraceEnabled()) {
220+
LanguageServerPlugin.logError(ex);
221+
}
219222
}
220223
isFirstFoldingRange[0] = false;
221224
});

0 commit comments

Comments
 (0)