From 6b151535488877b00ccf9a80aac571f953f2bec3 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 23 Aug 2016 14:53:46 +0300 Subject: [PATCH] always mark this pass as up-to-date after apply; use dirty region LINE_MARKERS for LineMarkerPass to avoid confusion when GHP is finished and applied but LMP doesn't start because region was marked up-to-date already. --- .../daemon/impl/DaemonRespondToChangesTest.java | 8 +++++--- .../codeInsight/daemon/impl/FileStatusMap.java | 3 ++- .../daemon/impl/LineMarkersPassFactory.java | 11 +++-------- .../codeInsight/daemon/impl/PassExecutorService.java | 10 +++++++--- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java index 302c04d6f9bf..df510db52958 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java @@ -126,6 +126,7 @@ import com.intellij.util.io.storage.HeavyProcessLatch; import com.intellij.util.ui.UIUtil; import com.intellij.xml.util.CheckDtdReferencesInspection; import gnu.trove.THashSet; +import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -1423,10 +1424,11 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase { public void testLIPGetAllParentsAfterCodeBlockModification() throws Throwable { + @Language("JAVA") String text = "class LQF {\n" + " int f;\n" + " public void me() {\n" + - " \n" + + " //\n" + " }\n" + "}"; configureByText(StdFileTypes.JAVA, text); @@ -1476,12 +1478,12 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase { // inside code block modification visitedElements.clear(); - type("//"); + backspace(); + backspace(); infos = highlightErrors(); assertEmpty(infos); - PsiMethod method = ((PsiJavaFile)myFile).getClasses()[0].getMethods()[0]; List methodAndParents = CollectHighlightsUtil.getElementsInRange(myFile, method.getTextRange().getStartOffset(), method.getTextRange().getEndOffset(), true); diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java index a0c28fa315e9..27637611f0b5 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -107,6 +107,7 @@ public class FileStatusMap implements Disposable { setDirtyScope(Pass.UPDATE_ALL, WHOLE_FILE_DIRTY_MARKER); setDirtyScope(Pass.EXTERNAL_TOOLS, WHOLE_FILE_DIRTY_MARKER); setDirtyScope(Pass.LOCAL_INSPECTIONS, WHOLE_FILE_DIRTY_MARKER); + setDirtyScope(Pass.LINE_MARKERS, WHOLE_FILE_DIRTY_MARKER); TextEditorHighlightingPassRegistrarEx registrar = (TextEditorHighlightingPassRegistrarEx) TextEditorHighlightingPassRegistrar.getInstance(project); for(DirtyScopeTrackingHighlightingPassFactory factory: registrar.getDirtyScopeTrackingFactories()) { setDirtyScope(factory.getPassId(), WHOLE_FILE_DIRTY_MARKER); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPassFactory.java index 63a472e94744..b1fa2327047d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPassFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,19 +51,14 @@ public class LineMarkersPassFactory extends AbstractProjectComponent implements @Override @Nullable public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor editor) { - TextRange restrictRange = calculateRangeToProcessForSyntaxPass(editor); + TextRange restrictRange = FileStatusMap.getDirtyTextRange(editor, Pass.LINE_MARKERS); Document document = editor.getDocument(); if (restrictRange == null) return new ProgressableTextEditorHighlightingPass.EmptyPass(myProject, document); ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor); return new LineMarkersPass(myProject, file, document, expandRangeToCoverWholeLines(document, visibleRange), expandRangeToCoverWholeLines(document, restrictRange)); } - @Nullable - private static TextRange calculateRangeToProcessForSyntaxPass(Editor editor) { - return FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL); - } - - static TextRange expandRangeToCoverWholeLines(@NotNull Document document, TextRange textRange) { + private static TextRange expandRangeToCoverWholeLines(@NotNull Document document, TextRange textRange) { if (textRange == null) return null; return MarkupModelImpl.roundToLineBoundaries(document, textRange.getStartOffset(), textRange.getEndOffset()); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java index c8b99538c5cd..6bb31fe38995 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -492,10 +492,15 @@ class PassExecutorService implements Disposable { log(updateProgress, pass, " is canceled during apply, sorry"); return; } + Document document = pass.getDocument(); try { if (fileEditor.getComponent().isDisplayable() || ApplicationManager.getApplication().isUnitTestMode()) { - log(updateProgress, pass, " Applied"); pass.applyInformationToEditor(); + FileStatusMap fileStatusMap = DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap(); + if (document != null) { + fileStatusMap.markFileUpToDate(document, pass.getId()); + } + log(updateProgress, pass, " Applied"); } } catch (ProcessCanceledException e) { @@ -503,7 +508,6 @@ class PassExecutorService implements Disposable { throw e; } catch (RuntimeException e) { - Document document = pass.getDocument(); VirtualFile file = document == null ? null : FileDocumentManager.getInstance().getFile(document); FileType fileType = file == null ? null : file.getFileType(); String message = "Exception while applying information to " + fileEditor + "("+fileType+")";