Skip to content

Commit

Permalink
WIP: Updates to ts-mode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlarumbe committed Aug 12, 2023
1 parent 4b329b9 commit f0f8730
Show file tree
Hide file tree
Showing 9 changed files with 1,672 additions and 1,648 deletions.
634 changes: 317 additions & 317 deletions test/files/faceup/axi_demux.sv.ts.faceup

Large diffs are not rendered by default.

1,732 changes: 866 additions & 866 deletions test/files/faceup/axi_test.sv.ts.faceup

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions test/files/faceup/instances.sv.ts.faceup

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions test/files/faceup/tb_program.sv.ts.faceup

Large diffs are not rendered by default.

220 changes: 110 additions & 110 deletions test/files/faceup/ucontroller.sv.ts.faceup

Large diffs are not rendered by default.

420 changes: 210 additions & 210 deletions test/files/faceup/uvm_component.svh.ts.faceup

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions test/verilog-ext-tests-setup-faces.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@
(set-face-attribute 'verilog-ext-font-lock-uvm-classes-face nil :foreground "light blue")
(set-face-attribute 'verilog-ext-font-lock-xilinx-attributes-face nil :foreground "orange1")

(set-face-attribute 'verilog-ts-font-lock-grouping-keywords-face nil :foreground "dark olive green")
(set-face-attribute 'verilog-ts-font-lock-punctuation-face nil :foreground "burlywood")
(set-face-attribute 'verilog-ts-font-lock-operator-face nil :foreground "burlywood" :weight 'extra-bold)
(set-face-attribute 'verilog-ts-font-lock-brackets-face nil :foreground "goldenrod")
(set-face-attribute 'verilog-ts-font-lock-parenthesis-face nil :foreground "dark goldenrod")
(set-face-attribute 'verilog-ts-font-lock-curly-braces-face nil :foreground "DarkGoldenrod2")
(set-face-attribute 'verilog-ts-font-lock-port-connection-face nil :foreground "bisque2")
(set-face-attribute 'verilog-ts-font-lock-dot-name-face nil :foreground "gray70")
(set-face-attribute 'verilog-ts-font-lock-brackets-content-face nil :foreground "yellow green")
(set-face-attribute 'verilog-ts-font-lock-width-num-face nil :foreground "chartreuse2")
(set-face-attribute 'verilog-ts-font-lock-width-type-face nil :foreground "sea green" :weight 'bold)
(set-face-attribute 'verilog-ts-font-lock-module-face nil :foreground "green1")
(set-face-attribute 'verilog-ts-font-lock-instance-face nil :foreground "medium spring green")
(set-face-attribute 'verilog-ts-font-lock-time-event-face nil :foreground "deep sky blue" :weight 'bold)
(set-face-attribute 'verilog-ts-font-lock-time-unit-face nil :foreground "light steel blue")
(set-face-attribute 'verilog-ts-font-lock-preprocessor-face nil :foreground "pale goldenrod")
(set-face-attribute 'verilog-ts-font-lock-modport-face nil :foreground "light blue")
(set-face-attribute 'verilog-ts-font-lock-direction-face nil :foreground "RosyBrown3")
(set-face-attribute 'verilog-ts-font-lock-translate-off-face nil :background "gray20" :slant 'italic)
(set-face-attribute 'verilog-ts-font-lock-attribute-face nil :foreground "orange1")


(provide 'verilog-ext-tests-setup-faces)

;;; verilog-ext-tests-setup-faces.el ends here
7 changes: 5 additions & 2 deletions test/verilog-ext-tests-setup-straight.el
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@
;;;; Setup package
(message "Installing and setting up verilog-ext")
(use-package verilog-ext
:straight (:host github :repo "gmlarumbe/verilog-ext"
:files (:defaults "snippets" "ts-mode/*.el"))
:after verilog-mode
:hook ((verilog-mode . verilog-ext-mode))
:demand
Expand All @@ -106,6 +104,11 @@
(setq treesit-font-lock-level 4))))


(use-package verilog-ts-mode
:straight (:host github :repo "gmlarumbe/verilog-ext"
:files ("ts-mode/verilog-ts-mode.el")))


(provide 'verilog-ext-tests-setup-straight)

;;; verilog-ext-tests-setup-straight.el ends here
131 changes: 65 additions & 66 deletions ts-mode/verilog-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@

(require 'treesit)
(require 'project)
(eval-when-compile
(require 'verilog-mode))
(require 'verilog-mode)

(declare-function treesit-parser-create "treesit.c")
(declare-function treesit-induce-sparse-tree "treesit.c")
Expand Down Expand Up @@ -204,44 +203,44 @@ With `prefix-arg', move ARG expressions."

(defvar verilog-ts-font-lock-grouping-keywords-face 'verilog-ts-font-lock-grouping-keywords-face)
(defface verilog-ts-font-lock-grouping-keywords-face
'((t (:foreground "dark olive green")))
'((t (:inherit font-lock-misc-punctuation-face)))
"Face for grouping keywords: begin, end."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-punctuation-face 'verilog-ts-font-lock-punctuation-face)
(defface verilog-ts-font-lock-punctuation-face
'((t (:foreground "burlywood")))
'((t (:inherit font-lock-punctuation-face)))
"Face for punctuation symbols, e.g:
!,;:?'=<>*"
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-punctuation-bold-face 'verilog-ts-font-lock-punctuation-bold-face)
(defface verilog-ts-font-lock-punctuation-bold-face
'((t (:inherit verilog-ts-font-lock-punctuation-face :weight extra-bold)))
"Face for bold punctuation symbols, such as &^~+-/|."
(defvar verilog-ts-font-lock-operator-face 'verilog-ts-font-lock-operator-face)
(defface verilog-ts-font-lock-operator-face
'((t (:inherit font-lock-operator-face)))
"Face for operator symbols, such as &^~+-/|."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-brackets-face 'verilog-ts-font-lock-brackets-face)
(defface verilog-ts-font-lock-brackets-face
'((t (:foreground "goldenrod")))
'((t (:inherit font-lock-bracket-face)))
"Face for brackets []."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-parenthesis-face 'verilog-ts-font-lock-parenthesis-face)
(defface verilog-ts-font-lock-parenthesis-face
'((t (:foreground "dark goldenrod")))
'((t (:inherit font-lock-bracket-face)))
"Face for parenthesis ()."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-curly-braces-face 'verilog-ts-font-lock-curly-braces-face)
(defface verilog-ts-font-lock-curly-braces-face
'((t (:foreground "DarkGoldenrod2")))
'((t (:inherit font-lock-bracket-face)))
"Face for curly braces {}."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-port-connection-face 'verilog-ts-font-lock-port-connection-face)
(defface verilog-ts-font-lock-port-connection-face
'((t (:foreground "bisque2")))
'((t (:inherit font-lock-constant-face)))
"Face for port connections of instances.
.portA (signalA),
.portB (signalB)
Expand All @@ -250,23 +249,23 @@ With `prefix-arg', move ARG expressions."

(defvar verilog-ts-font-lock-dot-name-face 'verilog-ts-font-lock-dot-name-face)
(defface verilog-ts-font-lock-dot-name-face
'((t (:foreground "gray70")))
'((t (:inherit font-lock-property-name-face)))
"Face for dot-name regexps:
- Interface signals, classes attributes/methods and hierarchical refs.
axi_if.Ready <= 1'b1;
obj.method();"
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-braces-content-face 'verilog-ts-font-lock-braces-content-face)
(defface verilog-ts-font-lock-braces-content-face
'((t (:foreground "yellow green")))
"Face for content between braces: arrays, bit vector width and indexing."
(defvar verilog-ts-font-lock-brackets-content-face 'verilog-ts-font-lock-brackets-content-face)
(defface verilog-ts-font-lock-brackets-content-face
'((t (:inherit font-lock-number-face)))
"Face for content between brackets: arrays, bit vector width and indexing."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-width-num-face 'verilog-ts-font-lock-width-num-face)
(defface verilog-ts-font-lock-width-num-face
'((t (:foreground "chartreuse2")))
'((t (:inherit font-lock-number-face)))
"Face for the bit width number expressions.
{1}'b1,
{4}'hF,
Expand All @@ -275,7 +274,7 @@ obj.method();"

(defvar verilog-ts-font-lock-width-type-face 'verilog-ts-font-lock-width-type-face)
(defface verilog-ts-font-lock-width-type-face
'((t (:foreground "sea green" :weight bold)))
'((t (:inherit font-lock-builtin-face)))
"Face for the bit width type expressions.
1'{b}1,
4'{h}F,
Expand All @@ -284,69 +283,64 @@ obj.method();"

(defvar verilog-ts-font-lock-module-face 'verilog-ts-font-lock-module-face)
(defface verilog-ts-font-lock-module-face
'((t (:foreground "green1")))
'((t (:inherit font-lock-function-call-face)))
"Face for module names."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-instance-face 'verilog-ts-font-lock-instance-face)
(defface verilog-ts-font-lock-instance-face
'((t (:foreground "medium spring green")))
'((t (:inherit font-lock-variable-use-face)))
"Face for instance names."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-time-event-face 'verilog-ts-font-lock-time-event-face)
(defface verilog-ts-font-lock-time-event-face
'((t (:foreground "deep sky blue" :weight bold)))
'((t (:inherit font-lock-property-name-face)))
"Face for time-events: @ and #."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-time-unit-face 'verilog-ts-font-lock-time-unit-face)
(defface verilog-ts-font-lock-time-unit-face
'((t (:foreground "light steel blue")))
'((t (:inherit font-lock-property-use-face)))
"Face for time-units: ms, us, ns, ps, fs (delays and timescale/timeprecision)."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-preprocessor-face 'verilog-ts-font-lock-preprocessor-face)
(defface verilog-ts-font-lock-preprocessor-face
'((t (:foreground "pale goldenrod")))
'((t (:inherit font-lock-preprocessor-face)))
"Face for preprocessor compiler directives (`include, `define, UVM macros...)."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-modport-face 'verilog-ts-font-lock-modport-face)
(defface verilog-ts-font-lock-modport-face
'((t (:foreground "light blue")))
'((t (:inherit font-lock-type-face)))
"Face for interface modports."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-direction-face 'verilog-ts-font-lock-direction-face)
(defface verilog-ts-font-lock-direction-face
'((t (:foreground "RosyBrown3")))
'((t (:inherit font-lock-keyword-face)))
"Face for direction of ports/functions/tasks args."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-typedef-face 'verilog-ts-font-lock-typedef-face)
(defface verilog-ts-font-lock-typedef-face
'((t (:foreground "light blue")))
"Face for user defined types."
:group 'verilog-ts-faces)

;; TODO: How to implement translate off in italic?
;; Fontifying in blocks is bound to start/end of the block in tree-sitter parsed tree.
;; That means that two (comment) blocks would need to be found, parsed, and one of them
;; should contain "synthesis_translate off" and the other "synthesis_translate on".
;; Since this seems very complex for tree-sitter, the other option could be just analyzing
;; the whole buffer and run something like `treesit-fontify-with-override', but this doesn't
;; seem to work. It adds text properties to text, but not sure about how to refresh it.
(defvar verilog-ts-font-lock-translate-off-face 'verilog-ts-font-lock-translate-off-face)
(defface verilog-ts-font-lock-translate-off-face
'((t (:background "gray20" :slant italic)))
'((t (:slant italic)))
"Face for pragmas between comments, e.g:
* translate_off / * translate_on"
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-uvm-classes-face 'verilog-ts-font-lock-uvm-classes-face)
(defface verilog-ts-font-lock-uvm-classes-face
'((t (:foreground "light blue")))
"Face for UVM classes."
:group 'verilog-ts-faces)

(defvar verilog-ts-font-lock-xilinx-attributes-face 'verilog-ts-font-lock-xilinx-attributes-face)
(defface verilog-ts-font-lock-xilinx-attributes-face
'((t (:foreground "orange1")))
"Face for Xilinx Vivado RTL synthesis attributes."
(defvar verilog-ts-font-lock-attribute-face 'verilog-ts-font-lock-attribute-face)
(defface verilog-ts-font-lock-attribute-face
'((t (:inherit font-lock-property-name-face)))
"Face for RTL attributes."
:group 'verilog-ts-faces)


Expand Down Expand Up @@ -460,22 +454,22 @@ OVERRIDE, START, END, and ARGS, see `treesit-font-lock-rules'."
:language 'verilog
'(;; Arrays
((packed_dimension
(constant_range) @verilog-ts-font-lock-braces-content-face))
(constant_range) @verilog-ts-font-lock-brackets-content-face))
((unpacked_dimension
(constant_range) @verilog-ts-font-lock-braces-content-face))
(constant_range) @verilog-ts-font-lock-brackets-content-face))
(select1
(constant_range) @verilog-ts-font-lock-braces-content-face)
(constant_range) @verilog-ts-font-lock-brackets-content-face)
((unpacked_dimension
(constant_expression) @verilog-ts-font-lock-braces-content-face))
(constant_expression) @verilog-ts-font-lock-brackets-content-face))
(bit_select1
(expression) @verilog-ts-font-lock-braces-content-face)
(expression) @verilog-ts-font-lock-brackets-content-face)
(constant_select1
(constant_expression) @verilog-ts-font-lock-braces-content-face)
(constant_expression) @verilog-ts-font-lock-brackets-content-face)
(constant_bit_select1
(constant_expression) @verilog-ts-font-lock-braces-content-face)
(constant_expression) @verilog-ts-font-lock-brackets-content-face)
(indexed_range
(expression) @verilog-ts-font-lock-braces-content-face
(constant_expression) @verilog-ts-font-lock-braces-content-face)
(expression) @verilog-ts-font-lock-brackets-content-face
(constant_expression) @verilog-ts-font-lock-brackets-content-face)
;; Timeunit
((time_unit) @font-lock-constant-face)
;; Enum labels
Expand Down Expand Up @@ -509,7 +503,7 @@ OVERRIDE, START, END, and ARGS, see `treesit-font-lock-rules'."
;; Attributes
(["(*" "*)"] @font-lock-constant-face)
(attribute_instance
(attr_spec (simple_identifier) @verilog-ts-font-lock-xilinx-attributes-face))
(attr_spec (simple_identifier) @verilog-ts-font-lock-attribute-face))
;; Typedefs
(type_declaration
(simple_identifier) @font-lock-constant-face)
Expand Down Expand Up @@ -559,24 +553,24 @@ OVERRIDE, START, END, and ARGS, see `treesit-font-lock-rules'."
:feature 'operator
:language 'verilog
`(;; INFO: Some of these might be redundant
([,@verilog-ts-operators-arithmetic] @verilog-ts-font-lock-punctuation-bold-face)
([,@verilog-ts-operators-arithmetic] @verilog-ts-font-lock-operator-face)
([,@verilog-ts-operators-relational] @verilog-ts-font-lock-punctuation-face)
([,@verilog-ts-operators-equality] @verilog-ts-font-lock-punctuation-face)
([,@verilog-ts-operators-shift] @verilog-ts-font-lock-punctuation-face)
([,@verilog-ts-operators-bitwise] @verilog-ts-font-lock-punctuation-bold-face)
([,@verilog-ts-operators-logical] @verilog-ts-font-lock-punctuation-bold-face)
([,@verilog-ts-operators-bitwise] @verilog-ts-font-lock-operator-face)
([,@verilog-ts-operators-logical] @verilog-ts-font-lock-operator-face)
;; Operators (LRM 11.3):
((assignment_operator) @verilog-ts-font-lock-punctuation-face)
((unary_operator) @verilog-ts-font-lock-punctuation-face)
;; ((binary_operator) @verilog-ts-font-lock-punctuation-face)
;; ((inc_or_dec_operator) @verilog-ts-font-lock-punctuation-face)
;; ((stream_operator) @verilog-ts-font-lock-punctuation-face)
((event_trigger) @verilog-ts-font-lock-punctuation-face))
((assignment_operator) @verilog-ts-font-operator-face)
((unary_operator) @verilog-ts-font-operator-face)
;; ((binary_operator) @verilog-ts-font-operator-face)
;; ((inc_or_dec_operator) @verilog-ts-font-operator-face)
;; ((stream_operator) @verilog-ts-font-operator-face)
((event_trigger) @verilog-ts-font-operator-face))

:feature 'punctuation
:language 'verilog
`(([,@verilog-ts-punctuation] @verilog-ts-font-lock-punctuation-face)
(["."] @verilog-ts-font-lock-punctuation-bold-face)
(["."] @verilog-ts-font-lock-operator-face)
(["(" ")"] @verilog-ts-font-lock-parenthesis-face)
(["[" "]"] @verilog-ts-font-lock-brackets-face)
(["{" "}"] @verilog-ts-font-lock-curly-braces-face)
Expand Down Expand Up @@ -1167,8 +1161,9 @@ Return nil if there is no name or if NODE is not a defun node."
(defun verilog-ts-which-func-function ()
"Retrieve `which-func' candidates."
(let ((node (verilog-ts--node-has-parent-recursive (verilog-ts--node-at-point) verilog-ts-imenu-create-index-re)))
(setq verilog-ts-which-func-extra (verilog-ts--node-identifier-name node))
(verilog-ts-which-func-shorten-block (treesit-node-type node))))
(when node
(setq verilog-ts-which-func-extra (verilog-ts--node-identifier-name node))
(verilog-ts-which-func-shorten-block (treesit-node-type node)))))

(defun verilog-ts-which-func ()
"Hook for `verilog-ts-mode' to enable `which-func'."
Expand Down Expand Up @@ -1214,7 +1209,9 @@ Complete with keywords and current buffer identifiers."
(defvar-keymap verilog-ts-mode-map
:doc "Keymap for SystemVerilog language with tree-sitter"
:parent verilog-mode-map
"TAB" #'indent-for-tab-command)
"TAB" #'indent-for-tab-command
"C-M-f" #'verilog-ts-forward-sexp
"C-M-b" #'verilog-ts-backward-sexp)

(defvar verilog-ts-mode-syntax-table
(let ((table (make-syntax-table)))
Expand Down Expand Up @@ -1263,6 +1260,8 @@ Complete with keywords and current buffer identifiers."
(add-hook 'completion-at-point-functions #'verilog-ts-completion-at-point nil 'local)
;; Which-func
(verilog-ts-which-func)
;; Auto-mode-alist
(add-to-list 'auto-mode-alist '("\\.s?vh??\\'" . verilog-ts-mode))
;; Setup.
(treesit-major-mode-setup)))

Expand Down

0 comments on commit f0f8730

Please sign in to comment.