From b66d7cf93ba0e5bff0e2913b3ff9dbad54298420 Mon Sep 17 00:00:00 2001 From: Gonzalo Larumbe Date: Sun, 17 Sep 2023 16:29:04 +0200 Subject: [PATCH] Move node-identifier-type aux function to verilog-ts-mode --- test-hdl | 2 +- verilog-ext-tags.el | 42 ++++++++++-------------------------------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/test-hdl b/test-hdl index 001e1c7..bec42fb 160000 --- a/test-hdl +++ b/test-hdl @@ -1 +1 @@ -Subproject commit 001e1c783ce47fad317d0aca8f8dcbd044c5b546 +Subproject commit bec42fb11e7842b8643737abc4fa3ddd21b77718 diff --git a/verilog-ext-tags.el b/verilog-ext-tags.el index d124da6..f7d6d43 100644 --- a/verilog-ext-tags.el +++ b/verilog-ext-tags.el @@ -318,10 +318,6 @@ completion.") (eval-when-compile (regexp-opt '("task_declaration" "function_declaration" "class_constructor_declaration") 'symbols))) -(defconst verilog-ext-tags-port-header-ts-re - (eval-when-compile - (regexp-opt '("variable_port_header" "net_port_header1" "interface_port_header") 'symbols))) - (cl-defun verilog-ext-tags-table-push-defs-ts (&key table inst-table file) "Push definitions inside hash table TABLE using tree-sitter. @@ -341,38 +337,20 @@ completion and navigation." :node tree :file file))) -(defun verilog-ext-tags-table-push-defs-ts--type (ts-type ts-node) - "Return type of current TS-NODE depending on tree-sitter TS-TYPE." - (cond (;; Variables - (string-match "\\" ts-type) - (treesit-node-text (verilog-ts--node-has-child-recursive (verilog-ts--node-has-parent-recursive ts-node "\\") "\\") :no-prop)) - ;; TODO: Still not taking (random_qualifier) sibling of (data_type )into account for rand/randc attributes - ;; TODO: Still not taking unpacked/queue/array dimensions into account - (;; Nets - (string-match "\\" ts-type) - (verilog-ts--node-identifier-name (verilog-ts--node-has-parent-recursive ts-node "\\"))) - (;; Module/interface/program ports - (string-match "\\" ts-type) - (treesit-node-text (treesit-search-subtree ts-node verilog-ext-tags-port-header-ts-re) :no-prop)) - (;; Task/function arguments - (string-match "\\" ts-type) - (let ((port-direction (treesit-node-text (treesit-search-subtree ts-node "\\") :no-prop))) - (concat (when port-direction (concat port-direction " ")) - (treesit-node-text (treesit-search-subtree ts-node "\\") :no-prop)))) - (;; Typedefs - (string-match "\\" ts-type) - (treesit-node-text (verilog-ts--node-has-child-recursive (verilog-ts--node-has-parent-recursive ts-node "\\") "\\") :no-prop)) - (t ;; Default - ts-type))) +(defun verilog-ext-tags-table-push-defs-ts--parent (ts-node ts-type parent-node) + "Return parent identifier of TS-NODE. + +PARENT-NODE is the default parent for TS-NODE. -(defun verilog-ext-tags-table-push-defs-ts--parent (parent ts-type ts-node) - "Return parent of current TS-NODE depending on tree-sitter TS-TYPE and PARENT." +TS-TYPE is provided to avoid an additional call to `treesit-node-type' since +this function is synctactic sugar for +`verilog-ext-tags-table-push-defs-ts--recurse'." (cond (;; Externally defined methods (and (string-match verilog-ext-tags-method-declaration-ts-re ts-type) (verilog-ts--node-has-child-recursive ts-node "class_type")) (verilog-ts--node-identifier-name (verilog-ts--node-has-child-recursive ts-node "class_identifier"))) (t ;; Default - (verilog-ts--node-identifier-name parent)))) + (verilog-ts--node-identifier-name parent-node)))) (cl-defun verilog-ext-tags-table-push-defs-ts--recurse (&key table inst-table node parent file) "Push definitions recursively inside hash table TABLE using tree-sitter. @@ -409,10 +387,10 @@ completion and navigation." :parent (verilog-ts--node-identifier-name parent)) (verilog-ext-tags-table-push :table table :tag (verilog-ts--node-identifier-name ts-node) - :type (verilog-ext-tags-table-push-defs-ts--type ts-type ts-node) + :type (verilog-ts--node-identifier-type ts-node) :desc (verilog-ext-tags-desc) :file file - :parent (verilog-ext-tags-table-push-defs-ts--parent parent ts-type ts-node)))))) + :parent (verilog-ext-tags-table-push-defs-ts--parent ts-node ts-type parent)))))) (cl-defun verilog-ext-tags-table-push-refs-ts (&key table defs-table file) "Push references inside hash table TABLE using tree-sitter.