Update elm-ls

* elm_lsp is now elm_ls
* The binary published by @elm-tooling is elm-language-server

Updates tests, docs and adds more options to the plugin.
This commit is contained in:
andys8 2019-06-21 20:07:23 +02:00
parent 65ba4b85ec
commit 0843efc7a5
5 changed files with 73 additions and 36 deletions

View file

@ -0,0 +1,35 @@
" Author: antew - https://github.com/antew
" Description: elm-language-server integration for elm (diagnostics, formatting, and more)
call ale#Set('elm_ls_executable', 'elm-language-server')
call ale#Set('elm_ls_use_global', get(g:, 'ale_use_global_executables', 1))
call ale#Set('elm_ls_elm_path', 'elm')
call ale#Set('elm_ls_elm_format_path', 'elm-format')
call ale#Set('elm_ls_elm_test_path', 'elm-test')
function! elm_ls#GetRootDir(buffer) abort
let l:elm_json = ale#path#FindNearestFile(a:buffer, 'elm.json')
return !empty(l:elm_json) ? fnamemodify(l:elm_json, ':p:h') : ''
endfunction
function! elm_ls#GetOptions(buffer) abort
return {
\ 'runtime': 'node',
\ 'elmPath': ale#Var(a:buffer, 'elm_ls_elm_path'),
\ 'elmFormatPath': ale#Var(a:buffer, 'elm_ls_elm_format_path'),
\ 'elmTestPath': ale#Var(a:buffer, 'elm_ls_elm_test_path'),
\}
endfunction
call ale#linter#Define('elm', {
\ 'name': 'elm_ls',
\ 'lsp': 'stdio',
\ 'executable': {b -> ale#node#FindExecutable(b, 'elm_ls', [
\ 'node_modules/.bin/elm-language-server'
\ ])},
\ 'command': '%e --stdio',
\ 'project_root': function('elm_ls#GetRootDir'),
\ 'language': 'elm',
\ 'initialization_options': function('elm_ls#GetOptions')
\})

View file

@ -1,22 +0,0 @@
" Author: antew - https://github.com/antew
" Description: LSP integration for elm, currently supports diagnostics (linting)
call ale#Set('elm_lsp_executable', 'elm-lsp')
call ale#Set('elm_lsp_use_global', get(g:, 'ale_use_global_executables', 0))
function! elm_lsp#GetRootDir(buffer) abort
let l:elm_json = ale#path#FindNearestFile(a:buffer, 'elm.json')
return !empty(l:elm_json) ? fnamemodify(l:elm_json, ':p:h') : ''
endfunction
call ale#linter#Define('elm', {
\ 'name': 'elm_lsp',
\ 'lsp': 'stdio',
\ 'executable': {b -> ale#node#FindExecutable(b, 'elm_lsp', [
\ 'node_modules/.bin/elm-lsp',
\ ])},
\ 'command': '%e --stdio',
\ 'project_root': function('elm_lsp#GetRootDir'),
\ 'language': 'elm'
\})

View file

@ -29,20 +29,44 @@ g:ale_elm_format_options *g:ale_elm_format_options*
This variable can be set to pass additional options to elm-format. This variable can be set to pass additional options to elm-format.
=============================================================================== ===============================================================================
elm-lsp *ale-elm-elm-lsp* elm-ls *ale-elm-elm-ls*
g:ale_elm_lsp_executable *g:ale_elm_lsp_executable* g:ale_elm_ls_executable *g:ale_elm_ls_executable*
*b:ale_elm_lsp_executable* *b:ale_elm_ls_executable*
Type: |String| Type: |String|
Default: `'elm-lsp'` Default: `'elm-language-server'`
See |ale-integrations-local-executables| See |ale-integrations-local-executables|
g:ale_elm_lsp_use_global *g:ale_elm_lsp_use_global* g:ale_elm_ls_use_global *g:ale_elm_ls_use_global*
*b:ale_elm_lsp_use_global* *b:ale_elm_ls_use_global*
Type: |Number| Type: |Number|
Default: `get(g:, 'ale_use_global_executables', 0)` Default: `get(g:, 'ale_use_global_executables', 1)`
See |ale-integrations-local-executables|
g:ale_elm_ls_elm_path *g:ale_elm_ls_elm_path*
*b:ale_elm_ls_elm_path*
Type: |String|
Default: `'elm'`
See |ale-integrations-local-executables|
g:ale_elm_ls_elm_format_path *g:ale_elm_ls_elm_format_path*
*b:ale_elm_ls_elm_format_path*
Type: |String|
Default: `'elm-format'`
See |ale-integrations-local-executables|
g:ale_elm_ls_elm_test_path *g:ale_elm_ls_elm_test_path*
*b:ale_elm_ls_elm_test_path*
Type: |String|
Default: `'elm-test'`
See |ale-integrations-local-executables| See |ale-integrations-local-executables|

View file

@ -2002,7 +2002,7 @@ documented in additional help files.
credo.................................|ale-elixir-credo| credo.................................|ale-elixir-credo|
elm.....................................|ale-elm-options| elm.....................................|ale-elm-options|
elm-format............................|ale-elm-elm-format| elm-format............................|ale-elm-elm-format|
elm-lsp...............................|ale-elm-elm-lsp| elm-ls................................|ale-elm-elm-ls|
elm-make..............................|ale-elm-elm-make| elm-make..............................|ale-elm-elm-make|
erlang..................................|ale-erlang-options| erlang..................................|ale-erlang-options|
dialyzer..............................|ale-erlang-dialyzer| dialyzer..............................|ale-erlang-dialyzer|

View file

@ -1,5 +1,5 @@
Before: Before:
call ale#assert#SetUpLinterTest('elm', 'elm_lsp') call ale#assert#SetUpLinterTest('elm', 'elm_ls')
After: After:
call ale#assert#TearDownLinterTest() call ale#assert#TearDownLinterTest()
@ -7,7 +7,7 @@ After:
Execute(The default executable path should be correct): Execute(The default executable path should be correct):
call ale#test#SetFilename('../elm-test-files/newapp/src/Main.elm') call ale#test#SetFilename('../elm-test-files/newapp/src/Main.elm')
AssertLinter 'elm-lsp', ale#Escape('elm-lsp') . ' --stdio' AssertLinter 'elm-language-server', ale#Escape('elm-language-server') . ' --stdio'
Execute(The project root should be detected correctly): Execute(The project root should be detected correctly):
AssertLSPProject '' AssertLSPProject ''
@ -19,11 +19,11 @@ Execute(The project root should be detected correctly):
Execute(Should let users configure a global executable and override local paths): Execute(Should let users configure a global executable and override local paths):
call ale#test#SetFilename('../elm-test-files/newapp/src/Main.elm') call ale#test#SetFilename('../elm-test-files/newapp/src/Main.elm')
let g:ale_elm_lsp_executable = '/path/to/custom/elm-lsp' let g:ale_elm_ls_executable = '/path/to/custom/elm-language-server'
let g:ale_elm_lsp_use_global = 1 let g:ale_elm_ls_use_global = 1
AssertLinter '/path/to/custom/elm-lsp', AssertLinter '/path/to/custom/elm-language-server',
\ ale#Escape('/path/to/custom/elm-lsp') . ' --stdio' \ ale#Escape('/path/to/custom/elm-language-server') . ' --stdio'
Execute(The language should be correct): Execute(The language should be correct):
AssertLSPLanguage 'elm' AssertLSPLanguage 'elm'