summaryrefslogtreecommitdiff
path: root/ale_linters/terraform/terraform_lsp.vim
blob: e2408c15ec2455627831835400d55201effbd789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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',
\})