mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
no more convert problem descriptors for injected element to host file range
because some quick fixes expected their injected elements back from descriptor.getPsiElement() and all they got was PsiFile and that upset them very much
This commit is contained in:
@@ -3,7 +3,6 @@ package com.intellij.psi.util;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -124,13 +123,6 @@ public class PsiTreeUtil {
|
||||
if (element1 == element2) return element1;
|
||||
PsiFile file1 = element1.getContainingFile();
|
||||
PsiFile file2 = element2.getContainingFile();
|
||||
if (file1 != null && file2 != null) {
|
||||
InjectedLanguageManager ilm = InjectedLanguageManager.getInstance(file1.getProject());
|
||||
if (ilm.isInjectedFragment(file1) != ilm.isInjectedFragment(file2)) {
|
||||
// injected and non-injected files have no common ancestor
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
PsiElement topLevel = file1 == file2 ? file1 : null;
|
||||
|
||||
|
||||
+2
-20
@@ -160,13 +160,9 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
}
|
||||
|
||||
private void addDescriptorsFromInjectedResults(@NotNull InspectionManager iManager, @NotNull GlobalInspectionContextImpl context) {
|
||||
InjectedLanguageManager ilManager = InjectedLanguageManager.getInstance(myProject);
|
||||
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
|
||||
|
||||
for (Map.Entry<PsiFile, List<InspectionResult>> entry : result.entrySet()) {
|
||||
PsiFile file = entry.getKey();
|
||||
if (file == getFile()) continue; // not injected
|
||||
DocumentWindow documentRange = (DocumentWindow)documentManager.getDocument(file);
|
||||
List<InspectionResult> resultList = entry.getValue();
|
||||
for (InspectionResult inspectionResult : resultList) {
|
||||
LocalInspectionToolWrapper toolWrapper = inspectionResult.tool;
|
||||
@@ -174,22 +170,8 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
PsiElement psiElement = descriptor.getPsiElement();
|
||||
if (psiElement == null) continue;
|
||||
if (SuppressionUtil.inspectionResultSuppressed(psiElement, toolWrapper.getTool())) continue;
|
||||
List<TextRange> editables = ilManager.intersectWithAllEditableFragments(file, ((ProblemDescriptorBase)descriptor).getTextRange());
|
||||
for (TextRange editable : editables) {
|
||||
TextRange hostRange = documentRange.injectedToHost(editable);
|
||||
QuickFix[] fixes = descriptor.getFixes();
|
||||
LocalQuickFix[] localFixes = null;
|
||||
if (fixes != null) {
|
||||
localFixes = new LocalQuickFix[fixes.length];
|
||||
for (int k = 0; k < fixes.length; k++) {
|
||||
QuickFix fix = fixes[k];
|
||||
localFixes[k] = (LocalQuickFix)fix;
|
||||
}
|
||||
}
|
||||
ProblemDescriptor patchedDescriptor = iManager.createProblemDescriptor(getFile(), hostRange, descriptor.getDescriptionTemplate(),
|
||||
descriptor.getHighlightType(), true, localFixes);
|
||||
addDescriptors(toolWrapper, patchedDescriptor, context);
|
||||
}
|
||||
|
||||
addDescriptors(toolWrapper, descriptor, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -14,6 +14,7 @@ import com.intellij.codeInspection.reference.RefManager;
|
||||
import com.intellij.codeInspection.reference.RefVisitor;
|
||||
import com.intellij.codeInspection.ui.util.SynchronizedBidiMultiMap;
|
||||
import com.intellij.configurationStore.JbXmlOutputter;
|
||||
import com.intellij.injected.editor.VirtualFileWindow;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -52,8 +53,8 @@ public class DefaultInspectionToolPresentation implements InspectionToolPresenta
|
||||
@NotNull private final GlobalInspectionContextImpl myContext;
|
||||
protected InspectionNode myToolNode;
|
||||
|
||||
protected final SynchronizedBidiMultiMap<RefEntity, CommonProblemDescriptor> myProblemElements = createBidiMap();
|
||||
protected final SynchronizedBidiMultiMap<RefEntity, CommonProblemDescriptor> mySuppressedElements = createBidiMap();
|
||||
private final SynchronizedBidiMultiMap<RefEntity, CommonProblemDescriptor> myProblemElements = createBidiMap();
|
||||
private final SynchronizedBidiMultiMap<RefEntity, CommonProblemDescriptor> mySuppressedElements = createBidiMap();
|
||||
private final SynchronizedBidiMultiMap<RefEntity, CommonProblemDescriptor> myResolvedElements = createBidiMap();
|
||||
private final SynchronizedBidiMultiMap<RefEntity, CommonProblemDescriptor> myExcludedElements = createBidiMap();
|
||||
|
||||
@@ -348,7 +349,7 @@ public class DefaultInspectionToolPresentation implements InspectionToolPresenta
|
||||
}
|
||||
}
|
||||
|
||||
protected void exportResult(@NotNull RefEntity refEntity, @NotNull CommonProblemDescriptor descriptor, @NotNull Element element) {
|
||||
private void exportResult(@NotNull RefEntity refEntity, @NotNull CommonProblemDescriptor descriptor, @NotNull Element element) {
|
||||
final PsiElement psiElement = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor)descriptor).getPsiElement() : null;
|
||||
|
||||
@NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
|
||||
@@ -512,7 +513,7 @@ public class DefaultInspectionToolPresentation implements InspectionToolPresenta
|
||||
};
|
||||
}
|
||||
|
||||
public static SynchronizedBidiMultiMap<RefEntity, CommonProblemDescriptor> createBidiMap() {
|
||||
private static SynchronizedBidiMultiMap<RefEntity, CommonProblemDescriptor> createBidiMap() {
|
||||
return new SynchronizedBidiMultiMap<RefEntity, CommonProblemDescriptor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -531,6 +532,7 @@ public class DefaultInspectionToolPresentation implements InspectionToolPresenta
|
||||
StreamEx.of(descriptors).select(ProblemDescriptorBase.class).forEach(d -> {
|
||||
VirtualFile file = d.getContainingFile();
|
||||
if (file != null) {
|
||||
if (file instanceof VirtualFileWindow) file = ((VirtualFileWindow)file).getDelegate();
|
||||
LOG.assertTrue(file.equals(entityFile), "descriptor and containing entity files should be the same; descriptor: " + d.getDescriptionTemplate());
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user