summaryrefslogtreecommitdiff
path: root/ale_linters/puppet/languageserver.vim
blob: 52880f323fd54b78e5fe4d53c375e6ddbf5431d1 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
" Author: Alexander Olofsson <alexander.olofsson@liu.se>
" Description: Puppet Language Server integration for ALE

call ale#Set('puppet_languageserver_executable', 'puppet-languageserver')

function! ale_linters#puppet#languageserver#GetExecutable(buffer) abort
    return ale#Var(a:buffer, 'puppet_languageserver_executable')
endfunction

function! ale_linters#puppet#languageserver#GetCommand(buffer) abort
    let l:exe = ale#Escape(ale_linters#puppet#languageserver#GetExecutable(a:buffer))

    return l:exe . ' --stdio'
endfunction

function! ale_linters#puppet#languageserver#GetProjectRoot(buffer) abort
    " Note: The metadata.json file is recommended for Puppet 4+ modules, but
    " there's no requirement to have it, so fall back to the other possible
    " Puppet module directories
    let l:root_path = ale#path#FindNearestFile(a:buffer, 'metadata.json')
    if !empty(l:root_path)
        return fnamemodify(l:root_path, ':h')
    endif

    for l:test_path in [
    \   'manifests',
    \   'templates',
    \]
        let l:root_path = ale#path#FindNearestDirectory(a:buffer, l:test_path)
        if !empty(l:root_path)
            return fnamemodify(l:root_path, ':h:h')
        endif
    endfor

    return ''
endfunction

call ale#linter#Define('puppet', {
\   'name': 'languageserver',
\   'lsp': 'stdio',
\   'executable_callback': 'ale_linters#puppet#languageserver#GetExecutable',
\   'command_callback': 'ale_linters#puppet#languageserver#GetCommand',
\   'language': 'puppet',
\   'project_root_callback': 'ale_linters#puppet#languageserver#GetProjectRoot',
\})