Add yaml-language-server support for YAML (#2874) (#4029)

This commit is contained in:
Jeffrey Lau 2022-01-07 22:57:29 +08:00 committed by GitHub
parent 76bd059371
commit 5087246c82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 111 additions and 0 deletions

34
ale_linters/yaml/ls.vim Normal file
View File

@ -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')},
\})

View File

@ -640,6 +640,7 @@ Notes:
* `prettier`
* `spectral`
* `swaglint`
* `yaml-language-server`
* `yamlfix`
* `yamllint`
* YANG

View File

@ -105,6 +105,59 @@ g:ale_yaml_swaglint_use_global *g:ale_yaml_swaglint_use_global*
See |ale-integrations-local-executables|
===============================================================================
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*

View File

@ -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|

View File

@ -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

View File

@ -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}}

View File