Made JetPsiChecker aware of HTML diagnostics.
This commit is contained in:
@@ -30,6 +30,7 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.MultiRangeReference;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.xml.util.XmlStringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
@@ -152,9 +153,8 @@ public class JetPsiChecker implements Annotator {
|
||||
if (reference instanceof MultiRangeReference) {
|
||||
MultiRangeReference mrr = (MultiRangeReference)reference;
|
||||
for (TextRange range : mrr.getRanges()) {
|
||||
Annotation annotation = holder.createErrorAnnotation(
|
||||
range.shiftRight(referenceExpression.getTextOffset()),
|
||||
getMessage(diagnostic));
|
||||
Annotation annotation = holder.createErrorAnnotation(range.shiftRight(referenceExpression.getTextOffset()), getDefaultMessage(diagnostic));
|
||||
annotation.setTooltip(getMessage(diagnostic));
|
||||
|
||||
registerQuickFix(annotation, diagnostic);
|
||||
|
||||
@@ -163,7 +163,8 @@ public class JetPsiChecker implements Annotator {
|
||||
}
|
||||
else {
|
||||
for (TextRange textRange : textRanges) {
|
||||
Annotation annotation = holder.createErrorAnnotation(textRange, getMessage(diagnostic));
|
||||
Annotation annotation = holder.createErrorAnnotation(textRange, getDefaultMessage(diagnostic));
|
||||
annotation.setTooltip(getMessage(diagnostic));
|
||||
registerQuickFix(annotation, diagnostic);
|
||||
annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
|
||||
}
|
||||
@@ -174,9 +175,9 @@ public class JetPsiChecker implements Annotator {
|
||||
|
||||
if (diagnostic.getFactory() == Errors.ILLEGAL_ESCAPE_SEQUENCE) {
|
||||
for (TextRange textRange : diagnostic.getTextRanges()) {
|
||||
Annotation annotation = holder.createErrorAnnotation(textRange, getMessage(diagnostic));
|
||||
Annotation annotation = holder.createErrorAnnotation(textRange, getDefaultMessage(diagnostic));
|
||||
annotation.setTooltip(getMessage(diagnostic));
|
||||
annotation.setTextAttributes(JetHighlightingColors.INVALID_STRING_ESCAPE);
|
||||
//annotation.setEnforcedTextAttributes(TextAttributes.merge(JetHighlightingColors.INVALID_STRING_ESCAPE.getDefaultAttributes(), annotation.getTextAttributes().getDefaultAttributes()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -188,7 +189,8 @@ public class JetPsiChecker implements Annotator {
|
||||
|
||||
// Generic annotation
|
||||
for (TextRange textRange : textRanges) {
|
||||
Annotation errorAnnotation = holder.createErrorAnnotation(textRange, getMessage(diagnostic));
|
||||
Annotation errorAnnotation = holder.createErrorAnnotation(textRange, getDefaultMessage(diagnostic));
|
||||
errorAnnotation.setTooltip(getMessage(diagnostic));
|
||||
registerQuickFix(errorAnnotation, diagnostic);
|
||||
|
||||
if (diagnostic.getFactory() == Errors.INVISIBLE_REFERENCE) {
|
||||
@@ -198,7 +200,8 @@ public class JetPsiChecker implements Annotator {
|
||||
}
|
||||
else if (diagnostic.getSeverity() == Severity.WARNING) {
|
||||
for (TextRange textRange : textRanges) {
|
||||
Annotation annotation = holder.createWarningAnnotation(textRange, getMessage(diagnostic));
|
||||
Annotation annotation = holder.createWarningAnnotation(textRange, getDefaultMessage(diagnostic));
|
||||
annotation.setTooltip(getMessage(diagnostic));
|
||||
registerQuickFix(annotation, diagnostic);
|
||||
|
||||
if (diagnostic.getFactory() instanceof UnusedElementDiagnosticFactory) {
|
||||
@@ -240,7 +243,24 @@ public class JetPsiChecker implements Annotator {
|
||||
private static String getMessage(@NotNull Diagnostic diagnostic) {
|
||||
String message = IdeErrorMessages.RENDERER.render(diagnostic);
|
||||
if (ApplicationManager.getApplication().isInternal() || ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
return "[" + diagnostic.getFactory().getName() + "] " + message;
|
||||
String factoryName = diagnostic.getFactory().getName();
|
||||
if (message.startsWith("<html>")) {
|
||||
message = String.format("<html>[%s] %s", factoryName, message.substring("<html>".length()));
|
||||
} else {
|
||||
message = String.format("[%s] %s", factoryName, message);
|
||||
}
|
||||
}
|
||||
if (!message.startsWith("<html>")) {
|
||||
message = "<html><body>" + XmlStringUtil.escapeString(message) + "</body></html>";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getDefaultMessage(@NotNull Diagnostic diagnostic) {
|
||||
String message = DefaultErrorMessages.RENDERER.render(diagnostic);
|
||||
if (ApplicationManager.getApplication().isInternal() || ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
return String.format("[%s] %s", diagnostic.getFactory().getName(), message);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
@@ -252,6 +272,8 @@ public class JetPsiChecker implements Annotator {
|
||||
if (!redeclarations.add(redeclarationDiagnostic.getPsiElement())) return null;
|
||||
List<TextRange> textRanges = redeclarationDiagnostic.getTextRanges();
|
||||
if (textRanges.isEmpty()) return null;
|
||||
return holder.createErrorAnnotation(textRanges.get(0), getMessage(redeclarationDiagnostic));
|
||||
Annotation annotation = holder.createErrorAnnotation(textRanges.get(0), "");
|
||||
annotation.setTooltip(getMessage(redeclarationDiagnostic));
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user