simplify execution point highlighting pycharm/142.2525
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Tue, 16 Jun 2015 15:44:48 +0000 (18:44 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Tue, 16 Jun 2015 15:47:31 +0000 (18:47 +0300)
java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java
java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/ExecutionPointHighlighter.java

index 2ed9b5283ada45664e4b2466f23aa622d26f0945..da915026b9d3acec9fc0eccc4ddfbf2f02622d7b 100644 (file)
@@ -27,10 +27,6 @@ import com.intellij.execution.filters.LineNumbersMapping;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.impl.DocumentMarkupModel;
-import com.intellij.openapi.editor.markup.HighlighterTargetArea;
-import com.intellij.openapi.editor.markup.RangeHighlighter;
-import com.intellij.openapi.editor.markup.TextAttributes;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.*;
 import com.intellij.openapi.util.text.StringUtil;
@@ -42,7 +38,6 @@ import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.containers.EmptyIterable;
 import com.intellij.xdebugger.impl.ui.ExecutionPointHighlighter;
-import com.intellij.xdebugger.ui.DebuggerColors;
 import com.sun.jdi.AbsentInformationException;
 import com.sun.jdi.Location;
 import com.sun.jdi.Method;
@@ -286,20 +281,11 @@ public class PositionManagerImpl implements PositionManager, MultiRequestPositio
 
     @Nullable
     @Override
-    public RangeHighlighter createHighlighter(Document document, Project project, TextAttributes attributes) {
+    public TextRange getHighlightRange() {
       PsiElement element = getElementAt();
       NavigatablePsiElement method = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiLambdaExpression.class);
       if (method instanceof PsiLambdaExpression) {
-        TextRange range = method.getTextRange();
-        int startOffset = document.getLineStartOffset(getLine());
-        int endOffset = document.getLineEndOffset(getLine());
-        int hlStart = Math.max(startOffset, range.getStartOffset());
-        int hlEnd = Math.min(endOffset, range.getEndOffset());
-        if (hlStart != startOffset || hlEnd != endOffset) {
-          return DocumentMarkupModel.forDocument(document, project, true).
-            addRangeHighlighter(hlStart, hlEnd, DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes,
-                                HighlighterTargetArea.EXACT_RANGE);
-        }
+        return method.getTextRange();
       }
       return null;
     }
index 8ad0f30c03c09a0143d067dfda51499b235fc7ce..608e43c9adb92b61a1b93d3de43f56c6415acf45 100644 (file)
@@ -46,8 +46,6 @@ import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.markup.RangeHighlighter;
-import com.intellij.openapi.editor.markup.TextAttributes;
 import com.intellij.openapi.fileEditor.OpenFileDescriptor;
 import com.intellij.openapi.fileTypes.FileType;
 import com.intellij.openapi.fileTypes.StdFileTypes;
@@ -752,9 +750,9 @@ public abstract class DebuggerUtilsEx extends DebuggerUtils {
 
     @Nullable
     @Override
-    public RangeHighlighter createHighlighter(Document document, Project project, TextAttributes attributes) {
+    public TextRange getHighlightRange() {
       if (mySourcePosition instanceof ExecutionPointHighlighter.HighlighterProvider) {
-        return ((ExecutionPointHighlighter.HighlighterProvider)mySourcePosition).createHighlighter(document, project, attributes);
+        return ((ExecutionPointHighlighter.HighlighterProvider)mySourcePosition).getHighlightRange();
       }
       return null;
     }
index 269665ef7c80b5bce6d3bd410f62ee2a4456fd4e..66a362779492bce2e27327e16bfc6c259716815d 100644 (file)
@@ -24,14 +24,14 @@ import com.intellij.openapi.editor.colors.EditorColorsManager;
 import com.intellij.openapi.editor.colors.EditorColorsScheme;
 import com.intellij.openapi.editor.impl.DocumentMarkupModel;
 import com.intellij.openapi.editor.impl.EditorImpl;
-import com.intellij.openapi.editor.markup.GutterIconRenderer;
-import com.intellij.openapi.editor.markup.RangeHighlighter;
-import com.intellij.openapi.editor.markup.TextAttributes;
+import com.intellij.openapi.editor.markup.*;
 import com.intellij.openapi.fileEditor.OpenFileDescriptor;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.ui.AppUIUtil;
+import com.intellij.util.DocumentUtil;
 import com.intellij.xdebugger.XSourcePosition;
 import com.intellij.xdebugger.impl.XDebuggerUtilImpl;
 import com.intellij.xdebugger.impl.XSourcePositionImpl;
@@ -202,13 +202,21 @@ public class ExecutionPointHighlighter {
 
     EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
     TextAttributes attributes = myNotTopFrame ? scheme.getAttributes(DebuggerColors.NOT_TOP_FRAME_ATTRIBUTES)
-                                : scheme.getAttributes(DebuggerColors.EXECUTIONPOINT_ATTRIBUTES);
+                                              : scheme.getAttributes(DebuggerColors.EXECUTIONPOINT_ATTRIBUTES);
+    MarkupModel markupModel = DocumentMarkupModel.forDocument(document, myProject, true);
     if (mySourcePosition instanceof HighlighterProvider) {
-      myRangeHighlighter = ((HighlighterProvider)mySourcePosition).createHighlighter(document, myProject, attributes);
+      TextRange range = ((HighlighterProvider)mySourcePosition).getHighlightRange();
+      if (range != null) {
+        range = range.intersection(DocumentUtil.getLineTextRange(document, line));
+        if (range != null && !range.isEmpty()) {
+          myRangeHighlighter = markupModel.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(),
+                                                               DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes,
+                                                               HighlighterTargetArea.EXACT_RANGE);
+        }
+      }
     }
     if (myRangeHighlighter == null) {
-      myRangeHighlighter = DocumentMarkupModel.forDocument(document, myProject, true).
-          addLineHighlighter(line, DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes);
+      myRangeHighlighter = markupModel.addLineHighlighter(line, DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes);
     }
     myRangeHighlighter.putUserData(EXECUTION_POINT_HIGHLIGHTER_KEY, true);
     myRangeHighlighter.setGutterIconRenderer(myGutterIconRenderer);
@@ -231,6 +239,6 @@ public class ExecutionPointHighlighter {
 
   public interface HighlighterProvider {
     @Nullable
-    RangeHighlighter createHighlighter(Document document, Project project, TextAttributes attributes);
+    TextRange getHighlightRange();
   }
 }