]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/deno.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / handlers / deno.vim
1 " Author: Mohammed Chelouti - https://github.com/motato1
2 "         Arnold Chand <creativenull@outlook.com>
3 " Description: Handler functions for Deno.
4
5 call ale#Set('deno_executable', 'deno')
6 call ale#Set('deno_unstable', 0)
7 call ale#Set('deno_import_map', 'import_map.json')
8 call ale#Set('deno_lsp_project_root', '')
9
10 function! ale#handlers#deno#GetExecutable(buffer) abort
11     return ale#Var(a:buffer, 'deno_executable')
12 endfunction
13
14 " Find project root for Deno's language server.
15 "
16 " Deno projects do not require a project or configuration file at the project root.
17 " This means the root directory has to be guessed,
18 " unless it is explicitly specified by the user.
19 "
20 " The project root is determined by ...
21 " 1. using a user-specified value from deno_lsp_project_root
22 " 2. looking for common top-level files/dirs
23 " 3. using the buffer's directory
24 function! ale#handlers#deno#GetProjectRoot(buffer) abort
25     let l:project_root = ale#Var(a:buffer, 'deno_lsp_project_root')
26
27     if !empty(l:project_root)
28         return l:project_root
29     endif
30
31     let l:possible_project_roots = [
32     \   'deno.json',
33     \   'deno.jsonc',
34     \   'tsconfig.json',
35     \   '.git',
36     \   bufname(a:buffer),
37     \]
38
39     for l:possible_root in l:possible_project_roots
40         let l:project_root = ale#path#FindNearestFile(a:buffer, l:possible_root)
41
42         if empty(l:project_root)
43             let l:project_root = ale#path#FindNearestDirectory(a:buffer, l:possible_root)
44         endif
45
46         if !empty(l:project_root)
47             " dir:p expands to /full/path/to/dir/ whereas
48             " file:p expands to /full/path/to/file (no trailing slash)
49             " Appending '/' ensures that :h:h removes the path's last segment
50             " regardless of whether it is a directory or not.
51             return fnamemodify(l:project_root . '/', ':p:h:h')
52         endif
53     endfor
54
55     return ''
56 endfunction
57
58 " Initialization Options for deno, for javascript and typescript
59 function! ale#handlers#deno#GetInitializationOptions(buffer) abort
60     let l:options = {
61     \   'enable': v:true,
62     \   'lint': v:true,
63     \   'unstable': v:false,
64     \   'importMap': ale#path#FindNearestFile(a:buffer, 'import_map.json'),
65     \   }
66
67     if ale#Var(a:buffer, 'deno_unstable')
68         let l:options.unstable = v:true
69     endif
70
71     " Look for a value set using the historical option name.
72     let l:import_map = getbufvar(
73     \   a:buffer,
74     \   'ale_deno_importMap',
75     \   get(g:, 'ale_deno_importMap', '')
76     \)
77
78     if empty(l:import_map)
79         let l:import_map = ale#Var(a:buffer, 'deno_import_map')
80     endif
81
82     if !empty(l:import_map)
83         let l:options.importMap = ale#path#FindNearestFile(a:buffer, l:import_map)
84     endif
85
86     return l:options
87 endfunction