diff --git a/ale_linters/typescript/deno.vim b/ale_linters/typescript/deno.vim index 051cb208..f47fac7a 100644 --- a/ale_linters/typescript/deno.vim +++ b/ale_linters/typescript/deno.vim @@ -1,4 +1,5 @@ " Author: Mohammed Chelouti - https://github.com/motato1 +" Arnold Chand " Description: Deno lsp linter for TypeScript files. call ale#linter#Define('typescript', { @@ -7,19 +8,5 @@ call ale#linter#Define('typescript', { \ 'executable': function('ale#handlers#deno#GetExecutable'), \ 'command': '%e lsp', \ 'project_root': function('ale#handlers#deno#GetProjectRoot'), -\ 'initialization_options': function('ale_linters#typescript#deno#GetInitializationOptions'), +\ 'initialization_options': function('ale#handlers#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 diff --git a/autoload/ale/handlers/deno.vim b/autoload/ale/handlers/deno.vim index 4bf4546a..1b5e1718 100644 --- a/autoload/ale/handlers/deno.vim +++ b/autoload/ale/handlers/deno.vim @@ -1,8 +1,10 @@ " Author: Mohammed Chelouti - https://github.com/motato1 +" Arnold Chand " Description: Handler functions for Deno. call ale#Set('deno_executable', 'deno') call ale#Set('deno_unstable', 0) +call ale#Set('deno_importMap', 'import_map.json') call ale#Set('deno_lsp_project_root', '') function! ale#handlers#deno#GetExecutable(buffer) abort @@ -50,3 +52,23 @@ function! ale#handlers#deno#GetProjectRoot(buffer) abort return '' endfunction + +" Initialization Options for deno, for javascript and typescript +function! ale#handlers#deno#GetInitializationOptions(buffer) abort + let l:options = { + \ 'enable': v:true, + \ 'lint': v:true, + \ 'unstable': v:false, + \ 'importMap': ale#path#FindNearestFile(a:buffer, 'import_map.json'), + \ } + + if ale#Var(a:buffer, 'deno_unstable') + let l:options.unstable = v:true + endif + + if ale#Var(a:buffer, 'deno_importMap') isnot# '' + let l:options.importMap = ale#path#FindNearestFile(a:buffer, ale#Var(a:buffer, 'deno_importMap')) + endif + + return l:options +endfunction diff --git a/doc/ale-typescript.txt b/doc/ale-typescript.txt index a2446c2c..e2ee49c2 100644 --- a/doc/ale-typescript.txt +++ b/doc/ale-typescript.txt @@ -34,6 +34,12 @@ g:ale_deno_unstable *g:ale_deno_unstable* Enable or disable unstable Deno features and APIs. +g:ale_deno_importMap *g:ale_deno_importMap* + *b:ale_deno_importMap* + Type: |String| + Default: `'import_map.json'` + + Specify the import map filename to load url maps in a deno project. =============================================================================== eslint *ale-typescript-eslint* diff --git a/plugin/ale.vim b/plugin/ale.vim index 0268bc99..d19824b1 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -178,6 +178,9 @@ let g:ale_python_auto_poetry = get(g:, 'ale_python_auto_poetry', 0) " This variable can be overridden to set the GO111MODULE environment variable. let g:ale_go_go111module = get(g:, 'ale_go_go111module', '') +" Default executable for deno, needed set before plugin start +let g:ale_deno_executable = get(g:, 'ale_deno_executable', 'deno') + " If 1, enable a popup menu for commands. let g:ale_popup_menu_enabled = get(g:, 'ale_popup_menu_enabled', has('gui_running')) diff --git a/test/linter/test_typescript_deno_lsp.vader b/test/linter/test_typescript_deno_lsp.vader index 88b2e036..944f6a0a 100644 --- a/test/linter/test_typescript_deno_lsp.vader +++ b/test/linter/test_typescript_deno_lsp.vader @@ -1,4 +1,5 @@ Before: + let g:ale_deno_importMap = 'import_map.json' let g:ale_deno_unstable = 0 let g:ale_deno_executable = 'deno' let g:ale_deno_lsp_project_root = '' @@ -13,7 +14,8 @@ Execute(Should set deno lsp for TypeScript projects using stable Deno API): AssertLSPOptions { \ 'enable': v:true, \ 'lint': v:true, - \ 'unstable': v:false + \ 'unstable': v:false, + \ 'importMap': '' \} Execute(Should set deno lsp using unstable Deno API if enabled by user): @@ -22,7 +24,41 @@ Execute(Should set deno lsp using unstable Deno API if enabled by user): AssertLSPOptions { \ 'enable': v:true, \ 'lint': v:true, - \ 'unstable': v:true + \ 'unstable': v:true, + \ 'importMap': '' + \} + +Execute(Should set the default importMap filepath): + call ale#test#SetFilename('../test-files/typescript/test.ts') + + AssertLSPOptions { + \ 'enable': v:true, + \ 'lint': v:true, + \ 'unstable': v:false, + \ 'importMap': ale#path#Simplify(g:dir . '/../test-files/typescript/import_map.json') + \} + +Execute(Should set the importMap filepath from user defined importMap): + let g:ale_deno_importMap = 'custom_import_map.json' + call ale#test#SetFilename('../test-files/typescript/test.ts') + + AssertLSPOptions { + \ 'enable': v:true, + \ 'lint': v:true, + \ 'unstable': v:false, + \ 'importMap': ale#path#Simplify(g:dir . '/../test-files/typescript/custom_import_map.json') + \} + +Execute(Should set the importMap filepath from user defined importMap with unstable API): + let g:ale_deno_importMap = 'custom_import_map.json' + let g:ale_deno_unstable = 1 + call ale#test#SetFilename('../test-files/typescript/test.ts') + + AssertLSPOptions { + \ 'enable': v:true, + \ 'lint': v:true, + \ 'unstable': v:true, + \ 'importMap': ale#path#Simplify(g:dir . '/../test-files/typescript/custom_import_map.json') \} Execute(Should find project root containing tsconfig.json): diff --git a/test/test-files/typescript/custom_import_map.json b/test/test-files/typescript/custom_import_map.json new file mode 100644 index 00000000..e69de29b diff --git a/test/test-files/typescript/import_map.json b/test/test-files/typescript/import_map.json new file mode 100644 index 00000000..e69de29b diff --git a/test/test_deno_executable_detection.vader b/test/test_deno_executable_detection.vader index edd408b1..87690bfe 100644 --- a/test/test_deno_executable_detection.vader +++ b/test/test_deno_executable_detection.vader @@ -1,8 +1,9 @@ Before: + Save g:ale_deno_executable runtime autoload/ale/handlers/deno.vim After: - unlet! g:ale_deno_executable + unlet! b:ale_deno_executable call ale#linter#Reset()