Skip to content

Commit 74988e4

Browse files
tsufekiprabirshrestha
authored andcommitted
Fix WorkspaceEdit with both documentChanges and changes. (#368)
Prefer `documentChanges` property over `changes` when both are present in a WorkspaceEdit, complying to the spec: https://microsoft.github.io/language-server-protocol/specification#workspaceedit
1 parent 3deb1fb commit 74988e4

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

autoload/lsp/utils/workspace_edit.vim

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
" Applies WorkspaceEdit changes.
22
function! lsp#utils#workspace_edit#apply_workspace_edit(workspace_edit) abort
3-
if has_key(a:workspace_edit, 'changes')
3+
if has_key(a:workspace_edit, 'documentChanges')
44
let l:cur_buffer = bufnr('%')
55
let l:view = winsaveview()
6-
for [l:uri, l:text_edits] in items(a:workspace_edit['changes'])
7-
call lsp#utils#text_edit#apply_text_edits(l:uri, l:text_edits)
6+
for l:text_document_edit in a:workspace_edit['documentChanges']
7+
call lsp#utils#text_edit#apply_text_edits(l:text_document_edit['textDocument']['uri'], l:text_document_edit['edits'])
88
endfor
99
if l:cur_buffer !=# bufnr('%')
1010
execute 'keepjumps keepalt b ' . l:cur_buffer
1111
endif
1212
call winrestview(l:view)
13-
endif
14-
if has_key(a:workspace_edit, 'documentChanges')
13+
elseif has_key(a:workspace_edit, 'changes')
1514
let l:cur_buffer = bufnr('%')
1615
let l:view = winsaveview()
17-
for l:text_document_edit in a:workspace_edit['documentChanges']
18-
call lsp#utils#text_edit#apply_text_edits(l:text_document_edit['textDocument']['uri'], l:text_document_edit['edits'])
16+
for [l:uri, l:text_edits] in items(a:workspace_edit['changes'])
17+
call lsp#utils#text_edit#apply_text_edits(l:uri, l:text_edits)
1918
endfor
2019
if l:cur_buffer !=# bufnr('%')
2120
execute 'keepjumps keepalt b ' . l:cur_buffer

0 commit comments

Comments
 (0)