-
-
Notifications
You must be signed in to change notification settings - Fork 918
Introduce YANG LSP support #4390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
;;; lsp-yang.el --- YANG Client settings -*- lexical-binding: t; -*- | ||
|
||
;; Copyright (C) 2024 Siddharth Sharma | ||
|
||
;; Author: Siddharth Sharma <[email protected]> | ||
;; Keywords: languages, yang, lsp | ||
|
||
;; 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 <https://www.gnu.org/licenses/>. | ||
|
||
;;; Commentary: | ||
|
||
;; LSP support for YANG using using an external language server. Currently | ||
;; the supported server is: | ||
;; | ||
;; yang-lsp (yls). | ||
;; See https://github.com/TypeFox/yang-lsp/blob/master/docs/Settings.md | ||
;; for setting up the user/project/workspace files. | ||
|
||
;;; Code: | ||
|
||
(require 'lsp-mode) | ||
|
||
(defgroup lsp-yang nil | ||
"LSP support for the YANG data modeling language using yang-lsp server." | ||
:group 'lsp-yang | ||
:link '(url-link "https://github.com/TypeFox/yang-lsp")) | ||
|
||
(defcustom lsp-yang-yls-version "0.7.6" | ||
"yang-lsp server version to download. | ||
|
||
It has to be set before `lsp-yang.el' is loaded and it has to | ||
be available here: https://github.com/TypeFox/yang-lsp/releases/" | ||
:type 'string | ||
:group 'lsp-yang | ||
:package-version '(lsp-mode . "8.0.1")) | ||
|
||
(add-to-list 'auto-mode-alist '("^yang\\.settings$" . jsonc-mode)) | ||
|
||
(defcustom lsp-yang-yls-settings-schema-url | ||
(format "https://raw.githubusercontent.com/TypeFox/yang-lsp/v%s/schema/yang-lsp-settings-schema.json" | ||
lsp-yang-yls-version) | ||
"URL for yang-lsp server settings schema" | ||
:type 'string | ||
:group 'lsp-yang | ||
:package-version '(lsp-mode . "8.0.1")) | ||
|
||
(defcustom lsp-yang-yls-executable "yang-language-server" | ||
"The yang-lsp server executable to use. | ||
|
||
Leave as just the executable name to use the default behavior of finding the | ||
executable with variable `exec-path'." | ||
:group 'lsp-yang | ||
:type 'string) | ||
|
||
(defcustom lsp-yang-yls-download-url | ||
(format "https://github.com/TypeFox/yang-lsp/releases/download/v%s/yang-language-server_%s.zip" | ||
lsp-yang-yls-version | ||
lsp-yang-yls-version) | ||
"Automatic download url for yang-lsp server" | ||
:type 'string | ||
:group 'lsp-yang | ||
:package-version '(lsp-mode . "8.0.1")) | ||
|
||
(defcustom lsp-yang-yls-store-path | ||
(f-join lsp-server-install-dir "yang-lsp" "yang-lsp") | ||
"The path to the file in which `yang-language-server' will be stored." | ||
:type 'file | ||
:group 'lsp-yang | ||
:package-version '(lsp-mode . "8.0.1")) | ||
|
||
(defcustom lsp-yang-yls-binary-path | ||
(f-join lsp-server-install-dir (format "yang-lsp/yang-language-server-%s/bin" | ||
lsp-yang-yls-version) | ||
(pcase system-type | ||
('windows-nt "yang-language-server.bat") | ||
(_ "yang-language-server"))) | ||
"The path to `yang-language-server' binary." | ||
:type 'file | ||
:group 'lsp-yang | ||
:package-version '(lsp-mode . "8.0.1")) | ||
|
||
(defun lsp-yang--stored-yls-executable () | ||
"Return the stored yang-lsp server executable." | ||
(executable-find lsp-yang-yls-binary-path)) | ||
|
||
(lsp-dependency | ||
'yang-lsp | ||
`(:download :url lsp-yang-yls-download-url | ||
:decompress :zip | ||
:store-path lsp-yang-yls-store-path | ||
:binary-path lsp-yang-yls-binary-path | ||
:set-exectutable? t)) | ||
|
||
(lsp-register-client | ||
(make-lsp-client | ||
:new-connection (lsp-stdio-connection | ||
(lambda () (or (executable-find lsp-yang-yls-executable) | ||
(lsp-yang--stored-yls-executable))) | ||
(lambda () (or (executable-find lsp-yang-yls-executable) | ||
(file-executable-p (lsp-yang--stored-yls-executable))))) | ||
:major-modes '(yang-mode) | ||
:language-id "YANG" | ||
:priority -1 | ||
:server-id 'yls | ||
:download-server-fn (lambda (_client callback error-callback _update?) | ||
(lsp-package-ensure 'yang-lsp callback error-callback)))) | ||
|
||
(lsp-consistency-check lsp-yang) | ||
|
||
(provide 'lsp-yang) | ||
;;; lsp-yang.el ends here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
author: esmasth | ||
root_file: docs/manual-language-docs/lsp-yang.md | ||
--- | ||
# YANG (yang-lsp) | ||
|
||
`lsp-mode` provides YANG language support via the [TypeFox/yang-lsp][1] Server. | ||
The server identifier is `yls` as an abbreviation of the released binary called | ||
`yang-language-server`. | ||
|
||
## Configuration | ||
|
||
Add following configuration in `.emacs` or `init.el` to hook lsp on YANG files, | ||
since [`yang-mode`][2] is the supported major mode. | ||
|
||
```lisp | ||
(add-hook 'yang-mode-hook 'lsp) | ||
``` | ||
|
||
It recommended to add following configuration for the `yang.settings` file, | ||
which resides at the user/project/workspace root, to be validated via | ||
[`lsp-json`][5]. This may be automated by `lsp-yang` in later stages. | ||
|
||
```lisp | ||
(setq lsp-json-schemas | ||
`[(:fileMatch ["yang.settings"] :url lsp-yang-yls-settings-schema-url)]) | ||
``` | ||
|
||
To automatically trigger the [`lsp-json`][5] based validation, following | ||
configuration is recommended. | ||
|
||
```lisp | ||
(add-hook 'jsonc-mode-hook 'lsp) | ||
``` | ||
|
||
## Known Issues | ||
|
||
* Files in the project need to be opened in buffer to be known by LSP server | ||
* `yang.settings` is not associated with its [JSON schema][3] | ||
[`yang-lsp-settings-schema.json`][4] yet | ||
* yang-lsp settings file `yang.settings` is not respected | ||
* `lsp-format-buffer` does not follow `yang-mode` or `yang.settings` | ||
* Snippets have a bad format with extraneous characters | ||
|
||
[1]: https://github.com/TypeFox/yang-lsp | ||
[2]: https://github.com/mbj4668/yang-mode | ||
[3]: https://json-schema.org/ | ||
[4]: https://raw.githubusercontent.com/TypeFox/yang-lsp/v0.7.6/schema/yang-lsp-settings-schema.json | ||
[5]: https://emacs-lsp.github.io/lsp-mode/page/lsp-json/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.