summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold Chand <creativenull@outlook.com>2021-07-25 00:39:56 -0400
committerGitHub <noreply@github.com>2021-07-25 13:39:56 +0900
commit8c591996a83d623fb158fe090acbd89dabbfaf06 (patch)
tree048374b84da988f9a31297538f978a3957bb96fe
parent7d8fb2ba1716a744446b811fc278ecf30d4eb771 (diff)
downloadale-8c591996a83d623fb158fe090acbd89dabbfaf06.zip
Add importMap option to deno Initialization Options (#3827)
* feat(deno): move init options to handlers * feat(deno): add deno lsp support for js files * feat(deno): use default map option * feat(docs): add deno import map option * feat(deno): add tests for importMap option * fix(deno): use full path in importMap * feat(deno): remove deno as linter for js, separate PR * fix(deno): test for executable * fix(deno-test): include filename to simplify function
-rw-r--r--ale_linters/typescript/deno.vim17
-rw-r--r--autoload/ale/handlers/deno.vim22
-rw-r--r--doc/ale-typescript.txt6
-rw-r--r--plugin/ale.vim3
-rw-r--r--test/linter/test_typescript_deno_lsp.vader40
-rw-r--r--test/test-files/typescript/custom_import_map.json0
-rw-r--r--test/test-files/typescript/import_map.json0
-rw-r--r--test/test_deno_executable_detection.vader3
8 files changed, 73 insertions, 18 deletions
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 <creativenull@outlook.com>
" 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 <creativenull@outlook.com>
" 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
--- /dev/null
+++ b/test/test-files/typescript/custom_import_map.json
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
--- /dev/null
+++ b/test/test-files/typescript/import_map.json
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()