more precise external annotation range for multiline elements (PY-8614)

This commit is contained in:
Dmitry Jemerov
2013-01-30 18:52:58 +01:00
parent 8f7282751e
commit 2da6abfa09
@@ -17,6 +17,7 @@ import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
@@ -155,16 +156,20 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
}
}
if (problemElement != null) {
TextRange problemRange = problemElement.getTextRange();
if (StringUtil.offsetToLineNumber(text, problemRange.getStartOffset()) != StringUtil.offsetToLineNumber(text, problemRange.getEndOffset())) {
problemRange = new TextRange(offset, StringUtil.lineColToOffset(text, problem.myLine, 0)-1);
}
final Annotation annotation;
final String message = "PEP 8: " + problem.myDescription;
if (annotationResult.level == HighlightDisplayLevel.ERROR) {
annotation = holder.createErrorAnnotation(problemElement, message);
annotation = holder.createErrorAnnotation(problemRange, message);
}
else if (annotationResult.level == HighlightDisplayLevel.WARNING) {
annotation = holder.createWarningAnnotation(problemElement, message);
annotation = holder.createWarningAnnotation(problemRange, message);
}
else {
annotation = holder.createWeakWarningAnnotation(problemElement, message);
annotation = holder.createWeakWarningAnnotation(problemRange, message);
}
annotation.registerUniversalFix(new ReformatFix(), null, null);
annotation.registerFix(new IgnoreErrorFix(problem.myCode, annotationResult.ignoredErrors));