summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorpinicarus <pinicarus@protonmail.com>2020-11-01 11:45:36 +0100
committerpinicarus <pinicarus@protonmail.com>2020-11-01 11:45:36 +0100
commitdb96b007209f7ea0983c58cb1d18771f5a45a543 (patch)
tree092fb643e078359c8e8356c41fc7cb50ceb355e7 /autoload
parentd7557ef9be6ce680e811e31e217db5624d9e2897 (diff)
parent62f2c6d3261af41ef01db6868724881fd6eebccc (diff)
downloadale-db96b007209f7ea0983c58cb1d18771f5a45a543.zip
Merge branch 'custom-erlc-executable'
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/code_action.vim23
-rw-r--r--autoload/ale/completion.vim2
-rw-r--r--autoload/ale/maven.vim51
-rw-r--r--autoload/ale/organize_imports.vim11
-rw-r--r--autoload/ale/rename.vim59
5 files changed, 110 insertions, 36 deletions
diff --git a/autoload/ale/code_action.vim b/autoload/ale/code_action.vim
index 8c7263f3..42f4f265 100644
--- a/autoload/ale/code_action.vim
+++ b/autoload/ale/code_action.vim
@@ -1,26 +1,33 @@
" Author: Jerko Steiner <jerko.steiner@gmail.com>
" Description: Code action support for LSP / tsserver
-function! ale#code_action#HandleCodeAction(code_action, should_save) abort
+function! ale#code_action#HandleCodeAction(code_action, options) abort
let l:current_buffer = bufnr('')
let l:changes = a:code_action.changes
+ let l:should_save = get(a:options, 'should_save')
+ let l:force_save = get(a:options, 'force_save')
+ let l:safe_changes = []
for l:file_code_edit in l:changes
let l:buf = bufnr(l:file_code_edit.fileName)
if l:buf != -1 && l:buf != l:current_buffer && getbufvar(l:buf, '&mod')
- call ale#util#Execute('echom ''Aborting action, file is unsaved''')
+ if !l:force_save
+ call ale#util#Execute('echom ''Aborting action, file is unsaved''')
- return
+ return
+ endif
+ else
+ call add(l:safe_changes, l:file_code_edit)
endif
endfor
- for l:file_code_edit in l:changes
+ for l:file_code_edit in l:safe_changes
call ale#code_action#ApplyChanges(
- \ l:file_code_edit.fileName,
- \ l:file_code_edit.textChanges,
- \ a:should_save,
- \ )
+ \ l:file_code_edit.fileName,
+ \ l:file_code_edit.textChanges,
+ \ l:should_save,
+ \)
endfor
endfunction
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim
index ecd93600..efbf0fd5 100644
--- a/autoload/ale/completion.vim
+++ b/autoload/ale/completion.vim
@@ -1006,7 +1006,7 @@ function! ale#completion#HandleUserData(completed_item) abort
\|| l:source is# 'ale-import'
\|| l:source is# 'ale-omnifunc'
for l:code_action in get(l:user_data, 'code_actions', [])
- call ale#code_action#HandleCodeAction(l:code_action, v:false)
+ call ale#code_action#HandleCodeAction(l:code_action, {})
endfor
endif
diff --git a/autoload/ale/maven.vim b/autoload/ale/maven.vim
new file mode 100644
index 00000000..745f8c93
--- /dev/null
+++ b/autoload/ale/maven.vim
@@ -0,0 +1,51 @@
+" Description: Functions for working with Maven projects.
+"
+" Given a buffer number, find a Maven project root.
+function! ale#maven#FindProjectRoot(buffer) abort
+ let l:wrapper_path = ale#path#FindNearestFile(a:buffer, 'mvnw')
+
+ if !empty(l:wrapper_path)
+ return fnamemodify(l:wrapper_path, ':h')
+ endif
+
+ let l:pom_path = ale#path#FindNearestFile(a:buffer, 'pom.xml')
+
+ if !empty(l:pom_path)
+ return fnamemodify(l:pom_path, ':h')
+ endif
+
+ return ''
+endfunction
+
+
+" Given a buffer number, find the path to the executable.
+" First search on the path for 'mvnw' (mvnw.cmd on Windows), if nothing is found,
+" try the global command. Returns an empty string if cannot find the executable.
+function! ale#maven#FindExecutable(buffer) abort
+ let l:wrapper_cmd = has('unix') ? 'mvnw' : 'mvnw.cmd'
+ let l:wrapper_path = ale#path#FindNearestFile(a:buffer, l:wrapper_cmd)
+
+ if executable(l:wrapper_path)
+ return l:wrapper_path
+ endif
+
+ if executable('mvn')
+ return 'mvn'
+ endif
+
+ return ''
+endfunction
+
+" Given a buffer number, build a command to print the classpath of the root
+" project. Returns an empty string if cannot build the command.
+function! ale#maven#BuildClasspathCommand(buffer) abort
+ let l:executable = ale#maven#FindExecutable(a:buffer)
+ let l:project_root = ale#maven#FindProjectRoot(a:buffer)
+
+ if !empty(l:executable) && !empty(l:project_root)
+ return ale#path#CdString(l:project_root)
+ \ . l:executable . ' dependency:build-classpath'
+ endif
+
+ return ''
+endfunction
diff --git a/autoload/ale/organize_imports.vim b/autoload/ale/organize_imports.vim
index e89c832c..e2b1c0d2 100644
--- a/autoload/ale/organize_imports.vim
+++ b/autoload/ale/organize_imports.vim
@@ -12,10 +12,13 @@ function! ale#organize_imports#HandleTSServerResponse(conn_id, response) abort
let l:file_code_edits = a:response.body
- call ale#code_action#HandleCodeAction({
- \ 'description': 'Organize Imports',
- \ 'changes': l:file_code_edits,
- \}, v:false)
+ call ale#code_action#HandleCodeAction(
+ \ {
+ \ 'description': 'Organize Imports',
+ \ 'changes': l:file_code_edits,
+ \ },
+ \ {}
+ \)
endfunction
function! s:OnReady(linter, lsp_details) abort
diff --git a/autoload/ale/rename.vim b/autoload/ale/rename.vim
index 64952e63..8190411d 100644
--- a/autoload/ale/rename.vim
+++ b/autoload/ale/rename.vim
@@ -33,9 +33,10 @@ function! ale#rename#HandleTSServerResponse(conn_id, response) abort
return
endif
- let l:old_name = s:rename_map[a:response.request_seq].old_name
- let l:new_name = s:rename_map[a:response.request_seq].new_name
- call remove(s:rename_map, a:response.request_seq)
+ let l:options = remove(s:rename_map, a:response.request_seq)
+
+ let l:old_name = l:options.old_name
+ let l:new_name = l:options.new_name
if get(a:response, 'success', v:false) is v:false
let l:message = get(a:response, 'message', 'unknown')
@@ -77,10 +78,16 @@ function! ale#rename#HandleTSServerResponse(conn_id, response) abort
return
endif
- call ale#code_action#HandleCodeAction({
- \ 'description': 'rename',
- \ 'changes': l:changes,
- \}, v:true)
+ call ale#code_action#HandleCodeAction(
+ \ {
+ \ 'description': 'rename',
+ \ 'changes': l:changes,
+ \ },
+ \ {
+ \ 'should_save': 1,
+ \ 'force_save': get(l:options, 'force_save'),
+ \ },
+ \)
endfunction
function! s:getChanges(workspace_edit) abort
@@ -111,7 +118,7 @@ endfunction
function! ale#rename#HandleLSPResponse(conn_id, response) abort
if has_key(a:response, 'id')
\&& has_key(s:rename_map, a:response.id)
- call remove(s:rename_map, a:response.id)
+ let l:options = remove(s:rename_map, a:response.id)
if !has_key(a:response, 'result')
call s:message('No rename result received from server')
@@ -156,14 +163,20 @@ function! ale#rename#HandleLSPResponse(conn_id, response) abort
\})
endfor
- call ale#code_action#HandleCodeAction({
- \ 'description': 'rename',
- \ 'changes': l:changes,
- \}, v:true)
+ call ale#code_action#HandleCodeAction(
+ \ {
+ \ 'description': 'rename',
+ \ 'changes': l:changes,
+ \ },
+ \ {
+ \ 'should_save': 1,
+ \ 'force_save': get(l:options, 'force_save'),
+ \ },
+ \)
endif
endfunction
-function! s:OnReady(line, column, old_name, new_name, linter, lsp_details) abort
+function! s:OnReady(line, column, options, linter, lsp_details) abort
let l:id = a:lsp_details.connection_id
if !ale#lsp#HasCapability(l:id, 'rename')
@@ -195,19 +208,16 @@ function! s:OnReady(line, column, old_name, new_name, linter, lsp_details) abort
\ l:buffer,
\ a:line,
\ a:column,
- \ a:new_name
+ \ a:options.new_name
\)
endif
let l:request_id = ale#lsp#Send(l:id, l:message)
- let s:rename_map[l:request_id] = {
- \ 'new_name': a:new_name,
- \ 'old_name': a:old_name,
- \}
+ let s:rename_map[l:request_id] = a:options
endfunction
-function! s:ExecuteRename(linter, old_name, new_name) abort
+function! s:ExecuteRename(linter, options) abort
let l:buffer = bufnr('')
let [l:line, l:column] = getpos('.')[1:2]
@@ -215,12 +225,11 @@ function! s:ExecuteRename(linter, old_name, new_name) abort
let l:column = min([l:column, len(getline(l:line))])
endif
- let l:Callback = function(
- \ 's:OnReady', [l:line, l:column, a:old_name, a:new_name])
+ let l:Callback = function('s:OnReady', [l:line, l:column, a:options])
call ale#lsp_linter#StartLSP(l:buffer, a:linter, l:Callback)
endfunction
-function! ale#rename#Execute() abort
+function! ale#rename#Execute(options) abort
let l:lsp_linters = []
for l:linter in ale#linter#Get(&filetype)
@@ -245,6 +254,10 @@ function! ale#rename#Execute() abort
endif
for l:lsp_linter in l:lsp_linters
- call s:ExecuteRename(l:lsp_linter, l:old_name, l:new_name)
+ call s:ExecuteRename(l:lsp_linter, {
+ \ 'old_name': l:old_name,
+ \ 'new_name': l:new_name,
+ \ 'force_save': get(a:options, 'force_save') is 1,
+ \})
endfor
endfunction