mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
import popup: show for editable files only, also without edits since esc of the same popup
but the caret must be on the unresolved reference (IDEA-CR-51560) GitOrigin-RevId: 98fadb9830717111c136dda23a6c9e268de43416
This commit is contained in:
committed by
intellij-monorepo-bot
parent
212ad27819
commit
0dff7db31b
@@ -416,7 +416,6 @@ public class ImportHelperTest extends LightDaemonAnalyzerTestCase {
|
||||
assertEmpty(((PsiJavaFile)getFile()).getImportList().getAllImportStatements());
|
||||
|
||||
caretRight();
|
||||
type(" ");
|
||||
|
||||
doHighlighting();
|
||||
|
||||
@@ -518,6 +517,7 @@ public class ImportHelperTest extends LightDaemonAnalyzerTestCase {
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
|
||||
|
||||
try {
|
||||
type(" ");
|
||||
List<HighlightInfo> errs = highlightErrors();
|
||||
assertEmpty(errs);
|
||||
|
||||
|
||||
+12
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeHighlighting.TextEditorHighlightingPass;
|
||||
import com.intellij.codeInsight.daemon.DaemonBundle;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
@@ -40,6 +41,7 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass {
|
||||
|
||||
private final int myStartOffset;
|
||||
private final int myEndOffset;
|
||||
private final boolean hasDirtyTextRange;
|
||||
|
||||
ShowAutoImportPass(@NotNull Project project, @NotNull final PsiFile file, @NotNull Editor editor) {
|
||||
super(project, editor.getDocument(), false);
|
||||
@@ -52,6 +54,8 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass {
|
||||
myEndOffset = range.getEndOffset();
|
||||
|
||||
myFile = file;
|
||||
|
||||
hasDirtyTextRange = FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,7 +76,7 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass {
|
||||
|
||||
int caretOffset = myEditor.getCaretModel().getOffset();
|
||||
importUnambiguousImports(caretOffset);
|
||||
List<HighlightInfo> visibleHighlights = getVisibleHighlights(myStartOffset, myEndOffset, myProject, myEditor);
|
||||
List<HighlightInfo> visibleHighlights = getVisibleHighlights(myStartOffset, myEndOffset, myProject, myEditor, hasDirtyTextRange);
|
||||
|
||||
for (int i = visibleHighlights.size() - 1; i >= 0; i--) {
|
||||
HighlightInfo info = visibleHighlights.get(i);
|
||||
@@ -115,9 +119,15 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass {
|
||||
private static List<HighlightInfo> getVisibleHighlights(final int startOffset,
|
||||
final int endOffset,
|
||||
@NotNull Project project,
|
||||
@NotNull Editor editor) {
|
||||
@NotNull Editor editor,
|
||||
boolean isDirty) {
|
||||
final List<HighlightInfo> highlights = new ArrayList<>();
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
DaemonCodeAnalyzerEx.processHighlights(editor.getDocument(), project, null, startOffset, endOffset, info -> {
|
||||
//no changes after escape => suggest imports under caret only
|
||||
if (!isDirty && !info.getFixTextRange().contains(offset)) {
|
||||
return true;
|
||||
}
|
||||
if (info.hasHint() && !editor.getFoldingModel().isOffsetCollapsed(info.startOffset)) {
|
||||
highlights.add(info);
|
||||
}
|
||||
|
||||
+1
-7
@@ -2,10 +2,8 @@
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeHighlighting.*;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -19,10 +17,6 @@ final class ShowAutoImportPassFactory implements TextEditorHighlightingPassFacto
|
||||
@Override
|
||||
@Nullable
|
||||
public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor editor) {
|
||||
if (BaseIntentionAction.canModify(file)) {
|
||||
TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL);
|
||||
return textRange != null ? new ShowAutoImportPass(file.getProject(), file, editor) : null;
|
||||
}
|
||||
return null;
|
||||
return DaemonListeners.canChangeFileSilently(file) ? new ShowAutoImportPass(file.getProject(), file, editor) : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user