lsp-yang.el (4325B)
1 ;;; lsp-yang.el --- YANG Client settings -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2024 Siddharth Sharma 4 5 ;; Author: Siddharth Sharma <siddharth.sharma@ericsson.com> 6 ;; Keywords: languages, yang, lsp 7 8 ;; This program is free software; you can redistribute it and/or modify 9 ;; it under the terms of the GNU General Public License as published by 10 ;; the Free Software Foundation, either version 3 of the License, or 11 ;; (at your option) any later version. 12 13 ;; This program is distributed in the hope that it will be useful, 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 ;; GNU General Public License for more details. 17 18 ;; You should have received a copy of the GNU General Public License 19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>. 20 21 ;;; Commentary: 22 23 ;; LSP support for YANG using using an external language server. Currently 24 ;; the supported server is: 25 ;; 26 ;; yang-lsp (yls). 27 ;; See https://github.com/TypeFox/yang-lsp/blob/master/docs/Settings.md 28 ;; for setting up the user/project/workspace files. 29 30 ;;; Code: 31 32 (require 'lsp-mode) 33 34 (defgroup lsp-yang nil 35 "LSP support for the YANG data modeling language using yang-lsp server." 36 :group 'lsp-yang 37 :link '(url-link "https://github.com/TypeFox/yang-lsp")) 38 39 (defcustom lsp-yang-yls-version "0.7.6" 40 "yang-lsp server version to download. 41 42 It has to be set before `lsp-yang.el' is loaded and it has to 43 be available here: https://github.com/TypeFox/yang-lsp/releases/" 44 :type 'string 45 :group 'lsp-yang 46 :package-version '(lsp-mode . "9.0.0")) 47 48 (add-to-list 'auto-mode-alist '("^yang\\.settings$" . jsonc-mode)) 49 50 (defcustom lsp-yang-yls-settings-schema-url 51 (format "https://raw.githubusercontent.com/TypeFox/yang-lsp/v%s/schema/yang-lsp-settings-schema.json" 52 lsp-yang-yls-version) 53 "URL for yang-lsp server settings schema" 54 :type 'string 55 :group 'lsp-yang 56 :package-version '(lsp-mode . "9.0.0")) 57 58 (defcustom lsp-yang-yls-executable "yang-language-server" 59 "The yang-lsp server executable to use. 60 61 Leave as just the executable name to use the default behavior of finding the 62 executable with variable `exec-path'." 63 :group 'lsp-yang 64 :type 'string) 65 66 (defcustom lsp-yang-yls-download-url 67 (format "https://github.com/TypeFox/yang-lsp/releases/download/v%s/yang-language-server_%s.zip" 68 lsp-yang-yls-version 69 lsp-yang-yls-version) 70 "Automatic download url for yang-lsp server" 71 :type 'string 72 :group 'lsp-yang 73 :package-version '(lsp-mode . "9.0.0")) 74 75 (defcustom lsp-yang-yls-store-path 76 (f-join lsp-server-install-dir "yang-lsp" "yang-lsp") 77 "The path to the file in which `yang-language-server' will be stored." 78 :type 'file 79 :group 'lsp-yang 80 :package-version '(lsp-mode . "9.0.0")) 81 82 (defcustom lsp-yang-yls-binary-path 83 (f-join lsp-server-install-dir (format "yang-lsp/yang-language-server-%s/bin" 84 lsp-yang-yls-version) 85 (pcase system-type 86 ('windows-nt "yang-language-server.bat") 87 (_ "yang-language-server"))) 88 "The path to `yang-language-server' binary." 89 :type 'file 90 :group 'lsp-yang 91 :package-version '(lsp-mode . "9.0.0")) 92 93 (defun lsp-yang--stored-yls-executable () 94 "Return the stored yang-lsp server executable." 95 (executable-find lsp-yang-yls-binary-path)) 96 97 (lsp-dependency 98 'yang-lsp 99 `(:download :url lsp-yang-yls-download-url 100 :decompress :zip 101 :store-path lsp-yang-yls-store-path 102 :binary-path lsp-yang-yls-binary-path 103 :set-exectutable? t)) 104 105 (lsp-register-client 106 (make-lsp-client 107 :new-connection (lsp-stdio-connection 108 (lambda () (or (executable-find lsp-yang-yls-executable) 109 (lsp-yang--stored-yls-executable))) 110 (lambda () (or (executable-find lsp-yang-yls-executable) 111 (file-executable-p (lsp-yang--stored-yls-executable))))) 112 :major-modes '(yang-mode) 113 :language-id "YANG" 114 :priority -1 115 :server-id 'yls 116 :download-server-fn (lambda (_client callback error-callback _update?) 117 (lsp-package-ensure 'yang-lsp callback error-callback)))) 118 119 (lsp-consistency-check lsp-yang) 120 121 (provide 'lsp-yang) 122 ;;; lsp-yang.el ends here