mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 13:34:46 +08:00
#3312 - Just check if additionalTextEdits is non-empty
This commit is contained in:
@@ -496,18 +496,6 @@ function! ale#completion#NullFilter(buffer, item) abort
|
|||||||
return 1
|
return 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Check if additional text edits make changes starting on lines other than the
|
|
||||||
" one you're asking for completions on.
|
|
||||||
function! s:TextEditsChangeOtherLines(line, text_edit_list) abort
|
|
||||||
for l:edit in a:text_edit_list
|
|
||||||
if l:edit.range.start.line + 1 isnot a:line
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
|
|
||||||
return 0
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! ale#completion#ParseLSPCompletions(response) abort
|
function! ale#completion#ParseLSPCompletions(response) abort
|
||||||
let l:buffer = bufnr('')
|
let l:buffer = bufnr('')
|
||||||
let l:info = get(b:, 'ale_completion_info', {})
|
let l:info = get(b:, 'ale_completion_info', {})
|
||||||
@@ -552,9 +540,8 @@ function! ale#completion#ParseLSPCompletions(response) abort
|
|||||||
|
|
||||||
" Don't use LSP items with additional text edits when autoimport for
|
" Don't use LSP items with additional text edits when autoimport for
|
||||||
" completions is turned off.
|
" completions is turned off.
|
||||||
if has_key(l:item, 'additionalTextEdits')
|
if !empty(get(l:item, 'additionalTextEdits'))
|
||||||
\&& !g:ale_completion_autoimport
|
\&& !g:ale_completion_autoimport
|
||||||
\&& s:TextEditsChangeOtherLines(l:info.line, l:item.additionalTextEdits)
|
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -576,15 +563,6 @@ function! ale#completion#ParseLSPCompletions(response) abort
|
|||||||
let l:text_changes = []
|
let l:text_changes = []
|
||||||
|
|
||||||
for l:edit in l:item.additionalTextEdits
|
for l:edit in l:item.additionalTextEdits
|
||||||
" Don't apply additional text edits that are identical to the
|
|
||||||
" word we're going to insert anyway.
|
|
||||||
if l:edit.newText is# l:word
|
|
||||||
\&& l:edit.range.start.line + 1 is l:info.line
|
|
||||||
\&& l:edit.range.end.line + 1 is l:info.line
|
|
||||||
\&& l:edit.range.start.character is l:edit.range.end.character
|
|
||||||
continue
|
|
||||||
endif
|
|
||||||
|
|
||||||
call add(l:text_changes, {
|
call add(l:text_changes, {
|
||||||
\ 'start': {
|
\ 'start': {
|
||||||
\ 'line': l:edit.range.start.line + 1,
|
\ 'line': l:edit.range.start.line + 1,
|
||||||
|
|||||||
@@ -537,7 +537,6 @@ Execute(Should handle completion messages with the deprecated insertText attribu
|
|||||||
|
|
||||||
Execute(Should handle completion messages with additionalTextEdits when ale_completion_autoimport is turned on):
|
Execute(Should handle completion messages with additionalTextEdits when ale_completion_autoimport is turned on):
|
||||||
let g:ale_completion_autoimport = 1
|
let g:ale_completion_autoimport = 1
|
||||||
let b:ale_completion_info = {'line': 30}
|
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [
|
\ [
|
||||||
@@ -592,19 +591,6 @@ Execute(Should handle completion messages with additionalTextEdits when ale_comp
|
|||||||
\ {
|
\ {
|
||||||
\ 'range': {
|
\ 'range': {
|
||||||
\ 'start': {
|
\ 'start': {
|
||||||
\ 'line': 29,
|
|
||||||
\ 'character': 10,
|
|
||||||
\ },
|
|
||||||
\ 'end': {
|
|
||||||
\ 'line': 29,
|
|
||||||
\ 'character': 10,
|
|
||||||
\ },
|
|
||||||
\ },
|
|
||||||
\ 'newText': 'next_callback',
|
|
||||||
\ },
|
|
||||||
\ {
|
|
||||||
\ 'range': {
|
|
||||||
\ 'start': {
|
|
||||||
\ 'line': 10,
|
\ 'line': 10,
|
||||||
\ 'character': 1,
|
\ 'character': 1,
|
||||||
\ },
|
\ },
|
||||||
@@ -645,19 +631,6 @@ Execute(Should not handle completion messages with additionalTextEdits when ale_
|
|||||||
\ {
|
\ {
|
||||||
\ 'range': {
|
\ 'range': {
|
||||||
\ 'start': {
|
\ 'start': {
|
||||||
\ 'line': 29,
|
|
||||||
\ 'character': 10,
|
|
||||||
\ },
|
|
||||||
\ 'end': {
|
|
||||||
\ 'line': 29,
|
|
||||||
\ 'character': 10,
|
|
||||||
\ },
|
|
||||||
\ },
|
|
||||||
\ 'newText': 'next_callback',
|
|
||||||
\ },
|
|
||||||
\ {
|
|
||||||
\ 'range': {
|
|
||||||
\ 'start': {
|
|
||||||
\ 'line': 10,
|
\ 'line': 10,
|
||||||
\ 'character': 1,
|
\ 'character': 1,
|
||||||
\ },
|
\ },
|
||||||
@@ -674,9 +647,8 @@ Execute(Should not handle completion messages with additionalTextEdits when ale_
|
|||||||
\ },
|
\ },
|
||||||
\ })
|
\ })
|
||||||
|
|
||||||
Execute(Should still handle completion messages with additionalTextEdits with ale_completion_autoimport turned off, if edits all start on the line):
|
Execute(Should still handle completion messages with empty additionalTextEdits with ale_completion_autoimport turned off):
|
||||||
let g:ale_completion_autoimport = 0
|
let g:ale_completion_autoimport = 0
|
||||||
let b:ale_completion_info = {'line': 30}
|
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [
|
\ [
|
||||||
@@ -702,21 +674,7 @@ Execute(Should still handle completion messages with additionalTextEdits with al
|
|||||||
\ 'kind': 6,
|
\ 'kind': 6,
|
||||||
\ 'label': ' next_callback',
|
\ 'label': ' next_callback',
|
||||||
\ 'sortText': '3ee19999next_callback',
|
\ 'sortText': '3ee19999next_callback',
|
||||||
\ 'additionalTextEdits': [
|
\ 'additionalTextEdits': [],
|
||||||
\ {
|
|
||||||
\ 'range': {
|
|
||||||
\ 'start': {
|
|
||||||
\ 'line': 29,
|
|
||||||
\ 'character': 10,
|
|
||||||
\ },
|
|
||||||
\ 'end': {
|
|
||||||
\ 'line': 29,
|
|
||||||
\ 'character': 10,
|
|
||||||
\ },
|
|
||||||
\ },
|
|
||||||
\ 'newText': 'next_callback',
|
|
||||||
\ },
|
|
||||||
\ ],
|
|
||||||
\ },
|
\ },
|
||||||
\ ],
|
\ ],
|
||||||
\ },
|
\ },
|
||||||
|
|||||||
Reference in New Issue
Block a user