summaryrefslogtreecommitdiff
path: root/ale_linters/terraform/terraform_lsp.vim
diff options
context:
space:
mode:
Diffstat (limited to 'ale_linters/terraform/terraform_lsp.vim')
-rw-r--r--ale_linters/terraform/terraform_lsp.vim25
1 files changed, 25 insertions, 0 deletions
diff --git a/ale_linters/terraform/terraform_lsp.vim b/ale_linters/terraform/terraform_lsp.vim
new file mode 100644
index 00000000..e2408c15
--- /dev/null
+++ b/ale_linters/terraform/terraform_lsp.vim
@@ -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',
+\})