diff --git a/test-hdl b/test-hdl index f5e819f..a4d7adb 160000 --- a/test-hdl +++ b/test-hdl @@ -1 +1 @@ -Subproject commit f5e819fb256b1d959609d8b8e8814db4b8e57d68 +Subproject commit a4d7adbf457220ac0d16512f5f4364db49cf3e33 diff --git a/verilog-ext-beautify.el b/verilog-ext-beautify.el index 7031bb3..529d870 100644 --- a/verilog-ext-beautify.el +++ b/verilog-ext-beautify.el @@ -134,6 +134,7 @@ FILES is a list of strings containing the filepaths." (error "File %s does not exist! Aborting!" file))) (save-window-excursion (dolist (file files) + (message "Processing %s..." file) (with-temp-file file (insert-file-contents file) (verilog-ext-with-no-hooks @@ -141,9 +142,11 @@ FILES is a list of strings containing the filepaths." (verilog-ext-beautify-current-buffer))))) (defun verilog-ext-beautify-dir-files (dir) - "Beautify Verilog files on DIR." + "Beautify Verilog files on DIR. + +Include subdirectory files recursively." (interactive "DDirectory: ") - (let ((files (verilog-ext-dir-files dir))) + (let ((files (verilog-ext-dir-files dir :recursive))) (verilog-ext-beautify-files files))) diff --git a/verilog-ext-compile.el b/verilog-ext-compile.el index 354382a..099e8b5 100644 --- a/verilog-ext-compile.el +++ b/verilog-ext-compile.el @@ -26,10 +26,10 @@ ;; and jump to error based on `compilation-mode': ;; ;; - Interactive functions examples: -;; - `verilog-ext-compile-makefile': prompt to available Makefile targets and compile ;; - `verilog-ext-compile-project': compile using :compile-cmd of `verilog-ext-project-alist' ;; ;; - Non-interactive function usage examples: +;; - (verilog-ext-compile "make") ;; - (verilog-ext-compile-verilator (concat "verilator --lint-only " buffer-file-name)) ;; - (verilog-ext-compile-iverilog (concat "iverilog " buffer-file-name)) ;; - (verilog-ext-compile-verible (concat "verible-verilog-lint " buffer-file-name)) @@ -117,12 +117,20 @@ (surelog-info2 ,(concat "^\\[\\(?1:INF:\\(?2:[A-Z0-9]+\\)\\)\\]\\s-+") nil nil nil 0 nil (1 compilation-info-face) (2 verilog-ext-compile-msg-code-face))) "Surelog regexps.") +(defconst verilog-ext-compile-all-re (append verilog-ext-compile-verilator-re + verilog-ext-compile-iverilog-re + verilog-ext-compile-verible-re + verilog-ext-compile-slang-re + verilog-ext-compile-svlint-re + verilog-ext-compile-surelog-re)) + (defconst verilog-ext-compile-verilator-buf "*verilator*") (defconst verilog-ext-compile-iverilog-buf "*iverilog*") (defconst verilog-ext-compile-verible-buf "*verible*") (defconst verilog-ext-compile-slang-buf "*slang*") (defconst verilog-ext-compile-svlint-buf "*svlint*") (defconst verilog-ext-compile-surelog-buf "*surelog*") +(defconst verilog-ext-compile-all-buf "*verilog-ext-compile") ;;;; Compilation-modes and macros (defmacro verilog-ext-compile-define-mode (name &rest args) @@ -229,6 +237,17 @@ ARGS is a property list." :buf verilog-ext-compile-surelog-buf :comp-mode verilog-ext-compile-surelog-mode) +(verilog-ext-compile-define-mode verilog-ext-compile-mode + :desc "Verilog" + :docstring "All Verilog supported tools Compilation mode." + :compile-re verilog-ext-compile-all-re + :buf-name verilog-ext-compile-all-buf) + +(verilog-ext-compile-define-fn verilog-ext-compile + :docstring "Compile Verilog COMMAND with error regexp highlighting." + :buf verilog-ext-compile-all-buf + :comp-mode verilog-ext-compile-mode) + ;;;; Compilation interactive functions (defun verilog-ext-compile-makefile () @@ -268,7 +287,7 @@ set the appropriate mode." ("svlint" #'verilog-ext-compile-svlint) ("surelog" #'verilog-ext-compile-surelog) ("verible-verilog-lint" #'verilog-ext-compile-verible) - (_ #'compile))) + (_ #'verilog-ext-compile))) (cmd-processed (cond (;; For svlint, make sure the -1 arg is present (string= cmd-bin "svlint") (if (member "-1" cmd-args) @@ -282,7 +301,7 @@ set the appropriate mode." ;; For the rest use the provided command (t compile-cmd))) - (cmd (mapconcat `("cd" ,(verilog-ext-buffer-proj-root proj) "&&" ,cmd-processed) " "))) + (cmd (mapconcat #'identity `("cd" ,(verilog-ext-buffer-proj-root proj) "&&" ,cmd-processed) " "))) (funcall fn cmd))) diff --git a/verilog-ext-eglot.el b/verilog-ext-eglot.el index 78f1681..493c29f 100644 --- a/verilog-ext-eglot.el +++ b/verilog-ext-eglot.el @@ -148,8 +148,8 @@ Configure in the same way as for `lsp-verilog'." (defun verilog-ext-eglot-set-server (server-id) "Configure Verilog for `eglot' with SERVER-ID server. Override any previous configuration for `verilog-mode' and `verilog-ts-mode'." - (interactive (list (intern (completing-read "Server-id: " verilog-ext-server-lsp-ids nil t)))) - (let ((cmd (alist-get server-id verilog-ext-server-lsp-list))) + (interactive (list (intern (completing-read "Server-id: " verilog-ext-lsp-server-ids nil t)))) + (let ((cmd (alist-get server-id verilog-ext-lsp-available-servers))) (unless cmd (error "%s not recognized as a supported server" server-id)) (if (not (executable-find (if (listp cmd) @@ -160,7 +160,7 @@ Override any previous configuration for `verilog-mode' and `verilog-ts-mode'." (dolist (mode '(verilog-mode verilog-ts-mode)) (setq eglot-server-programs (assq-delete-all mode eglot-server-programs)) (if (listp cmd) - (push `(,@mode ,cmd) eglot-server-programs) + (push `(,mode ,@cmd) eglot-server-programs) (push `(,mode ,cmd) eglot-server-programs))) ;; Additional settings depending on chosen server-id (when (equal server-id 've-svlangserver) diff --git a/verilog-ext-flycheck.el b/verilog-ext-flycheck.el index 53e518c..6ac4981 100644 --- a/verilog-ext-flycheck.el +++ b/verilog-ext-flycheck.el @@ -409,7 +409,7 @@ be undefined when defining the checker." (verilog-ext-flycheck-setup-linter linter) (setq verilog-ext-flycheck-linter linter) ; Save state for reporting ;; Refresh linter if in a verilog buffer - (when (eq major-mode 'verilog-mode) + (when (member major-mode '(verilog-mode verilog-ts-mode)) (flycheck-select-checker linter)) (message "Linter set to: %s " linter)) diff --git a/verilog-ext-lsp.el b/verilog-ext-lsp.el index bbcced2..6ad38cb 100644 --- a/verilog-ext-lsp.el +++ b/verilog-ext-lsp.el @@ -47,7 +47,7 @@ Register additional clients." (unless (alist-get 'verilog-ts-mode lsp-language-id-configuration) (push (cons 'verilog-ts-mode "verilog") lsp-language-id-configuration)) ;; Register clients - (dolist (server verilog-ext-server-lsp-list) + (dolist (server verilog-ext-lsp-available-servers) (setq server-id (car server)) (setq server-bin (cdr server)) (cond ((eq server-id 've-svlangserver) @@ -67,8 +67,8 @@ Register additional clients." "Set language server defined by SERVER-ID. Disable the rest to avoid handling priorities. Override any previous configuration for `verilog-mode' and `verilog-ts-mode'." - (interactive (list (intern (completing-read "Server-id: " verilog-ext-server-lsp-ids nil t)))) - (let ((cmd (cdr (assoc server-id verilog-ext-server-lsp-list)))) + (interactive (list (intern (completing-read "Server-id: " verilog-ext-lsp-server-ids nil t)))) + (let ((cmd (cdr (assoc server-id verilog-ext-lsp-available-servers)))) (if (not (executable-find (if (listp cmd) (car cmd) cmd))) @@ -76,7 +76,7 @@ Override any previous configuration for `verilog-mode' and `verilog-ts-mode'." ;; Else configure available server (dolist (mode '(verilog-mode verilog-ts-mode)) (setq lsp-disabled-clients (assq-delete-all mode lsp-disabled-clients)) - (push (cons mode (remove server-id verilog-ext-server-lsp-ids)) lsp-disabled-clients)) + (push (cons mode (remove server-id verilog-ext-lsp-server-ids)) lsp-disabled-clients)) (message "[Verilog LSP]: %s" server-id)))) diff --git a/verilog-ext-nav.el b/verilog-ext-nav.el index ecd6845..6c3c8b0 100644 --- a/verilog-ext-nav.el +++ b/verilog-ext-nav.el @@ -924,8 +924,8 @@ after the search has been done." "Jump to the first result and push xref marker if there were any matches. Kill the buffer if there is only one match." (when verilog-ext-jump-to-parent-trigger - (let ((module-name (propertize verilog-ext-jump-to-parent-module-name 'face '(:foreground "green"))) - (dir (propertize verilog-ext-jump-to-parent-module-dir 'face '(:foreground "light blue"))) + (let ((module-name (propertize verilog-ext-jump-to-parent-module-name 'face 'verilog-ext-font-lock-module-face)) + (dir verilog-ext-jump-to-parent-module-dir) (num-matches)) (save-excursion (goto-char (point-min)) diff --git a/verilog-ext-tags.el b/verilog-ext-tags.el index 677f41a..18d1a27 100644 --- a/verilog-ext-tags.el +++ b/verilog-ext-tags.el @@ -458,8 +458,8 @@ PARENT is passed as an argument to build the :items prop list of `verilog-ext-tags-defs-current-file'." (let* ((ts-node (car node)) (children (cdr node)) - (type (treesit-node-type ts-node)) - (is-instance (and type (string-match verilog-ts-instance-re type))) + (ts-type (treesit-node-type ts-node)) + (is-instance (and ts-type (string-match verilog-ts-instance-re ts-type))) (is-typedef-class (verilog-ts--node-is-typedef-class-p ts-node))) ;; Iterate over all the nodes of the tree (mapc (lambda (child-node) @@ -481,10 +481,10 @@ PARENT is passed as an argument to build the :items prop list of (puthash `(,(verilog-ts--node-identifier-name ts-node) ; Key plist :file ,file :line ,(line-number-at-pos)) - `(:type ,type ; Value plist + `(:type ,(verilog-ts--node-identifier-type ts-node) ; Value plist :desc ,(verilog-ext-tags-desc) :col ,(current-column) - :parent ,(verilog-ext-tags-table-push-defs-ts--parent ts-node type parent)) + :parent ,(verilog-ext-tags-table-push-defs-ts--parent ts-node ts-type parent)) verilog-ext-tags-defs-current-file))))) (defun verilog-ext-tags-table-push-refs-ts (file) diff --git a/verilog-ext-utils.el b/verilog-ext-utils.el index 9fdd088..ae2f482 100644 --- a/verilog-ext-utils.el +++ b/verilog-ext-utils.el @@ -128,14 +128,14 @@ type_t foo1, foo2 , foo4, foo6[], foo7 [25], foo8 ;") "\\(" verilog-ext-typedef-class-params-optional-re "\\|" verilog-ext-range-optional-re "\\)" "\\s-*\\(?2:\\<" verilog-identifier-re "\\>\\)")) ;;;;; LSP -(defconst verilog-ext-server-lsp-list +(defconst verilog-ext-lsp-available-servers '((ve-hdl-checker . ("hdl_checker" "--lsp")) (ve-svlangserver . "svlangserver") (ve-verible-ls . "verible-verilog-ls") (ve-svls . "svls") (ve-veridian . "veridian")) "Verilog-ext available LSP servers.") -(defconst verilog-ext-server-lsp-ids (mapcar #'car verilog-ext-server-lsp-list)) +(defconst verilog-ext-lsp-server-ids (mapcar #'car verilog-ext-lsp-available-servers)) ;;;;; Misc (defvar verilog-ext-buffer-list nil) diff --git a/verilog-ext.el b/verilog-ext.el index 8499931..7649c87 100644 --- a/verilog-ext.el +++ b/verilog-ext.el @@ -26,22 +26,22 @@ ;; Extensions for Verilog Mode: ;; ;; - Tree-sitter `verilog-ts-mode' support -;; - Improved syntax highlighting -;; - Builtin xref backend +;; - Improved syntax highlighting for `verilog-mode' +;; - Find definitions and references with builtin `xref' backend ;; - Auto-completion with dot and scope completion -;; - Hierarchy extraction and navigation: builtin and vhier based +;; - Hierarchy extraction and navigation ;; - LSP configuration for `lsp-mode' and `eglot' ;; - Support for many linters via `flycheck' ;; - Beautify modules and instances ;; - Code navigation functions for RTL and Verification environments -;; - Extended collection of custom and `yasnippet' templates insertion via `hydra' +;; - Templates insertion via `hydra': custom and `yasnippet' based ;; - Code formatter via `apheleia' ;; - Compilation-based utilities -;; - Improve `imenu' entries: detect instances, classes and methods -;; - Enhanced support for `which-func' +;; - Improve `imenu': detect instances, classes and methods +;; - Add support for `which-func' ;; - Code folding via `hideshow' ;; - Project tags, typedef analysis and caching -;; - Time-stamp auto-configuration +;; - `time-stamp' auto-configuration ;; - Convert block end comments to names ;; - Port connections utilities @@ -72,7 +72,7 @@ time-stamp block-end-comments ports) - "Which Verilog-ext features to enable." + "Which `verilog-ext' features to enable." :type '(set (const :tag "Improved syntax highlighting via `font-lock'." font-lock) (const :tag "Xref backend to navigate definitions/references in current project." @@ -91,7 +91,7 @@ beautify) (const :tag "Code Navigation functions." navigation) - (const :tag "`yasnippet' and custom templates." + (const :tag "`yasnippet' and custom templates via `hydra'." template) (const :tag "`verible' formatter via `apheleia'." formatter) @@ -99,7 +99,7 @@ compilation) (const :tag "Improved `imenu'." imenu) - (const :tag "Improved `which-function-mode'." + (const :tag "Support for `which-function-mode'." which-func) (const :tag "`hideshow' configuration." hideshow) @@ -156,49 +156,47 @@ FEATURES can be a single feature or a list of features." (defvar verilog-ext-mode-map (let ((map (make-sparse-keymap))) ;; Features - (verilog-ext-when-feature 'hideshow - (define-key map (kbd "C-") 'verilog-ext-hs-toggle-hiding)) - (verilog-ext-when-feature 'formatter - (define-key map (kbd "C-c C-l") 'verilog-ext-formatter-run)) - (verilog-ext-when-feature 'compilation - (define-key map (kbd "C-c ") 'verilog-ext-compile-project) - (define-key map (kbd "C-c C-p") 'verilog-ext-preprocess)) + (verilog-ext-when-feature '(capf xref) + (define-key map (kbd "C-c C-u") 'verilog-ext-tags-get)) + (verilog-ext-when-feature 'hierarchy + (define-key map (kbd "C-c C-v") 'verilog-ext-hierarchy-current-buffer)) (verilog-ext-when-feature 'flycheck (define-key map (kbd "C-c C-f") 'verilog-ext-flycheck-mode)) (verilog-ext-when-feature 'template (define-key map (kbd "C-c C-t") 'verilog-ext-hydra/body)) - (verilog-ext-when-feature 'hierarchy - (define-key map (kbd "C-c C-v") 'verilog-ext-hierarchy-current-buffer)) + (verilog-ext-when-feature 'formatter + (define-key map (kbd "C-c C-l") 'verilog-ext-formatter-run)) (verilog-ext-when-feature 'beautify (define-key map (kbd "C-M-i") 'verilog-ext-beautify-block-at-point-indent) (define-key map (kbd "C-c C-b") 'verilog-ext-beautify-module-at-point)) - (verilog-ext-when-feature 'xref - (define-key map (kbd "C-c C-u") 'verilog-ext-tags-get)) (verilog-ext-when-feature 'navigation - (when (eq major-mode 'verilog-mode) - (define-key map (kbd "C-M-a") 'verilog-ext-nav-beg-of-defun-dwim) - (define-key map (kbd "C-M-e") 'verilog-ext-nav-end-of-defun-dwim) - (define-key map (kbd "C-M-d") 'verilog-ext-nav-down-dwim) - (define-key map (kbd "C-M-u") 'verilog-ext-nav-up-dwim) - (define-key map (kbd "C-M-p") 'verilog-ext-nav-prev-dwim) - (define-key map (kbd "C-M-n") 'verilog-ext-nav-next-dwim)) + (define-key map (kbd "C-M-.") 'verilog-ext-jump-to-parent-module) (define-key map (kbd "C-c M-.") 'verilog-ext-jump-to-module-at-point-def) (define-key map (kbd "C-c M-?") 'verilog-ext-jump-to-module-at-point-ref) - (define-key map (kbd "C-M-.") 'verilog-ext-jump-to-parent-module)) + (define-key map (kbd "C-M-a") 'verilog-ext-nav-beg-of-defun-dwim) + (define-key map (kbd "C-M-e") 'verilog-ext-nav-end-of-defun-dwim) + (define-key map (kbd "C-M-d") 'verilog-ext-nav-down-dwim) + (define-key map (kbd "C-M-u") 'verilog-ext-nav-up-dwim) + (define-key map (kbd "C-M-p") 'verilog-ext-nav-prev-dwim) + (define-key map (kbd "C-M-n") 'verilog-ext-nav-next-dwim)) + (verilog-ext-when-feature 'compilation + (define-key map (kbd "C-c ") 'verilog-ext-compile-project) + (define-key map (kbd "C-c C-p") 'verilog-ext-preprocess)) + (verilog-ext-when-feature 'hideshow + (define-key map (kbd "C-") 'verilog-ext-hs-toggle-hiding)) (verilog-ext-when-feature 'ports (define-key map (kbd "C-c C-c c") 'verilog-ext-ports-clean-blanks) (define-key map (kbd "C-c C-c t") 'verilog-ext-ports-toggle-connect) (define-key map (kbd "C-c C-c r") 'verilog-ext-ports-connect-recursively)) ;; Misc - (when (eq major-mode 'verilog-mode) - (define-key map (kbd "TAB") 'verilog-ext-tab) - (define-key map (kbd "M-d") 'verilog-ext-kill-word) - (define-key map (kbd "M-f") 'verilog-ext-forward-word) - (define-key map (kbd "M-b") 'verilog-ext-backward-word) - (define-key map (kbd "C-") 'verilog-ext-backward-kill-word) - (define-key map (kbd "M-DEL") 'verilog-ext-backward-kill-word)) + (define-key map (kbd "TAB") 'verilog-ext-tab) + (define-key map (kbd "M-d") 'verilog-ext-kill-word) + (define-key map (kbd "M-f") 'verilog-ext-forward-word) + (define-key map (kbd "M-b") 'verilog-ext-backward-word) + (define-key map (kbd "C-") 'verilog-ext-backward-kill-word) + (define-key map (kbd "M-DEL") 'verilog-ext-backward-kill-word) map) - "Key map for the `verilog-ext'.") + "Keymap for `verilog-ext'.") ;;;###autoload (defun verilog-ext-mode-setup () @@ -207,25 +205,25 @@ FEATURES can be a single feature or a list of features." ;; Features (verilog-ext-when-feature 'font-lock (verilog-ext-font-lock-setup)) - (verilog-ext-when-feature 'hideshow - (verilog-ext-hs-setup)) - (verilog-ext-when-feature 'template - (verilog-ext-template-add-snippets)) - (verilog-ext-when-feature 'typedefs - (verilog-ext-typedef-set)) + (verilog-ext-when-feature '(capf xref) + (verilog-ext-tags-setup)) (verilog-ext-when-feature 'hierarchy (verilog-ext-hierarchy-setup)) - (verilog-ext-when-feature 'formatter - (verilog-ext-formatter-setup)) - (verilog-ext-when-feature 'flycheck - (verilog-ext-flycheck-setup)) (verilog-ext-when-feature 'eglot (verilog-ext-eglot-set-server verilog-ext-eglot-default-server)) (verilog-ext-when-feature 'lsp (verilog-ext-lsp-setup) (verilog-ext-lsp-set-server verilog-ext-lsp-mode-default-server)) - (verilog-ext-when-feature '(capf xref) - (verilog-ext-tags-setup)) + (verilog-ext-when-feature 'flycheck + (verilog-ext-flycheck-setup)) + (verilog-ext-when-feature 'template + (verilog-ext-template-add-snippets)) + (verilog-ext-when-feature 'formatter + (verilog-ext-formatter-setup)) + (verilog-ext-when-feature 'hideshow + (verilog-ext-hs-setup)) + (verilog-ext-when-feature 'typedefs + (verilog-ext-typedef-set)) ;; Jump to parent module ag/ripgrep hooks (add-hook 'ag-search-finished-hook #'verilog-ext-navigation-ag-rg-hook) (add-hook 'ripgrep-search-finished-hook #'verilog-ext-navigation-ag-rg-hook)) @@ -239,7 +237,6 @@ FEATURES can be a single feature or a list of features." :global nil (unless (derived-mode-p 'verilog-mode) (error "Verilog-ext only works with `verilog-mode' or `verilog-ts-mode'")) - ;; Update list of open buffers/directories (Verilog AUTO, flycheck) (if verilog-ext-mode (progn ;; Common @@ -247,6 +244,10 @@ FEATURES can be a single feature or a list of features." (verilog-ext-update-buffer-file-and-dir-list) (add-hook 'kill-buffer-hook #'verilog-ext-kill-buffer-hook nil :local) ;; Features + (verilog-ext-when-feature 'xref + (verilog-ext-xref-set)) + (verilog-ext-when-feature 'capf + (verilog-ext-capf-set)) (verilog-ext-when-feature 'hierarchy (if verilog-ext-hierarchy-vhier-use-open-buffers (progn (setq verilog-ext-hierarchy-vhier-open-dirs verilog-ext-dir-list) @@ -265,10 +266,6 @@ FEATURES can be a single feature or a list of features." (verilog-ext-block-end-comments-to-names-mode)) (verilog-ext-when-feature 'time-stamp (verilog-ext-time-stamp-mode)) - (verilog-ext-when-feature 'capf - (verilog-ext-capf-set)) - (verilog-ext-when-feature 'xref - (verilog-ext-xref-set)) ;; `verilog-mode'-only customization (exclude `verilog-ts-mode') (when (eq major-mode 'verilog-mode) ;; Syntax table overriding: @@ -277,9 +274,6 @@ FEATURES can be a single feature or a list of features." ;; and `verilog-ext-indent-region' to get back standard table to avoid ;; indentation issues with compiler directives. (modify-syntax-entry ?` ".") - ;; Imenu - (verilog-ext-when-feature 'imenu - (setq-local imenu-create-index-function #'verilog-ext-imenu-index)) ;; Font-lock ;; It's not possible to add font-lock keywords to minor-modes. ;; The workaround consists in add/remove keywords to the major mode when @@ -287,19 +281,22 @@ FEATURES can be a single feature or a list of features." ;; https://emacs.stackexchange.com/questions/60198/font-lock-add-keywords-is-not-working (verilog-ext-when-feature 'font-lock (font-lock-flush) - (setq-local font-lock-multiline nil)))) + (setq-local font-lock-multiline nil)) + ;; Imenu + (verilog-ext-when-feature 'imenu + (setq-local imenu-create-index-function #'verilog-ext-imenu-index)))) ;; Cleanup (remove-hook 'kill-buffer-hook #'verilog-ext-kill-buffer-hook :local) - (verilog-ext-when-feature 'block-end-comments - (verilog-ext-block-end-comments-to-names-mode -1)) - (verilog-ext-when-feature 'time-stamp - (verilog-ext-time-stamp-mode -1)) - (verilog-ext-when-feature 'typedef - (verilog-ext-typedef-set :disable)) (verilog-ext-when-feature 'xref (verilog-ext-xref-set :disable)) (verilog-ext-when-feature 'capf - (verilog-ext-capf-set :disable)))) + (verilog-ext-capf-set :disable)) + (verilog-ext-when-feature 'typedef + (verilog-ext-typedef-set :disable)) + (verilog-ext-when-feature 'block-end-comments + (verilog-ext-block-end-comments-to-names-mode -1)) + (verilog-ext-when-feature 'time-stamp + (verilog-ext-time-stamp-mode -1)))) ;;; Provide