Updated plugins
This commit is contained in:
@@ -9,30 +9,44 @@ endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform#GetCommand(buffer) abort
|
||||
return ale#Escape(ale_linters#terraform#terraform#GetExecutable(a:buffer))
|
||||
\ . ' fmt -no-color --check=true -'
|
||||
\ . ' validate -no-color -json '
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform#GetType(severity) abort
|
||||
if a:severity is? 'warning'
|
||||
return 'W'
|
||||
endif
|
||||
|
||||
return 'E'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform#GetDetail(error) abort
|
||||
return get(a:error, 'detail', get(a:error, 'summary', ''))
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform#Handle(buffer, lines) abort
|
||||
let l:head = '^Error running fmt: In <standard input>: '
|
||||
let l:output = []
|
||||
let l:patterns = [
|
||||
\ l:head.'At \(\d\+\):\(\d\+\): \(.*\)$',
|
||||
\ l:head.'\(.*\)$'
|
||||
\]
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:patterns)
|
||||
if len(l:match[2]) > 0
|
||||
let l:errors = ale#util#FuzzyJSONDecode(a:lines, {'diagnostics': []})
|
||||
let l:dir = expand('#' . a:buffer . ':p:h')
|
||||
let l:file = expand('#' . a:buffer . ':p')
|
||||
|
||||
for l:error in l:errors['diagnostics']
|
||||
if has_key(l:error, 'range')
|
||||
call add(l:output, {
|
||||
\ 'lnum': str2nr(l:match[1]),
|
||||
\ 'col': str2nr(l:match[2]),
|
||||
\ 'text': l:match[3],
|
||||
\ 'type': 'E',
|
||||
\ 'filename': ale#path#GetAbsPath(l:dir, l:error['range']['filename']),
|
||||
\ 'lnum': l:error['range']['start']['line'],
|
||||
\ 'col': l:error['range']['start']['column'],
|
||||
\ 'text': ale_linters#terraform#terraform#GetDetail(l:error),
|
||||
\ 'type': ale_linters#terraform#terraform#GetType(l:error['severity']),
|
||||
\})
|
||||
else
|
||||
call add(l:output, {
|
||||
\ 'lnum': line('$'),
|
||||
\ 'text': l:match[1],
|
||||
\ 'type': 'E',
|
||||
\ 'filename': l:file,
|
||||
\ 'lnum': 0,
|
||||
\ 'col': 0,
|
||||
\ 'text': ale_linters#terraform#terraform#GetDetail(l:error),
|
||||
\ 'type': ale_linters#terraform#terraform#GetType(l:error['severity']),
|
||||
\})
|
||||
endif
|
||||
endfor
|
||||
@@ -42,7 +56,7 @@ endfunction
|
||||
|
||||
call ale#linter#Define('terraform', {
|
||||
\ 'name': 'terraform',
|
||||
\ 'output_stream': 'stderr',
|
||||
\ 'output_stream': 'stdout',
|
||||
\ 'executable': function('ale_linters#terraform#terraform#GetExecutable'),
|
||||
\ 'command': function('ale_linters#terraform#terraform#GetCommand'),
|
||||
\ 'callback': 'ale_linters#terraform#terraform#Handle',
|
||||
|
||||
@@ -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',
|
||||
\})
|
||||
Reference in New Issue
Block a user