mirror of https://github.com/dense-analysis/ale
Add terraform-lsp integration (#2758)
* Add terraform-lsp integration https://github.com/juliosueiras/terraform-lsp * Add tests & docs for terraform-lsp integration terraform_langserver_options setting added to send custom flags to terraform-lsp. Vader tests have been added to test custom executable, custom flags, and finding the project root. All tests pass. Initial documentation has been added for the above. Resolves dense-analysis/ale#2758, juliosueiras#57 * Fix tag alignment Co-authored-by: = <Aubrey.S.Lavigne@gmail.com> Co-authored-by: w0rp <w0rp@users.noreply.github.com>
This commit is contained in:
parent
3281321d5c
commit
36b50058bb
|
@ -0,0 +1,25 @@
|
|||
" Author: OJFord <dev@ojford.com>
|
||||
" Description: terraform-lsp integration for ALE (cf. https://github.com/juliosueiras/terraform-lsp)
|
||||
|
||||
call ale#Set('terraform_langserver_executable', 'terraform-lsp')
|
||||
call ale#Set('terraform_langserver_options', '')
|
||||
|
||||
function! ale_linters#terraform#terraform_lsp#GetCommand(buffer) abort
|
||||
return '%e'
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'terraform_langserver_options'))
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform_lsp#GetProjectRoot(buffer) abort
|
||||
let l:tf_dir = ale#path#FindNearestDirectory(a:buffer, '.terraform')
|
||||
|
||||
return !empty(l:tf_dir) ? fnamemodify(l:tf_dir, ':h:h') : ''
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('terraform', {
|
||||
\ 'name': 'terraform_lsp',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable': {b -> ale#Var(b, 'terraform_langserver_executable')},
|
||||
\ 'command': function('ale_linters#terraform#terraform_lsp#GetCommand'),
|
||||
\ 'project_root': function('ale_linters#terraform#terraform_lsp#GetProjectRoot'),
|
||||
\ 'language': 'terraform',
|
||||
\})
|
|
@ -32,6 +32,25 @@ g:ale_terraform_terraform_executable *g:ale_terraform_terraform_executable*
|
|||
This variable can be changed to use a different executable for terraform.
|
||||
|
||||
|
||||
===============================================================================
|
||||
terraform-lsp *ale-terraform-terraform-lsp*
|
||||
|
||||
g:ale_terraform_langserver_executable *g:ale_terraform_langserver_executable*
|
||||
*b:ale_terraform_langserver_executable*
|
||||
Type: |String|
|
||||
Default: `'terraform-lsp'`
|
||||
|
||||
This variable can be changed to use a different executable for terraform-lsp.
|
||||
|
||||
|
||||
g:ale_terraform_langserver_options *g:ale_terraform_langserver_options*
|
||||
*b:ale_terraform_langserver_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be changed to pass custom CLI flags to terraform-lsp.
|
||||
|
||||
|
||||
===============================================================================
|
||||
tflint *ale-terraform-tflint*
|
||||
|
||||
|
|
|
@ -2623,6 +2623,7 @@ documented in additional help files.
|
|||
terraform...............................|ale-terraform-options|
|
||||
terraform-fmt-fixer...................|ale-terraform-fmt-fixer|
|
||||
terraform.............................|ale-terraform-terraform|
|
||||
terraform-lsp.........................|ale-terraform-terraform-lsp|
|
||||
tflint................................|ale-terraform-tflint|
|
||||
tex.....................................|ale-tex-options|
|
||||
chktex................................|ale-tex-chktex|
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
Before:
|
||||
call ale#assert#SetUpLinterTest('terraform', 'terraform_lsp')
|
||||
|
||||
After:
|
||||
if isdirectory(g:dir . '/.terraform')
|
||||
call delete(g:dir . '/.terraform', 'd')
|
||||
endif
|
||||
|
||||
unlet! b:ale_terraform_langserver_executable
|
||||
unlet! b:ale_terraform_langserver_options
|
||||
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(Should send correct LSP language):
|
||||
AssertLSPLanguage 'terraform'
|
||||
|
||||
Execute(Should load default executable):
|
||||
AssertLinter 'terraform-lsp', ale#Escape('terraform-lsp')
|
||||
|
||||
Execute(Should configure custom executable):
|
||||
let b:ale_terraform_langserver_executable = 'foo'
|
||||
AssertLinter 'foo', ale#Escape('foo')
|
||||
|
||||
Execute(Should set custom options):
|
||||
let b:ale_terraform_langserver_options = '--bar'
|
||||
|
||||
AssertLinter 'terraform-lsp',
|
||||
\ ale#Escape('terraform-lsp') . ' --bar'
|
||||
|
||||
Execute(Should return current directory if it contains .terraform directory):
|
||||
call mkdir(g:dir . '/.terraform')
|
||||
AssertLSPProject g:dir
|
||||
|
||||
Execute(Should return nearest directory with .terraform if found in parent directory):
|
||||
call ale#test#SetFilename('../terraform_files/main.tf')
|
||||
|
||||
let b:parent_dir = ale#path#Simplify(g:dir . '/..')
|
||||
let b:tf_dir = b:parent_dir . '/.terraform'
|
||||
|
||||
if !isdirectory(b:tf_dir)
|
||||
call mkdir(b:tf_dir)
|
||||
endif
|
||||
|
||||
AssertLSPProject b:parent_dir
|
||||
|
||||
call delete(b:tf_dir, 'd')
|
||||
unlet!b:parent_dir
|
||||
unlet!b:tf_dir
|
Loading…
Reference in New Issue