summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Lau <9203+zoonfafer@users.noreply.github.com>2022-01-07 22:57:29 +0800
committerGitHub <noreply@github.com>2022-01-07 23:57:29 +0900
commit5087246c8223712fa0097098e910951aba8603fb (patch)
tree2be44dff3e7c2832e06223cf3a2e2d3e38011c4a
parent76bd0593713004ae38d738874e9e0575aefc88dd (diff)
downloadale-5087246c8223712fa0097098e910951aba8603fb.zip
Add yaml-language-server support for YAML (#2874) (#4029)
-rw-r--r--ale_linters/yaml/ls.vim34
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale-yaml.txt53
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/linter/test_yaml_ls.vader21
-rw-r--r--test/test-files/yaml/test.yaml0
7 files changed, 111 insertions, 0 deletions
diff --git a/ale_linters/yaml/ls.vim b/ale_linters/yaml/ls.vim
new file mode 100644
index 00000000..8e3f6d00
--- /dev/null
+++ b/ale_linters/yaml/ls.vim
@@ -0,0 +1,34 @@
+" Author: Jeffrey Lau - https://github.com/zoonfafer
+" Description: YAML Language Server https://github.com/redhat-developer/yaml-language-server
+
+call ale#Set('yaml_ls_executable', 'yaml-language-server')
+call ale#Set('yaml_ls_use_global', get(g:, 'ale_use_global_executables', 0))
+call ale#Set('yaml_ls_config', {})
+
+function! ale_linters#yaml#ls#GetExecutable(buffer) abort
+ return ale#path#FindExecutable(a:buffer, 'yaml_ls', [
+ \ 'node_modules/.bin/yaml-language-server',
+ \])
+endfunction
+
+function! ale_linters#yaml#ls#GetCommand(buffer) abort
+ let l:executable = ale_linters#yaml#ls#GetExecutable(a:buffer)
+
+ return ale#Escape(l:executable) . ' --stdio'
+endfunction
+
+" Just use the current file
+function! ale_linters#yaml#ls#FindProjectRoot(buffer) abort
+ let l:project_file = expand('#' . a:buffer . ':p')
+
+ return fnamemodify(l:project_file, ':h')
+endfunction
+
+call ale#linter#Define('yaml', {
+\ 'name': 'yaml-language-server',
+\ 'lsp': 'stdio',
+\ 'executable': function('ale_linters#yaml#ls#GetExecutable'),
+\ 'command': function('ale_linters#yaml#ls#GetCommand'),
+\ 'project_root': function('ale_linters#yaml#ls#FindProjectRoot'),
+\ 'lsp_config': {b -> ale#Var(b, 'yaml_ls_config')},
+\})
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index f93e0807..ed1d1d5e 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -640,6 +640,7 @@ Notes:
* `prettier`
* `spectral`
* `swaglint`
+ * `yaml-language-server`
* `yamlfix`
* `yamllint`
* YANG
diff --git a/doc/ale-yaml.txt b/doc/ale-yaml.txt
index 65e0d069..a5da85a5 100644
--- a/doc/ale-yaml.txt
+++ b/doc/ale-yaml.txt
@@ -106,6 +106,59 @@ g:ale_yaml_swaglint_use_global *g:ale_yaml_swaglint_use_global*
===============================================================================
+yaml-language-server *ale-yaml-language-server*
+
+Website: https://github.com/redhat-developer/yaml-language-server
+
+
+Installation
+-------------------------------------------------------------------------------
+
+Install yaml-language-server either globally or locally: >
+
+ npm install yaml-language-server -g # global
+ npm install yaml-language-server # local
+
+
+Options
+-------------------------------------------------------------------------------
+
+g:ale_yaml_ls_executable *g:ale_yaml_ls_executable*
+ *b:ale_yaml_ls_executable*
+ Type: |String|
+ Default: `'yaml-language-server'`
+
+ This variable can be set to change the path to yaml-language-server.
+
+
+g:ale_yaml_ls_config *g:ale_yaml_ls_config*
+ *b:ale_yaml_ls_config*
+ Type: |Dictionary|
+ Default: `{}`
+
+ Dictionary containing configuration settings that will be passed to the
+ language server. For example, to enable schema store: >
+ {
+ \ 'yaml': {
+ \ 'schemaStore': {
+ \ 'enable': v:true,
+ \ },
+ \ },
+ \ }
+<
+ Consult the yaml-language-server documentation for more information about
+ settings.
+
+
+g:ale_yaml_ls_use_global *g:ale_yaml_ls_use_global*
+ *b:ale_yaml_ls_use_global*
+ Type: |String|
+ Default: `get(g:, 'ale_use_global_executables', 0)`
+
+ See |ale-integrations-local-executables|
+
+
+===============================================================================
yamlfix *ale-yaml-yamlfix*
Website: https://lyz-code.github.io/yamlfix
diff --git a/doc/ale.txt b/doc/ale.txt
index 19a8dd2f..4e576284 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -3232,6 +3232,7 @@ documented in additional help files.
prettier..............................|ale-yaml-prettier|
spectral..............................|ale-yaml-spectral|
swaglint..............................|ale-yaml-swaglint|
+ yaml-language-server..................|ale-yaml-language-server|
yamlfix...............................|ale-yaml-yamlfix|
yamllint..............................|ale-yaml-yamllint|
yang....................................|ale-yang-options|
diff --git a/supported-tools.md b/supported-tools.md
index 1d7b7583..75b22d94 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -649,6 +649,7 @@ formatting.
* [prettier](https://github.com/prettier/prettier)
* [spectral](https://github.com/stoplightio/spectral)
* [swaglint](https://github.com/byCedric/swaglint)
+ * [yaml-language-server](https://github.com/redhat-developer/yaml-language-server)
* [yamlfix](https://lyz-code.github.io/yamlfix)
* [yamllint](https://yamllint.readthedocs.io/)
* YANG
diff --git a/test/linter/test_yaml_ls.vader b/test/linter/test_yaml_ls.vader
new file mode 100644
index 00000000..449ce8c3
--- /dev/null
+++ b/test/linter/test_yaml_ls.vader
@@ -0,0 +1,21 @@
+Before:
+ call ale#assert#SetUpLinterTest('yaml', 'ls')
+
+After:
+ call ale#assert#TearDownLinterTest()
+
+Execute(should set correct defaults):
+ AssertLinter 'yaml-language-server', ale#Escape('yaml-language-server') . ' --stdio'
+
+Execute(should set correct LSP values):
+ call ale#test#SetFilename('../test-files/yaml/test.yaml')
+
+ AssertLSPLanguage 'yaml'
+ AssertLSPOptions {}
+ AssertLSPConfig {}
+ AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/yaml')
+
+Execute(should accept configuration settings):
+ AssertLSPConfig {}
+ let b:ale_yaml_ls_config = {'yaml': {'hover': v:false, 'completion': v:true}}
+ AssertLSPConfig {'yaml': {'hover': v:false, 'completion': v:true}}
diff --git a/test/test-files/yaml/test.yaml b/test/test-files/yaml/test.yaml
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/yaml/test.yaml