[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 145c5d6 25/38: Fixed jumping to object properties
From: |
Dmitry Gutov |
Subject: |
[elpa] master 145c5d6 25/38: Fixed jumping to object properties |
Date: |
Wed, 09 Sep 2015 18:41:47 +0000 |
branch: master
commit 145c5d6153c9fa11e3da117eb96caacfef7106a9
Author: ScottyB <address@hidden>
Commit: ScottyB <address@hidden>
Fixed jumping to object properties
---
js2-mode.el | 74 +++++++++++++++++---------------------------------
tests/navigation.el | 12 ++++++--
2 files changed, 34 insertions(+), 52 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 56c98ac..cfcc302 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -12305,15 +12305,29 @@ it marks the next defun after the ones already
marked."
(ring-insert find-tag-marker-ring (point-marker))
(let* ((node (js2-node-at-point))
(parent (js2-node-parent node))
- (prop-names (if (js2-prop-get-node-p parent)
- (js2-prop-names-left node)))
- (name (if (and (js2-name-node-p node)
- (not (js2-object-prop-node-p parent)))
- (js2-name-node-name node)
- (error "Node is not a supported jump node")))
- (node-init (if (and prop-names (listp prop-names))
- (js2-find-property prop-names node)
- (js2-symbol-ast-node (js2-get-symbol-declaration node
name)))))
+ (prop-names (if (js2-prop-get-node-p parent)(reverse
(js2-prop-names-left node))))
+ (name (or (and prop-names (pop prop-names))
+ (unless (and (js2-object-prop-node-p parent)
+ (eq node (js2-object-prop-node-left parent)))
+ (js2-name-node-name node))
+ (error "Node is not a supported jump node")))
+ node-init)
+ (ignore-errors
+ (setq node-init (js2-symbol-ast-node (js2-get-symbol-declaration node
name)))
+ (when prop-names
+ (let ((found-node (js2-var-init-node-initializer (js2-node-parent
node-init))))
+ (setq node-init nil)
+ (when (js2-object-node-p found-node)
+ (js2-visit-ast
+ found-node
+ (lambda (node endp)
+ (unless endp
+ (when (and (js2-object-prop-node-p node)
+ (string= (car prop-names)
+ (js2-name-node-name
(js2-object-prop-node-left node))))
+ (pop prop-names)
+ (unless prop-names (setq node-init node)))
+ t)))))))
(unless node-init
(pop-tag-mark)
(error "No jump location found"))
@@ -12342,7 +12356,8 @@ points can be found for each property in the chain."
(if (js2-name-node-p node)
(push (js2-name-node-name node) names)
t))))
- names)))
+ names)
+ (if (listp names) names (list names))))
(defun js2-get-symbol-declaration (node name)
"Find definition for NAME from NODE."
@@ -12350,45 +12365,6 @@ points can be found for each property in the chain."
(or (js2-node-get-enclosing-scope node)
node) name) name))
-(defun js2-find-property (list-names node)
- "Find the property definition that consists of LIST-NAMES.
-Supports navigation to 'foo.bar = 3' and 'foo = {bar: 3}'. NODE
-is the node at point."
- (catch 'prop-found
- (js2-visit-ast-root
- js2-mode-ast ; todo: check for scope
- (lambda (node endp)
- (let ((parent (js2-node-parent node))
- matching-node)
- (unless endp
- (if (and (js2-name-node-p node)
- (setq matching-node (or
- (js2-build-prop-name-list node
list-names)
- (and (js2-object-prop-node-p parent)
- (string= (js2-name-node-name node)
- (first list-names))
- node))))
- (throw 'prop-found matching-node))
- t))
- )))
- )
-
-(defun js2-build-prop-name-list (name-node list-names)
- "Compare the names in NAME-NODE to the ones in LIST-NAMES.
-Returns the matching node to jump to or nil."
- (let ((list-names (reverse list-names))
- (next-prop (js2-node-parent name-node)))
- ;; check right side properties
- (when (string= (pop list-names)
- (js2-name-node-name name-node))
- ;; check left side properties
- (while (and list-names
- (js2-prop-get-node-p next-prop)
- (string= (pop list-names)
- (js2-name-node-name
- (setq next-prop (js2-prop-get-node-right
next-prop)))))))
- (unless list-names name-node)))
-
(provide 'js2-mode)
;;; js2-mode.el ends here
diff --git a/tests/navigation.el b/tests/navigation.el
index 6f94d7a..f07d466 100644
--- a/tests/navigation.el
+++ b/tests/navigation.el
@@ -28,7 +28,7 @@
(let ((start-point (or (- (point) point-offset))))
(js2-mode)
(goto-char start-point)
- (js2-jump-to-definition)
+ (ignore-errors (js2-jump-to-definition))
(print (format "%d %d" (point) start-point))
(should (= (point) (or expected-point start-point))))))
@@ -44,5 +44,11 @@
(ert-deftest js2-jump-to-object-property ()
(js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"};
aObject.prop1" 16))
-;; (ert-deftest js2-no-jump-to-object-property ()
-;; (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"};
anotherObject.dprop1"))
+(ert-deftest js2-no-jump-to-object-property ()
+ (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"};
anotherObject.prop1"))
+
+(ert-deftest js2-jump-to-nested-property ()
+ (js2-navigation-helper "var aObject = {prop1: {prop2: { prop3: 4}}};
aObject.prop3" 33))
+
+(ert-deftest js2-jump-to-object ()
+ (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"};
aObject.prop1" 5 13))
- [elpa] master c8b8e11 19/38: js2-define-destruct-symbols: Speed up, theoretically, (continued)
- [elpa] master c8b8e11 19/38: js2-define-destruct-symbols: Speed up, theoretically, Dmitry Gutov, 2015/09/09
- [elpa] master a6f2a94 15/38: Allow plain parameters after default, Dmitry Gutov, 2015/09/09
- [elpa] master d0686a0 18/38: js2-define-destruct-symbols-internal: Remove, don't need it anymore, Dmitry Gutov, 2015/09/09
- [elpa] master f146f13 17/38: js2-define-destruct-symbols-internal: Stop growing NAME-NODES exponentially, Dmitry Gutov, 2015/09/09
- [elpa] master eba59c5 21/38: Added missing etags dependency, Dmitry Gutov, 2015/09/09
- [elpa] master 7184664 20/38: Add a jump to definition command bound to M-., Dmitry Gutov, 2015/09/09
- [elpa] master bc5cdb4 23/38: Simplified property name matching, Dmitry Gutov, 2015/09/09
- [elpa] master 1ee5c45 22/38: Return correct node when searching for the definition of a property., Dmitry Gutov, 2015/09/09
- [elpa] master 579aacb 24/38: Simplified method of searching for nodes based on scope, Dmitry Gutov, 2015/09/09
- [elpa] master f942b83 26/38: Support jumping to buffers of the same major mode, Dmitry Gutov, 2015/09/09
- [elpa] master 145c5d6 25/38: Fixed jumping to object properties,
Dmitry Gutov <=
- [elpa] master bb0476c 29/38: Clarified js2-search-scope doc string, Dmitry Gutov, 2015/09/09
- [elpa] master c4f4095 28/38: Only jump if not already at var or function definition, Dmitry Gutov, 2015/09/09
- [elpa] master af85699 30/38: Clean up todo in js2-search-scope and fix year typo, Dmitry Gutov, 2015/09/09
- [elpa] master aaf218a 27/38: Find definition by locating assignment nodes, Dmitry Gutov, 2015/09/09
- [elpa] master e236923 31/38: Removed functions: js2-build-prop-name-list and js2-names-left., Dmitry Gutov, 2015/09/09
- [elpa] master 75129c1 33/38: Use cl-assert instead of error, Dmitry Gutov, 2015/09/09
- [elpa] master bbb5086 34/38: Remove a space, Dmitry Gutov, 2015/09/09
- [elpa] master 58335d4 36/38: Add NEWS and bump the version, Dmitry Gutov, 2015/09/09
- [elpa] master 9ad7708 32/38: Add cl- prefix, improve line lengths, Dmitry Gutov, 2015/09/09
- [elpa] master ffa06cb 35/38: Explicitly remap js-find-symbol, Dmitry Gutov, 2015/09/09