forked from gmlarumbe/verilog-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verilog-ext-lsp.el
85 lines (70 loc) · 3.58 KB
/
verilog-ext-lsp.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;;; verilog-ext-lsp.el --- Verilog-ext LSP setup -*- lexical-binding: t -*-
;; Copyright (C) 2022-2023 Gonzalo Larumbe
;; Author: Gonzalo Larumbe <gonzalomlarumbe@gmail.com>
;; URL: https://github.com/gmlarumbe/verilog-ext
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Support for various SystemVerilog language servers
;; - Builtin:
;; - hdl_checker: https://github.com/suoto/hdl_checker
;; - svlangserver: https://github.com/imc-trading/svlangserver
;; - Additional:
;; - verible: https://github.com/chipsalliance/verible/tree/master/verilog/tools/ls
;; - svls: https://github.com/dalance/svls
;; - veridian: https://github.com/vivekmalneedi/veridian
;;; Code:
(require 'lsp-mode)
(require 'lsp-verilog)
(require 'verilog-ext-utils)
;;;; lsp-mode
(defvar verilog-ext-lsp-mode-default-server 've-svlangserver)
(defun verilog-ext-lsp-setup ()
"Configure Verilog for `lsp-mode'.
Register additional clients."
(interactive)
(let (server-id server-bin)
;; Add `verilog-ts-mode' to the list of existing lsp ids
(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-lsp-available-servers)
(setq server-id (car server))
(setq server-bin (cdr server))
(cond ((eq server-id 've-svlangserver)
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection 'lsp-clients-svlangserver-command)
:major-modes '(verilog-mode verilog-ts-mode)
:library-folders-fn 'lsp-clients-svlangserver-get-workspace-additional-dirs
:server-id server-id)))
(t
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection server-bin)
:major-modes '(verilog-mode verilog-ts-mode)
:server-id server-id))))
(message "Registered lsp-client: %s" server-id))))
(defun verilog-ext-lsp-set-server (server-id)
"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-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-lsp-server-ids)) lsp-disabled-clients))
(message "[Verilog LSP]: %s" server-id))))
(provide 'verilog-ext-lsp)
;;; verilog-ext-lsp.el ends here