From d0e33022539863b2c55aca49c1d1a9852b50c91d Mon Sep 17 00:00:00 2001 From: David Hotham Date: Fri, 3 Aug 2018 20:59:32 +0100 Subject: [PATCH] Add support for yang-lsp --- README.md | 1 + ale_linters/yang/yang_lsp.vim | 14 ++++++++++++++ doc/ale-yang.txt | 17 +++++++++++++++++ doc/ale.txt | 3 +++ .../test_yang_lsp_command_callbacks.vader | 12 ++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 ale_linters/yang/yang_lsp.vim create mode 100644 doc/ale-yang.txt create mode 100644 test/command_callback/test_yang_lsp_command_callbacks.vader diff --git a/README.md b/README.md index 210c4bfa..746b63d4 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,7 @@ formatting. | XHTML | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | XML | [xmllint](http://xmlsoft.org/xmllint.html) | | YAML | [swaglint](https://github.com/byCedric/swaglint), [yamllint](https://yamllint.readthedocs.io/) | +| YANG | [yang-lsp](https://github.com/theia-ide/yang-lsp) | diff --git a/ale_linters/yang/yang_lsp.vim b/ale_linters/yang/yang_lsp.vim new file mode 100644 index 00000000..a60e9113 --- /dev/null +++ b/ale_linters/yang/yang_lsp.vim @@ -0,0 +1,14 @@ +call ale#Set('yang_lsp_executable', 'yang-language-server') + +function! ale_linters#yang#yang_lsp#GetProjectRoot(buffer) abort + let l:project_root = ale#path#FindNearestFile(a:buffer, 'yang.settings') + return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' +endfunction + +call ale#linter#Define('yang', { +\ 'name': 'yang_lsp', +\ 'lsp': 'stdio', +\ 'executable_callback': ale#VarFunc('yang_lsp_executable'), +\ 'project_root_callback': 'ale_linters#yang#yang_lsp#GetProjectRoot', +\ 'command': '%e', +\}) diff --git a/doc/ale-yang.txt b/doc/ale-yang.txt new file mode 100644 index 00000000..ad619733 --- /dev/null +++ b/doc/ale-yang.txt @@ -0,0 +1,17 @@ +=============================================================================== +ALE YANG Integration *ale-yang-options* + + +=============================================================================== +yang-lsp *ale-yang-lsp* + +g:ale_yang_lsp_executable *g:ale_yang_lsp_executable* + *b:ale_yang_lsp_executable* + Type: |String| + Default: `'yang-language-server'` + + This variable can be changed to use a different executable for yang-lsp. + + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index db060a2b..9698b59c 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -292,6 +292,8 @@ CONTENTS *ale-contents* yaml..................................|ale-yaml-options| swaglint............................|ale-yaml-swaglint| yamllint............................|ale-yaml-yamllint| + yang..................................|ale-yang-options| + yang-lsp............................|ale-yang-lsp| 8. Commands/Keybinds....................|ale-commands| 9. API..................................|ale-api| 10. Special Thanks......................|ale-special-thanks| @@ -435,6 +437,7 @@ Notes: * XHTML: `alex`!!, `proselint`, `write-good` * XML: `xmllint` * YAML: `swaglint`, `yamllint` +* YANG: `yang-lsp` =============================================================================== 3. Linting *ale-lint* diff --git a/test/command_callback/test_yang_lsp_command_callbacks.vader b/test/command_callback/test_yang_lsp_command_callbacks.vader new file mode 100644 index 00000000..5be7501f --- /dev/null +++ b/test/command_callback/test_yang_lsp_command_callbacks.vader @@ -0,0 +1,12 @@ +Before: + call ale#assert#SetUpLinterTest('yang', 'yang_lsp') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The executable should be configurable): + AssertLinter 'yang-language-server', ale#Escape('yang-language-server') + + let b:ale_yang_lsp_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar')