config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

lsp-verilog.el (8406B)


      1 ;;; lsp-verilog.el --- Verilog Client settings         -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2019 Patrick Grogan
      4 
      5 ;; Author: Patrick Grogan <pogrogan@gmail.com>
      6 ;; Created: 7 December 2019
      7 ;; Keywords: languages, lsp, verilog
      8 
      9 ;; This program is free software; you can redistribute it and/or modify
     10 ;; it under the terms of the GNU General Public License as published by
     11 ;; the Free Software Foundation, either version 3 of the License, or
     12 ;; (at your option) any later version.
     13 
     14 ;; This program is distributed in the hope that it will be useful,
     15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 ;; GNU General Public License for more details.
     18 
     19 ;; You should have received a copy of the GNU General Public License
     20 ;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
     21 
     22 ;;; Commentary:
     23 ;; LSP client support for Verilog/SystemVerilog. The following language
     24 ;; servers are available:
     25 ;;   1) HDL Checker. See https://github.com/suoto/hdl_checker
     26 ;;   2) SVLangserver. See https://github.com/imc-trading/svlangserver
     27 ;;   3) Verible. See https://github.com/chipsalliance/verible
     28 ;;
     29 ;; This file is based on the lsp-vhdl.el file.
     30 ;;
     31 
     32 ;;; Code:
     33 
     34 (require 'lsp-mode)
     35 
     36 (defgroup lsp-svlangserver nil
     37   "Settings for the SystemVerilog language server client."
     38   :group 'lsp-mode
     39   :link '(url-link "https://github.com/imc-trading/svlangserver")
     40   :package-version '(lsp-mode . "8.0.0"))
     41 
     42 (defcustom lsp-clients-svlangserver-includeIndexing '["**/*.{sv,svh}"]
     43   "Files included for indexing (glob pattern)"
     44   :group 'lsp-svlangserver
     45   :type '(lsp-repeatable-vector string)
     46   :safe (lambda (x) (seq-every-p #'stringp x)))
     47 
     48 (defcustom lsp-clients-svlangserver-excludeIndexing '["test/**/*.{sv,svh}"]
     49   "Files excluded for indexing (glob pattern)"
     50   :group 'lsp-svlangserver
     51   :type '(lsp-repeatable-vector string)
     52   :safe (lambda (x) (seq-every-p #'stringp x)))
     53 
     54 (defcustom lsp-clients-svlangserver-defines nil
     55   "Defines needed for linting"
     56   :group 'lsp-svlangserver
     57   :type '(lsp-repeatable-vector string)
     58   :safe (lambda (x) (seq-every-p #'stringp x)))
     59 
     60 (defcustom lsp-clients-svlangserver-launchConfiguration "verilator -sv --lint-only -Wall"
     61   "Verilator command used for linting"
     62   :group 'lsp-svlangserver
     63   :type 'string
     64   :safe (lambda (x) (stringp x)))
     65 
     66 (defcustom lsp-clients-svlangserver-lintOnUnsaved t
     67   "Enable linting on unsaved files"
     68   :group 'lsp-svlangserver
     69   :type 'boolean
     70   :safe (lambda (x) (booleanp x)))
     71 
     72 (defcustom lsp-clients-svlangserver-formatCommand "verible-verilog-format"
     73   "Verible verilog format command"
     74   :group 'lsp-svlangserver
     75   :type 'string
     76   :safe (lambda (x) (stringp x)))
     77 
     78 (defcustom lsp-clients-svlangserver-disableCompletionProvider nil
     79   "Disable auto completion provided by the language server"
     80   :group 'lsp-svlangserver
     81   :type 'boolean
     82   :safe (lambda (x) (booleanp x)))
     83 
     84 (defcustom lsp-clients-svlangserver-disableHoverProvider nil
     85   "Disable hover over help provided by the language server"
     86   :group 'lsp-svlangserver
     87   :type 'boolean
     88   :safe (lambda (x) (booleanp x)))
     89 
     90 (defcustom lsp-clients-svlangserver-disableSignatureHelpProvider nil
     91   "Disable signature help provided by the language server"
     92   :group 'lsp-svlangserver
     93   :type 'boolean
     94   :safe (lambda (x) (booleanp x)))
     95 
     96 (defcustom lsp-clients-svlangserver-disableLinting nil
     97   "Disable verilator linting"
     98   :group 'lsp-svlangserver
     99   :type 'boolean
    100   :safe (lambda (x) (booleanp x)))
    101 
    102 (defcustom lsp-clients-svlangserver-workspace-additional-dirs nil
    103   "Additional directories to be managed by this instance of svlangserver"
    104   :group 'lsp-svlangserver
    105   :type '(lsp-repeatable-vector string)
    106   :safe (lambda (x) (seq-every-p #'stringp x)))
    107 
    108 (defcustom lsp-clients-svlangserver-bin-path "svlangserver"
    109   "svlangserver binary path"
    110   :group 'lsp-svlangserver
    111   :type 'string
    112   :safe (lambda (x) (stringp x)))
    113 
    114 (defcustom lsp-clients-svlangserver-bin-args nil
    115   "command line arguments for svlangserver binary"
    116   :group 'lsp-svlangserver
    117   :type '(lsp-repeatable-vector string)
    118   :safe (lambda (x) (seq-every-p #'stringp x)))
    119 
    120 (defcustom lsp-clients-svlangserver-node-command "node"
    121   "node binary path"
    122   :group 'lsp-svlangserver
    123   :type 'string
    124   :safe (lambda (x) (stringp x)))
    125 
    126 (defcustom lsp-clients-svlangserver-module-path "svlangserver.js"
    127   "svlangserver module path"
    128   :group 'lsp-svlangserver
    129   :type 'string
    130   :safe (lambda (x) (stringp x)))
    131 
    132 (defun lsp-clients-svlangserver-build-index ()
    133   (interactive)
    134   (lsp-send-execute-command "systemverilog.build_index"))
    135 
    136 (defun lsp-clients-svlangserver-report-hierarchy (container-name)
    137   (interactive (list (read-string "Module/interface: " (cond ((use-region-p) (buffer-substring (region-beginning) (region-end))) (t "")))))
    138   (lsp-send-execute-command "systemverilog.report_hierarchy" (vector container-name)))
    139 
    140 (lsp-dependency 'svlangserver
    141                 '(:system "svlangserver"))
    142 
    143 (defun lsp-clients-svlangserver-get-workspace-additional-dirs (_workspace)
    144   lsp-clients-svlangserver-workspace-additional-dirs)
    145 
    146 (defun lsp-clients-svlangserver-command ()
    147   (let ((svlangserver-bin-path (lsp-package-path 'svlangserver)))
    148     (if svlangserver-bin-path
    149       (cons svlangserver-bin-path lsp-clients-svlangserver-bin-args)
    150       (if (file-exists-p lsp-clients-svlangserver-bin-path)
    151         (cons lsp-clients-svlangserver-bin-path lsp-clients-svlangserver-bin-args)
    152         (if (file-exists-p lsp-clients-svlangserver-module-path)
    153           `(,lsp-clients-svlangserver-node-command ,lsp-clients-svlangserver-module-path ,"--stdio")
    154           `(,"svlangserver"))))))
    155 
    156 (lsp-register-client
    157     (make-lsp-client :new-connection (lsp-stdio-connection 'lsp-clients-svlangserver-command)
    158                      :major-modes '(verilog-mode)
    159                      :priority -1
    160                      :library-folders-fn 'lsp-clients-svlangserver-get-workspace-additional-dirs
    161                      :server-id 'svlangserver))
    162 
    163 (lsp-register-custom-settings '(("systemverilog.includeIndexing" lsp-clients-svlangserver-includeIndexing)
    164                                 ("systemverilog.excludeIndexing" lsp-clients-svlangserver-excludeIndexing)
    165                                 ("systemverilog.defines" lsp-clients-svlangserver-defines)
    166                                 ("systemverilog.launchConfiguration" lsp-clients-svlangserver-launchConfiguration)
    167                                 ("systemverilog.lintOnUnsaved" lsp-clients-svlangserver-lintOnUnsaved)
    168                                 ("systemverilog.formatCommand" lsp-clients-svlangserver-formatCommand)
    169                                 ("systemverilog.disableCompletionProvider" lsp-clients-svlangserver-disableCompletionProvider)
    170                                 ("systemverilog.disableHoverProvider" lsp-clients-svlangserver-disableHoverProvider)
    171                                 ("systemverilog.disableSignatureHelpProvider" lsp-clients-svlangserver-disableSignatureHelpProvider)
    172                                 ("systemverilog.disableLinting" lsp-clients-svlangserver-disableLinting)))
    173 
    174 (defgroup lsp-verilog nil
    175   "LSP support for Verilog/SystemVerilog."
    176   :group 'lsp-mode
    177   :link '(url-link "https://github.com/suoto/hdl_checker"))
    178 
    179 (defcustom lsp-clients-verilog-executable '("hdl_checker" "--lsp")
    180   "Command to start the hdl_checker language server."
    181   :group 'lsp-verilog
    182   :risky t
    183   :type 'file)
    184 
    185 (lsp-register-client
    186  (make-lsp-client :new-connection (lsp-stdio-connection lsp-clients-verilog-executable)
    187                   :major-modes '(verilog-mode)
    188                   :language-id "verilog"
    189     	          :priority -2
    190                   :server-id 'lsp-verilog))
    191 
    192 (lsp-consistency-check lsp-verilog)
    193 
    194 (defgroup lsp-verible nil
    195   "LSP support for Verilog/SystemVerilog using the Verible suite."
    196   :group 'lsp-mode
    197   :link '(url-link "https://github.com/chipsalliance/verible"))
    198 
    199 (defcustom lsp-clients-verible-executable '("verible-verilog-ls")
    200   "Command to start the Verible Verilog language server."
    201   :group 'lsp-verible
    202   :risky t
    203   :type 'file)
    204 
    205 (lsp-register-client
    206  (make-lsp-client :new-connection (lsp-stdio-connection lsp-clients-verible-executable)
    207                   :major-modes '(verilog-mode)
    208                   :language-id "verilog"
    209                   :priority -2
    210                   :server-id 'lsp-verilog-verible))
    211 
    212 (provide 'lsp-verilog)
    213 ;;; lsp-verilog.el ends here