feat: Add Deno lsp support
This commit is contained in:
parent
4f2666265a
commit
9b362634f7
5 changed files with 129 additions and 0 deletions
25
ale_linters/typescript/deno.vim
Normal file
25
ale_linters/typescript/deno.vim
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
" Author: Mohammed Chelouti - https://github.com/motato1
|
||||||
|
" Description: Deno lsp linter for TypeScript files.
|
||||||
|
|
||||||
|
call ale#linter#Define('typescript', {
|
||||||
|
\ 'name': 'deno',
|
||||||
|
\ 'lsp': 'stdio',
|
||||||
|
\ 'executable': function('ale#handlers#deno#GetExecutable'),
|
||||||
|
\ 'command': '%e lsp',
|
||||||
|
\ 'project_root': function('ale#handlers#deno#GetProjectRoot'),
|
||||||
|
\ 'initialization_options': function('ale_linters#typescript#deno#GetInitializationOptions'),
|
||||||
|
\})
|
||||||
|
|
||||||
|
function! ale_linters#typescript#deno#GetInitializationOptions(buffer) abort
|
||||||
|
let l:options = {
|
||||||
|
\ 'enable': v:true,
|
||||||
|
\ 'lint': v:true,
|
||||||
|
\ 'unstable': v:false,
|
||||||
|
\ }
|
||||||
|
|
||||||
|
if ale#Var(a:buffer, 'deno_unstable')
|
||||||
|
let l:options.unstable = v:true
|
||||||
|
endif
|
||||||
|
|
||||||
|
return l:options
|
||||||
|
endfunction
|
|
@ -3,7 +3,50 @@
|
||||||
|
|
||||||
call ale#Set('deno_executable', 'deno')
|
call ale#Set('deno_executable', 'deno')
|
||||||
call ale#Set('deno_unstable', 0)
|
call ale#Set('deno_unstable', 0)
|
||||||
|
call ale#Set('deno_lsp_project_root', '')
|
||||||
|
|
||||||
function! ale#handlers#deno#GetExecutable(buffer) abort
|
function! ale#handlers#deno#GetExecutable(buffer) abort
|
||||||
return ale#Var(a:buffer, 'deno_executable')
|
return ale#Var(a:buffer, 'deno_executable')
|
||||||
endfunction
|
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
|
||||||
|
|
61
test/command_callback/test_typescript_deno_lsp.vader
Normal file
61
test/command_callback/test_typescript_deno_lsp.vader
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
Before:
|
||||||
|
let g:ale_deno_unstable = 0
|
||||||
|
let g:ale_deno_executable = 'deno'
|
||||||
|
let g:ale_deno_project_root = ''
|
||||||
|
|
||||||
|
runtime autoload/ale/handlers/deno.vim
|
||||||
|
call ale#assert#SetUpLinterTest('typescript', 'deno')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(Should set deno lsp for TypeScript projects using stable Deno API):
|
||||||
|
AssertLSPLanguage 'typescript'
|
||||||
|
AssertLSPConfig {}
|
||||||
|
AssertLSPProject ale#path#Simplify(g:dir . '/../..')
|
||||||
|
AssertLSPOptions {
|
||||||
|
\ 'enable': v:true,
|
||||||
|
\ 'lint': v:true,
|
||||||
|
\ 'unstable': v:false
|
||||||
|
\}
|
||||||
|
|
||||||
|
Execute(Should set deno lsp using unstable Deno API if enabled by user):
|
||||||
|
let g:ale_deno_unstable = 1
|
||||||
|
AssertLSPLanguage 'typescript'
|
||||||
|
AssertLSPConfig {}
|
||||||
|
AssertLSPProject ale#path#Simplify(g:dir . '/../..')
|
||||||
|
AssertLSPOptions {
|
||||||
|
\ 'enable': v:true,
|
||||||
|
\ 'lint': v:true,
|
||||||
|
\ 'unstable': v:true
|
||||||
|
\}
|
||||||
|
|
||||||
|
Execute(Should find project root containing tsconfig.json):
|
||||||
|
call ale#test#SetFilename('../typescript/test.ts')
|
||||||
|
AssertLSPLanguage 'typescript'
|
||||||
|
AssertLSPConfig {}
|
||||||
|
AssertLSPProject ale#path#Simplify(g:dir . '/../typescript')
|
||||||
|
AssertLSPOptions {
|
||||||
|
\ 'enable': v:true,
|
||||||
|
\ 'lint': v:true,
|
||||||
|
\ 'unstable': v:false
|
||||||
|
\}
|
||||||
|
|
||||||
|
Execute(Should use user-specified project root):
|
||||||
|
let g:ale_deno_lsp_project_root = '/'
|
||||||
|
|
||||||
|
call ale#test#SetFilename('../typescript/test.ts')
|
||||||
|
AssertLSPLanguage 'typescript'
|
||||||
|
AssertLSPConfig {}
|
||||||
|
AssertLSPProject '/'
|
||||||
|
AssertLSPOptions {
|
||||||
|
\ 'enable': v:true,
|
||||||
|
\ 'lint': v:true,
|
||||||
|
\ 'unstable': v:false
|
||||||
|
\}
|
||||||
|
|
||||||
|
|
||||||
|
Execute(Check Deno LSP command):
|
||||||
|
AssertLinter 'deno', [
|
||||||
|
\ ale#Escape('deno') . ' lsp',
|
||||||
|
\]
|
0
test/typescript/test.ts
Normal file
0
test/typescript/test.ts
Normal file
0
test/typescript/tsconfig.json
Normal file
0
test/typescript/tsconfig.json
Normal file
Reference in a new issue