Skip to content

Commit

Permalink
More code cleaning and misc bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlarumbe committed Oct 20, 2023
1 parent 48a6852 commit 31bc0f3
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 87 deletions.
7 changes: 5 additions & 2 deletions verilog-ext-beautify.el
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,19 @@ 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
(verilog-mode))
(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)))


Expand Down
25 changes: 22 additions & 3 deletions verilog-ext-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 ()
Expand Down Expand Up @@ -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)
Expand All @@ -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)))


Expand Down
6 changes: 3 additions & 3 deletions verilog-ext-eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion verilog-ext-flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
8 changes: 4 additions & 4 deletions verilog-ext-lsp.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -67,16 +67,16 @@ 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)))
(message "%s not in $PATH, skipping config..." server-id)
;; 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))))


Expand Down
4 changes: 2 additions & 2 deletions verilog-ext-nav.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions verilog-ext-tags.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions verilog-ext-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 31bc0f3

Please sign in to comment.