[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 579aacb 24/38: Simplified method of searching for nodes ba
From: |
Dmitry Gutov |
Subject: |
[elpa] master 579aacb 24/38: Simplified method of searching for nodes based on scope |
Date: |
Wed, 09 Sep 2015 18:41:46 +0000 |
branch: master
commit 579aacb69ff4598caa54e00642cd1b9e71a40405
Author: ScottyB <address@hidden>
Commit: ScottyB <address@hidden>
Simplified method of searching for nodes based on scope
---
js2-mode.el | 73 +++++++++++++++-----------------------------------
tests/navigation.el | 2 +-
2 files changed, 23 insertions(+), 52 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index ce95353..56c98ac 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -12312,8 +12312,8 @@ it marks the next defun after the ones already marked."
(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)
- (js2-name-declaration name))))
+ (js2-find-property prop-names node)
+ (js2-symbol-ast-node (js2-get-symbol-declaration node
name)))))
(unless node-init
(pop-tag-mark)
(error "No jump location found"))
@@ -12344,51 +12344,34 @@ points can be found for each property in the chain."
t))))
names)))
-(defun js2-find-property (list-names)
+(defun js2-get-symbol-declaration (node name)
+ "Find definition for NAME from NODE."
+ (js2-scope-get-symbol (js2-get-defining-scope
+ (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}'."
+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
+ 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))))
+ (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-name-declaration (name)
- "Return the declaration node for node named NAME."
- (let* ((node (js2-root-or-node))
- (scope-def (js2-get-defining-scope node name))
- (scope (if scope-def (js2-scope-get-symbol scope-def name) nil))
- (symbol (if scope (js2-symbol-ast-node scope) nil)))
- (if (not symbol)
- (js2-get-function-node name scope-def)
- symbol)))
-
-(defun js2-get-function-name (fn-node)
- "Return the name of the function FN-NODE.
-Value may be either function name or the variable name that holds
-the function."
- (let ((parent (js2-node-parent fn-node)))
- (if (js2-function-node-p fn-node)
- (or (js2-function-name fn-node)
- (if (js2-var-init-node-p parent)
- (js2-name-node-name (js2-var-init-node-target parent)))))))
-
-(defun js2-root-or-node ()
- "Return the current node or js2-ast-root node."
- (let ((node (js2-node-at-point)))
- (if (js2-ast-root-p node)
- node
- (js2-node-get-enclosing-scope node))))
+ t))
+ )))
+ )
(defun js2-build-prop-name-list (name-node list-names)
"Compare the names in NAME-NODE to the ones in LIST-NAMES.
@@ -12406,18 +12389,6 @@ Returns the matching node to jump to or nil."
(setq next-prop (js2-prop-get-node-right
next-prop)))))))
(unless list-names name-node)))
-(defun js2-get-function-node (name scope)
- "Return node of function named NAME in SCOPE."
- (catch 'function-found
- (js2-visit-ast
- scope
- (lambda (node end-p)
- (when (and (not end-p)
- (string= name (js2-get-function-name node)))
- (throw 'function-found node))
- t))
- nil))
-
(provide 'js2-mode)
;;; js2-mode.el ends here
diff --git a/tests/navigation.el b/tests/navigation.el
index 78b61f2..6f94d7a 100644
--- a/tests/navigation.el
+++ b/tests/navigation.el
@@ -44,5 +44,5 @@
(ert-deftest js2-jump-to-object-property ()
(js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"};
aObject.prop1" 16))
-;; (ert-deftest js2-jump-to-object-property ()
+;; (ert-deftest js2-no-jump-to-object-property ()
;; (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"};
anotherObject.dprop1"))
- [elpa] master 5beb8ea 13/38: Define js2-re-search-forward as an alias as well, (continued)
- [elpa] master 5beb8ea 13/38: Define js2-re-search-forward as an alias as well, Dmitry Gutov, 2015/09/09
- [elpa] master fc56c58 16/38: js2-define-destruct-symbols-internal: Anticipate js2-getter-setter-node, Dmitry Gutov, 2015/09/09
- [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 <=
- [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, 2015/09/09
- [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