Web Inspector: Improve debugger highlight when inside of getter/setter calls
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Oct 2016 23:04:04 +0000 (23:04 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Oct 2016 23:04:04 +0000 (23:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163428
<rdar://problem/28769061>

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-10-14
Reviewed by Timothy Hatcher.

* UserInterface/Views/SourceCodeTextEditor.js:
(WebInspector.SourceCodeTextEditor.prototype.textEditorExecutionHighlightRange):
When in the middle of a member expression at a '.' or '[' get the best member
expression range.

* UserInterface/Views/TextEditor.js:
(WebInspector.TextEditor.prototype._updateExecutionRangeHighlight):
Include the character at the current position. This is useful since AST Nodes
don't give us token info but we would like to know if we are at particular tokens.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207358 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js
Source/WebInspectorUI/UserInterface/Views/TextEditor.js

index 2289301..6ac4b9e 100644 (file)
@@ -1,5 +1,23 @@
 2016-10-14  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: Improve debugger highlight when inside of getter/setter calls
+        https://bugs.webkit.org/show_bug.cgi?id=163428
+        <rdar://problem/28769061>
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/SourceCodeTextEditor.js:
+        (WebInspector.SourceCodeTextEditor.prototype.textEditorExecutionHighlightRange):
+        When in the middle of a member expression at a '.' or '[' get the best member
+        expression range.
+
+        * UserInterface/Views/TextEditor.js:
+        (WebInspector.TextEditor.prototype._updateExecutionRangeHighlight):
+        Include the character at the current position. This is useful since AST Nodes
+        don't give us token info but we would like to know if we are at particular tokens.
+
+2016-10-14  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: Unused Breakpoint getter/setter for "id" - should be "identifier"
         https://bugs.webkit.org/show_bug.cgi?id=163395
 
index 2202208..9098d06 100644 (file)
@@ -1215,7 +1215,7 @@ WebInspector.SourceCodeTextEditor = class SourceCodeTextEditor extends WebInspec
         this._reinsertAllIssues();
     }
 
-    textEditorExecutionHighlightRange(offset, position, callback)
+    textEditorExecutionHighlightRange(offset, position, characterAtOffset, callback)
     {
         let script = this._getAssociatedScript(position);
         if (!script) {
@@ -1283,6 +1283,8 @@ WebInspector.SourceCodeTextEditor = class SourceCodeTextEditor extends WebInspec
                 return aLength - bLength;
             });
 
+            let characterAtOffsetIsDotOrBracket = characterAtOffset === "." || characterAtOffset === "[";
+
             for (let i = 0; i < nodes.length; ++i) {
                 let node = nodes[i];
 
@@ -1293,14 +1295,38 @@ WebInspector.SourceCodeTextEditor = class SourceCodeTextEditor extends WebInspec
                     return;
                 }
 
-                // In the middle of a member expression.
+                // In the middle of a member expression we want to highlight the best
+                // member expression range. We can end up in the middle when we are
+                // paused inside of a getter and select the parent call frame. For
+                // these cases we may be at a '.' or '[' and we can find the best member
+                // expression from there.
+                //
+                // Examples:
+                //
+                //     foo*.x.y.z => inside x looking at parent call frame => |foo.x|.y.z
+                //     foo.x*.y.z => inside y looking at parent call frame => |foo.x.y|.z
+                //
+                //     foo*["x"]["y"]["z"] => inside x looking at parent call frame => |foo["x"]|["y"]["z"]
+                //     foo["x"]*["y"]["z"] => inside y looking at parent call frame => |foo["x"]["y"]|["z"]
+                //
                 if (node.type === WebInspector.ScriptSyntaxTree.NodeType.ThisExpression
-                    || node.type === WebInspector.ScriptSyntaxTree.NodeType.IdentifierExpression) {
-                    let nextNode = nodes[i + 1];
-                    if (nextNode && nextNode.type === WebInspector.ScriptSyntaxTree.NodeType.MemberExpression) {
-                        callback(convertRangeOffsetsToSourceCodeOffsets(nextNode.range));
+                    || (characterAtOffsetIsDotOrBracket && (node.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier || node.type === WebInspector.ScriptSyntaxTree.NodeType.MemberExpression))) {
+                    let memberExpressionNode = null;
+                    for (let j = i + 1; j < nodes.length; ++j) {
+                        let nextNode = nodes[j];
+                        if (nextNode.type === WebInspector.ScriptSyntaxTree.NodeType.MemberExpression) {
+                            memberExpressionNode = nextNode;
+                            if (offset === memberExpressionNode.range[1])
+                                continue;
+                        }
+                        break;
+                    }
+
+                    if (memberExpressionNode) {
+                        callback(convertRangeOffsetsToSourceCodeOffsets(memberExpressionNode.range));
                         return;
                     }
+
                     callback(convertRangeOffsetsToSourceCodeOffsets(node.range));
                     return;
                 }
index ba64cc3..51d1cf3 100644 (file)
@@ -1241,8 +1241,9 @@ WebInspector.TextEditor = class TextEditor extends WebInspector.View
         let originalOffset = this.currentPositionToOriginalOffset(currentPosition);
         let originalCodeMirrorPosition = this.currentPositionToOriginalPosition(currentPosition);
         let originalPosition = new WebInspector.SourceCodePosition(originalCodeMirrorPosition.line, originalCodeMirrorPosition.ch);
+        let characterAtOffset = this._codeMirror.getRange(currentPosition, {line: this._executionLineNumber, ch: this._executionColumnNumber + 1});
 
-        this._delegate.textEditorExecutionHighlightRange(originalOffset, originalPosition, (range) => {
+        this._delegate.textEditorExecutionHighlightRange(originalOffset, originalPosition, characterAtOffset, (range) => {
             let start, end;
             if (!range) {
                 // Highlight the rest of the line.