]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/haskell/hls.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / ale / ale_linters / haskell / hls.vim
1 " Author: Yen3 <yen3rc@gmail.com>
2 " Description: A language server for haskell
3 "              The file is based on hie.vim (author: Luxed
4 "              <devildead13@gmail.com>).  It search more project root files.
5 "
6 call ale#Set('haskell_hls_executable', 'haskell-language-server-wrapper')
7 call ale#Set('haskell_hls_config', {})
8
9 function! ale_linters#haskell#hls#FindRootFile(buffer) abort
10     let l:serach_root_files = [
11     \ 'stack.yaml',
12     \ 'cabal.project',
13     \ 'package.yaml',
14     \ 'hie.yaml'
15     \ ]
16
17     for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
18         for l:root_file in l:serach_root_files
19             if filereadable(l:path . '/' . l:root_file)
20                 " Add on / so fnamemodify(..., ':h') below keeps the path.
21                 return l:path . '/'
22             endif
23         endfor
24     endfor
25
26     return ''
27 endfunction
28
29 function! ale_linters#haskell#hls#GetProjectRoot(buffer) abort
30     " Search for the project file first
31     let l:project_file = ale_linters#haskell#hls#FindRootFile(a:buffer)
32
33     " If it's empty, search for the cabal file
34     if empty(l:project_file)
35         " Search all of the paths except for the root filesystem path.
36         let l:paths = join(
37         \   ale#path#Upwards(expand('#' . a:buffer . ':p:h'))[:-2],
38         \   ','
39         \)
40         let l:project_file = globpath(l:paths, '*.cabal')
41     endif
42
43     " If we still can't find one, use the current file.
44     if empty(l:project_file)
45         let l:project_file = expand('#' . a:buffer . ':p')
46     endif
47
48     return fnamemodify(l:project_file, ':h')
49 endfunction
50
51 function! ale_linters#haskell#hls#GetCommand(buffer) abort
52     let l:executable = ale#Var(a:buffer, 'haskell_hls_executable')
53
54     return ale#handlers#haskell_stack#EscapeExecutable(l:executable,
55     \ 'haskell-language-server-wrapper')
56     \ . ' --lsp'
57 endfunction
58
59 call ale#linter#Define('haskell', {
60 \   'name': 'hls',
61 \   'lsp': 'stdio',
62 \   'command': function('ale_linters#haskell#hls#GetCommand'),
63 \   'executable': {b -> ale#Var(b, 'haskell_hls_executable')},
64 \   'project_root': function('ale_linters#haskell#hls#GetProjectRoot'),
65 \   'lsp_config': {b -> ale#Var(b, 'haskell_hls_config')},
66 \})