use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project scss-lint-plugin by idok.
the class ScssLintAnnotationResult method getHighlightDisplayKeyByClass.
@NotNull
public static HighlightDisplayKey getHighlightDisplayKeyByClass() {
String id = "ScssLint";
HighlightDisplayKey key = HighlightDisplayKey.find(id);
if (key == null) {
key = new HighlightDisplayKey(id, id);
}
return key;
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project scss-lint-plugin by idok.
the class ScssLintAnnotationResult method apply.
@Override
public void apply(@NotNull PsiFile file, ScssLintAnnotationResult annotationResult, @NotNull AnnotationHolder holder) {
if (annotationResult == null) {
return;
}
InspectionProjectProfileManager inspectionProjectProfileManager = InspectionProjectProfileManager.getInstance(file.getProject());
SeverityRegistrar severityRegistrar = inspectionProjectProfileManager.getSeverityRegistrar();
HighlightDisplayKey inspectionKey = getHighlightDisplayKeyByClass();
EditorColorsScheme colorsScheme = annotationResult.input.colorsScheme;
Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if (document == null) {
return;
}
if (annotationResult.fileLevel != null) {
Annotation annotation = holder.createWarningAnnotation(file, annotationResult.fileLevel);
annotation.registerFix(new EditSettingsAction(new ScssLintSettingsPage(file.getProject())));
annotation.setFileLevelAnnotation(true);
return;
}
// TODO consider adding a fix to edit configuration file
if (annotationResult.result == null || annotationResult.result.lint == null || annotationResult.result.lint.isEmpty()) {
return;
}
// String relativeFile = FileUtils.makeRelative(file.getProject(), file.getVirtualFile());
List<Lint.Issue> issues = annotationResult.result.lint.values().iterator().next();
if (issues == null) {
return;
}
ScssLintProjectComponent component = annotationResult.input.project.getComponent(ScssLintProjectComponent.class);
int tabSize = 4;
for (Lint.Issue issue : issues) {
HighlightSeverity severity = getHighlightSeverity(issue, component.treatAsWarnings);
TextAttributes forcedTextAttributes = AnnotatorUtils.getTextAttributes(colorsScheme, severityRegistrar, severity);
Annotation annotation = createAnnotation(holder, file, document, issue, "SCSS Lint: ", tabSize, severity, forcedTextAttributes, inspectionKey, false);
if (annotation != null) {
int offset = StringUtil.lineColToOffset(document.getText(), issue.line - 1, issue.column);
PsiElement lit = PsiUtil.getElementAtOffset(file, offset);
BaseActionFix actionFix = Fixes.getFixForRule(issue.linter, lit);
if (actionFix != null) {
annotation.registerFix(actionFix, null, inspectionKey);
}
// annotation.registerFix(new SuppressActionFix(issue.rule, lit), null, inspectionKey);
}
}
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project intellij-community by JetBrains.
the class RegExpInspectionTestCase method highlightTest.
protected void highlightTest(@Language("RegExp") String code) {
final LocalInspectionTool inspection = getInspection();
myFixture.enableInspections(inspection);
final HighlightDisplayKey displayKey = HighlightDisplayKey.find(inspection.getShortName());
if (displayKey != null) {
final Project project = myFixture.getProject();
final InspectionProfileImpl currentProfile = ProjectInspectionProfileManager.getInstance(project).getCurrentProfile();
final HighlightDisplayLevel errorLevel = currentProfile.getErrorLevel(displayKey, null);
if (errorLevel == HighlightDisplayLevel.DO_NOT_SHOW) {
currentProfile.setErrorLevel(displayKey, HighlightDisplayLevel.WARNING, project);
}
}
myFixture.configureByText(RegExpFileType.INSTANCE, code);
myFixture.testHighlighting();
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project android by JetBrains.
the class AndroidLintExternalAnnotator method apply.
@Override
public void apply(@NotNull PsiFile file, State state, @NotNull AnnotationHolder holder) {
if (state.isDirty()) {
return;
}
final Project project = file.getProject();
if (DumbService.isDumb(project))
return;
for (ProblemData problemData : state.getProblems()) {
final Issue issue = problemData.getIssue();
final String message = problemData.getMessage();
final TextRange range = problemData.getTextRange();
if (range.getStartOffset() == range.getEndOffset()) {
continue;
}
final Pair<AndroidLintInspectionBase, HighlightDisplayLevel> pair = AndroidLintUtil.getHighlighLevelAndInspection(project, issue, file);
if (pair == null) {
continue;
}
final AndroidLintInspectionBase inspection = pair.getFirst();
HighlightDisplayLevel displayLevel = pair.getSecond();
if (inspection != null) {
final HighlightDisplayKey key = HighlightDisplayKey.find(inspection.getShortName());
if (key != null) {
final PsiElement startElement = file.findElementAt(range.getStartOffset());
final PsiElement endElement = file.findElementAt(range.getEndOffset() - 1);
if (startElement != null && endElement != null && !inspection.isSuppressedFor(startElement)) {
if (problemData.getConfiguredSeverity() != null) {
HighlightDisplayLevel configuredLevel = AndroidLintInspectionBase.toHighlightDisplayLevel(problemData.getConfiguredSeverity());
if (configuredLevel != null) {
displayLevel = configuredLevel;
}
}
final Annotation annotation = createAnnotation(holder, message, range, displayLevel, issue);
for (AndroidLintQuickFix fix : inspection.getQuickFixes(startElement, endElement, message)) {
if (fix.isApplicable(startElement, endElement, AndroidQuickfixContexts.EditorContext.TYPE)) {
annotation.registerFix(new MyFixingIntention(fix, startElement, endElement));
}
}
for (IntentionAction intention : inspection.getIntentions(startElement, endElement)) {
annotation.registerFix(intention);
}
String id = key.getID();
if (LintIdeIssueRegistry.CUSTOM_ERROR == issue || LintIdeIssueRegistry.CUSTOM_WARNING == issue) {
Issue original = LintIdeClient.findCustomIssue(message);
if (original != null) {
id = original.getId();
}
}
annotation.registerFix(new SuppressLintIntentionAction(id, startElement));
annotation.registerFix(new MyDisableInspectionFix(key));
annotation.registerFix(new MyEditInspectionToolsSettingsAction(key, inspection));
if (issue == DeprecationDetector.ISSUE || issue == GradleDetector.DEPRECATED) {
annotation.setHighlightType(ProblemHighlightType.LIKE_DEPRECATED);
}
if (INCLUDE_IDEA_SUPPRESS_ACTIONS) {
final SuppressQuickFix[] suppressActions = inspection.getBatchSuppressActions(startElement);
for (SuppressQuickFix action : suppressActions) {
if (action.isAvailable(project, startElement)) {
ProblemHighlightType type = annotation.getHighlightType();
annotation.registerFix(action, null, key, InspectionManager.getInstance(project).createProblemDescriptor(startElement, endElement, message, type, true, LocalQuickFix.EMPTY_ARRAY));
}
}
}
}
}
}
}
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project android by JetBrains.
the class AndroidLintExternalAnnotator method getIssuesFromInspections.
@NotNull
static List<Issue> getIssuesFromInspections(@NotNull Project project, @Nullable PsiElement context) {
final List<Issue> result = new ArrayList<>();
final IssueRegistry fullRegistry = new LintIdeIssueRegistry();
for (Issue issue : fullRegistry.getIssues()) {
final String inspectionShortName = AndroidLintInspectionBase.getInspectionShortNameByIssue(project, issue);
if (inspectionShortName == null) {
continue;
}
final HighlightDisplayKey key = HighlightDisplayKey.find(inspectionShortName);
if (key == null) {
continue;
}
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
final boolean enabled = context != null ? profile.isToolEnabled(key, context) : profile.isToolEnabled(key);
if (!enabled) {
continue;
} else if (!issue.isEnabledByDefault()) {
// If an issue is marked as not enabled by default, lint won't run it, even if it's in the set
// of issues provided by an issue registry. Since in the IDE we're enforcing the enabled-state via
// inspection profiles, mark the issue as enabled to allow users to turn on a lint check directly
// via the inspections UI.
issue.setEnabledByDefault(true);
}
result.add(issue);
}
return result;
}
Aggregations