forked from gmlarumbe/verilog-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verilog-lsp.el
117 lines (90 loc) · 4.21 KB
/
verilog-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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
;;; verilog-lsp.el --- SystemVerilog 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:
;;;; Common
(defcustom verilog-ext-lsp-available-servers
'((verilog . "hdl_checker")
(svlangserver . "svlangserver")
(verible-ls . "verible-verilog-ls")
(svls . "svls")
(veridian . "veridian"))
"Verilog-ext available LSP servers."
:type '(alist :key-type (symbol)
:value-type (string))
:group 'verilog-ext)
(defconst verilog-ext-lsp-server-ids
(mapcar #'car verilog-ext-lsp-available-servers))
(defconst verilog-ext-lsp-server-binaries
(mapcar #'cdr verilog-ext-lsp-available-servers))
;;;; lsp-mode
(require 'lsp-mode)
(defvar verilog-ext-lsp-mode-default-server 'svlangserver)
(defun verilog-ext-lsp-configure ()
"Configure Verilog for `lsp-mode'.
Register additional clients."
(interactive)
(let (server-id server-bin)
(dolist (server verilog-ext-lsp-available-servers)
(setq server-id (car server))
(setq server-bin (cdr server))
(when (not (member server-id '(verilog svlangserver))) ; Already registered by `lsp-mode'
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection server-bin)
:major-modes '(verilog-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'."
(interactive (list (intern (completing-read "Server-id: " verilog-ext-lsp-server-ids nil t))))
(unless (executable-find (cdr (assoc server-id verilog-ext-lsp-available-servers)))
(message "%s not in $PATH, skipping config..." server-id))
(let ((server-list verilog-ext-lsp-server-ids))
(setq lsp-disabled-clients (assq-delete-all 'verilog-mode lsp-disabled-clients))
(push (cons 'verilog-mode (remove server-id server-list)) lsp-disabled-clients)
(message "[Verilog LSP]: %s" server-id)))
;;;;; Default config
(verilog-ext-lsp-configure)
(verilog-ext-lsp-set-server verilog-ext-lsp-mode-default-server)
;;;; eglot
(require 'eglot)
(defvar verilog-ext-eglot-default-server 'svlangserver)
(defun verilog-ext-eglot-set-server (server-id)
"Configure Verilog for `eglot'.
Override any previous configuration for `verilog-mode'."
(interactive (list (intern (completing-read "Server-id: " verilog-ext-lsp-server-ids nil t))))
(unless (executable-find (cdr (assoc server-id verilog-ext-lsp-available-servers)))
(message "%s not in $PATH, skipping config..." server-id))
(setq eglot-server-programs (assq-delete-all 'verilog-mode eglot-server-programs))
(push (list 'verilog-mode (alist-get server-id verilog-ext-lsp-available-servers))
eglot-server-programs)
(message "Set eglot SV server: %s" server-id))
;;;;; Default config
(verilog-ext-eglot-set-server verilog-ext-eglot-default-server)
;;;; Provide package
(provide 'verilog-lsp)
;;; verilog-lsp.el ends here