]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/vue/volar.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:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / ale_linters / vue / volar.vim
1 " Author: Arnold Chand <creativenull@outlook.com>
2 " Description: Volar Language Server integration for ALE adopted from
3 "              nvim-lspconfig and volar/packages/shared/src/types.ts
4
5 call ale#Set('vue_volar_executable', 'vue-language-server')
6 call ale#Set('vue_volar_use_global', 1)
7 call ale#Set('vue_volar_init_options', {
8 \   'typescript': { 'tsdk': '' },
9 \})
10
11 function! ale_linters#vue#volar#GetProjectRoot(buffer) abort
12     let l:project_roots = [
13     \   'package.json',
14     \   'vite.config.js',
15     \   'vite.config.mjs',
16     \   'vite.config.cjs',
17     \   'vite.config.ts',
18     \   '.git',
19     \   bufname(a:buffer)
20     \]
21
22     for l:project_root in l:project_roots
23         let l:nearest_filepath = ale#path#FindNearestFile(a:buffer, l:project_root)
24
25         if !empty(l:nearest_filepath)
26             return fnamemodify(l:nearest_filepath, ':h')
27         endif
28     endfor
29
30     return ''
31 endfunction
32
33 function! ale_linters#vue#volar#GetInitializationOptions(buffer) abort
34     let l:tsserver_path = ale#path#FindNearestDirectory(a:buffer, 'node_modules/typescript/lib')
35
36     if l:tsserver_path is# ''
37         " no-custom-checks
38         echohl WarningMsg
39         " no-custom-checks
40         echom '[volar] Must have typescript installed in project, please install via `npm install -D typescript`.'
41         " no-custom-checks
42         echohl None
43     endif
44
45     let l:init_options = ale#Var(a:buffer, 'vue_volar_init_options')
46     let l:init_options.typescript.tsdk = l:tsserver_path
47
48     return l:init_options
49 endfunction
50
51 call ale#linter#Define('vue', {
52 \   'name': 'volar',
53 \   'language': 'vue',
54 \   'lsp': 'stdio',
55 \   'executable': {b -> ale#path#FindExecutable(b, 'vue_volar', ['node_modules/.bin/vue-language-server'])},
56 \   'command': '%e --stdio',
57 \   'project_root': function('ale_linters#vue#volar#GetProjectRoot'),
58 \   'initialization_options': function('ale_linters#vue#volar#GetInitializationOptions'),
59 \})