diff options
author | Horacio Sanson <horacio@allm.inc> | 2021-01-30 15:41:40 +0900 |
---|---|---|
committer | Horacio Sanson <horacio@allm.inc> | 2021-01-30 16:09:39 +0900 |
commit | 64d430438ee75f7da5468c3820e1f32e8185f165 (patch) | |
tree | e4ded948e416629e2445bea10a6ab68f6e8ce973 /ale_linters/terraform/terraform_ls.vim | |
parent | 82c8e3a3a3740b520c748ff181e5c29f508b8455 (diff) | |
download | ale-64d430438ee75f7da5468c3820e1f32e8185f165.zip |
Fix 3371 - Add terraform-ls support
Diffstat (limited to 'ale_linters/terraform/terraform_ls.vim')
-rw-r--r-- | ale_linters/terraform/terraform_ls.vim | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ale_linters/terraform/terraform_ls.vim b/ale_linters/terraform/terraform_ls.vim new file mode 100644 index 00000000..ab35126e --- /dev/null +++ b/ale_linters/terraform/terraform_ls.vim @@ -0,0 +1,38 @@ +" Author: Horacio Sanson <hsanson@gmail.com> +" Description: terraform-ls integration for ALE (cf. https://github.com/hashicorp/terraform-ls) + +call ale#Set('terraform_terraform_executable', 'terraform') +call ale#Set('terraform_ls_executable', 'terraform-ls') +call ale#Set('terraform_ls_options', '') + +function! ale_linters#terraform#terraform_ls#GetTerraformExecutable(buffer) abort + let l:terraform_executable = ale#Var(a:buffer, 'terraform_terraform_executable') + + if(ale#path#IsAbsolute(l:terraform_executable)) + return '-tf-exec ' . l:terraform_executable + endif + + return '' +endfunction + +function! ale_linters#terraform#terraform_ls#GetCommand(buffer) abort + return '%e' + \ . ale#Pad('serve') + \ . ale#Pad(ale_linters#terraform#terraform_ls#GetTerraformExecutable(a:buffer)) + \ . ale#Pad(ale#Var(a:buffer, 'terraform_ls_options')) +endfunction + +function! ale_linters#terraform#terraform_ls#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_ls', +\ 'lsp': 'stdio', +\ 'executable': {b -> ale#Var(b, 'terraform_ls_executable')}, +\ 'command': function('ale_linters#terraform#terraform_ls#GetCommand'), +\ 'project_root': function('ale_linters#terraform#terraform_ls#GetProjectRoot'), +\ 'language': 'terraform', +\}) |