diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/DocumentLifeCycleHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/DocumentLifeCycleHandler.java index f467531a2c..399f208c79 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/DocumentLifeCycleHandler.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/DocumentLifeCycleHandler.java @@ -98,16 +98,19 @@ public boolean belongsTo(Object family) { } private void triggerValidation(ICompilationUnit cu) throws JavaModelException { + triggerValidation(cu, 400); + } + + private void triggerValidation(ICompilationUnit cu, long delay) throws JavaModelException { synchronized (toReconcile) { toReconcile.add(cu); } if (validationTimer != null) { validationTimer.cancel(); - validationTimer.schedule(400); + validationTimer.schedule(delay); } else { performValidation(new NullProgressMonitor()); } - } private IStatus performValidation(IProgressMonitor monitor) throws JavaModelException { @@ -282,7 +285,7 @@ public void handleChanged(DidChangeTextDocumentParams params) { IDocument document = JsonRpcHelpers.toDocument(unit.getBuffer()); edit.apply(document, TextEdit.NONE); } - triggerValidation(unit); + triggerValidation(unit, 0); } catch (JavaModelException | MalformedTreeException | BadLocationException e) { JavaLanguageServerPlugin.logException("Error while handling document change", e); } diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java index bc643d91cd..d474b16c77 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java @@ -475,6 +475,22 @@ public void didOpen(DidOpenTextDocumentParams params) { @Override public void didChange(DidChangeTextDocumentParams params) { logInfo(">> document/didChange"); + try { + Job[] jobs = Job.getJobManager().find(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS); + boolean wait = jobs.length > 0; + long start = System.currentTimeMillis(); + while (wait) { + jobs = Job.getJobManager().find(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS); + wait = (System.currentTimeMillis() - start) < 1000 && jobs.length > 0; + if (wait) { + Thread.sleep(100); + } + } + } catch (OperationCanceledException ignorable) { + // No need to pollute logs when query is cancelled + } catch (InterruptedException e) { + JavaLanguageServerPlugin.logException(e.getMessage(), e); + } documentLifeCycleHandler.didChange(params); }