summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorMohammed Chelouti <70812484+motato1@users.noreply.github.com>2020-12-29 21:46:02 +0100
committerMohammed Chelouti <70812484+motato1@users.noreply.github.com>2021-01-22 19:06:53 +0100
commit9b362634f7210657d94870b017e969bdcdda8de0 (patch)
treebb08e4a17bf156f54babd40207c6ee1f8ec51b5e /autoload
parent4f2666265a09cceac2e4091dc871107e418f1f67 (diff)
downloadale-9b362634f7210657d94870b017e969bdcdda8de0.zip
feat: Add Deno lsp support
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/handlers/deno.vim43
1 files changed, 43 insertions, 0 deletions
diff --git a/autoload/ale/handlers/deno.vim b/autoload/ale/handlers/deno.vim
index 636c25da..4bf4546a 100644
--- a/autoload/ale/handlers/deno.vim
+++ b/autoload/ale/handlers/deno.vim
@@ -3,7 +3,50 @@
call ale#Set('deno_executable', 'deno')
call ale#Set('deno_unstable', 0)
+call ale#Set('deno_lsp_project_root', '')
function! ale#handlers#deno#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'deno_executable')
endfunction
+
+" Find project root for Deno's language server.
+"
+" Deno projects do not require a project or configuration file at the project root.
+" This means the root directory has to be guessed,
+" unless it is explicitly specified by the user.
+"
+" The project root is determined by ...
+" 1. using a user-specified value from deno_lsp_project_root
+" 2. looking for common top-level files/dirs
+" 3. using the buffer's directory
+function! ale#handlers#deno#GetProjectRoot(buffer) abort
+ let l:project_root = ale#Var(a:buffer, 'deno_lsp_project_root')
+
+ if !empty(l:project_root)
+ return l:project_root
+ endif
+
+ let l:possible_project_roots = [
+ \ 'tsconfig.json',
+ \ '.git',
+ \ bufname(a:buffer),
+ \]
+
+ for l:possible_root in l:possible_project_roots
+ let l:project_root = ale#path#FindNearestFile(a:buffer, l:possible_root)
+
+ if empty(l:project_root)
+ let l:project_root = ale#path#FindNearestDirectory(a:buffer, l:possible_root)
+ endif
+
+ if !empty(l:project_root)
+ " dir:p expands to /full/path/to/dir/ whereas
+ " file:p expands to /full/path/to/file (no trailing slash)
+ " Appending '/' ensures that :h:h removes the path's last segment
+ " regardless of whether it is a directory or not.
+ return fnamemodify(l:project_root . '/', ':p:h:h')
+ endif
+ endfor
+
+ return ''
+endfunction