lsp-vhdl.el (5334B)
1 ;;; lsp-vhdl.el --- VHDL Client settings -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2019 Christian Birk Sørensen 4 5 ;; Author: Christian Birk Sørensen <chrbirks+emacs@gmail.com> 6 ;; Created: 6 October 2019 7 ;; Keywords: languages, lsp, vhdl 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 24 ;; LSP support for VHDL using using an external language server. Currently 25 ;; the supported servers are: 26 ;; 27 ;; VHDL-tool. See http://www.vhdltool.com/configuration for setting up the 28 ;; project file. 29 ;; 30 ;; HDL Checker. See https://github.com/suoto/hdl_checker/wiki/setting-up-a-project 31 ;; for setting up the project file. 32 ;; 33 ;; VHDL LS. See https://github.com/VHDL-LS/rust_hdl#configuration for setting 34 ;; up the project file. 35 ;; 36 ;; GHDL LS. See https://github.com/ghdl/ghdl-language-server for setting up the 37 ;; project file. 38 ;; 39 ;; Set the symbol lsp-vhdl-server to select the language server and set 40 ;; lsp-vhdl-server-path if the binary is not in the user PATH. 41 42 ;;; Code: 43 44 (require 'lsp-mode) 45 46 (defvar vhdl-tool-bin-name "vhdl-tool" 47 "Name of the VHDL Tool binary.") 48 49 (defvar hdl-checker-bin-name "hdl_checker" 50 "Name of HDL Checker binary.") 51 52 (defvar vhdl-ls-bin-name "vhdl_ls" 53 "Name of the VHDL LS binary.") 54 55 (defvar ghdl-ls-bin-name "ghdl-ls" 56 "Name of the GHDL LS binary.") 57 58 (defgroup lsp-vhdl nil 59 "LSP support for VHDL. Set lsp-vhdl-server to select server. The default is to use VHDL-tool." 60 :group 'lsp-mode) 61 62 (defcustom lsp-vhdl-server 'vhdl-tool 63 "Select which server to use: 64 VHDL-tool: A syntax checking, type checking and linting tool 65 \(http://vhdltool.com). 66 67 HDL Checker: A wrapper for third party tools such as GHDL, 68 ModelSim, Vivado Simulator 69 \(https://github.com/suoto/hdl_checker). 70 71 VHDL LS: A complete VHDL language server protocol implementation 72 with diagnostics, navigate to symbol, find all references etc 73 \(https://github.com/VHDL-LS/rust_hdl). 74 75 GHDL LS: A LSP server for VHDL based on GHDL 76 \(https://github.com/ghdl/ghdl-language-server)." 77 :type '(choice (const :tag "VHDL-tool" vhdl-tool) 78 (const :tag "HDL Checker" hdl-checker) 79 (const :tag "VHDL LS" vhdl-ls) 80 (const :tag "GHDL LS" ghdl-ls)) 81 :group 'lsp-vhdl) 82 83 (defcustom lsp-vhdl-server-path nil 84 "Path to binary server file." 85 :group 'lsp-vhdl 86 :risky t 87 :type 'file) 88 89 (defvar lsp-vhdl--params nil) 90 91 (defun lsp-vhdl--create-connection () 92 "Return lsp-stdio-connection based on the selected server." 93 (lsp-vhdl--set-server-path) 94 (lsp-vhdl--set-server-args) 95 (lsp-stdio-connection 96 (lambda () (cons (plist-get lsp-vhdl--params 'server-path) (plist-get lsp-vhdl--params 'server-args))) 97 (lambda () (executable-find (plist-get lsp-vhdl--params 'server-path))))) 98 99 (defun lsp-vhdl--set-server-path() 100 "Set path to server binary based on selection in lsp-vhdl-server." 101 (cond ((eq lsp-vhdl-server 'hdl-checker) (if (eq lsp-vhdl-server-path nil) 102 (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-path hdl-checker-bin-name)) 103 (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-path lsp-vhdl-server-path)))) 104 ((eq lsp-vhdl-server 'vhdl-tool) (if (eq lsp-vhdl-server-path nil) 105 (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-path vhdl-tool-bin-name)) 106 (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-path lsp-vhdl-server-path)))) 107 ((eq lsp-vhdl-server 'vhdl-ls) (if (eq lsp-vhdl-server-path nil) 108 (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-path vhdl-ls-bin-name)) 109 (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-path lsp-vhdl-server-path)))) 110 ((eq lsp-vhdl-server 'ghdl-ls) (if (eq lsp-vhdl-server-path nil) 111 (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-path ghdl-ls-bin-name)) 112 (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-path lsp-vhdl-server-path)))))) 113 114 (defun lsp-vhdl--set-server-args() 115 "Set server arguments based on server selection." 116 (cond ((eq lsp-vhdl-server 'hdl-checker) (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-args '("--lsp")))) 117 ((eq lsp-vhdl-server 'vhdl-tool) (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-args '("lsp")))) 118 ((eq lsp-vhdl-server 'vhdl-ls) (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-args '()))) 119 ((eq lsp-vhdl-server 'ghdl-ls) (setq lsp-vhdl--params (plist-put lsp-vhdl--params 'server-args '()))))) 120 121 (lsp-register-client 122 (make-lsp-client :new-connection (lsp-vhdl--create-connection) 123 :major-modes '(vhdl-mode vhdl-ts-mode) 124 :language-id "VHDL" 125 :priority -1 126 :server-id 'lsp-vhdl)) 127 128 (lsp-consistency-check lsp-vhdl) 129 130 (provide 'lsp-vhdl) 131 ;;; lsp-vhdl.el ends here