@@ -14,6 +14,70 @@ function! lsp#utils#text_edit#apply_text_edits(uri, text_edits) abort
14
14
endif
15
15
endfunction
16
16
17
+ " @summary Use this to convert textedit to vim list that is compatible with
18
+ " quickfix and locllist items
19
+ " @param uri = DocumentUri
20
+ " @param text_edit = TextEdit | TextEdit[]
21
+ " @returns []
22
+ function ! lsp#utils#text_edit#_lsp_to_vim_list (uri, text_edit) abort
23
+ let l: result = []
24
+ let l: cache = {}
25
+ if type (a: text_edit ) == type ([]) " TextEdit[]
26
+ for l: text_edit in a: text_edit
27
+ let l: vim_loc = s: lsp_text_edit_item_to_vim (a: uri , l: text_edit , l: cache )
28
+ if ! empty (l: vim_loc )
29
+ call add (l: result , l: vim_loc )
30
+ endif
31
+ endfor
32
+ else " TextEdit
33
+ let l: vim_loc = s: lsp_text_edit_item_to_vim (a: uri , a: text_edit , l: cache )
34
+ if ! empty (l: vim_loc )
35
+ call add (l: result , l: vim_loc )
36
+ endif
37
+ endif
38
+ return l: result
39
+ endfunction
40
+
41
+ " @param uri = DocumentUri
42
+ " @param text_edit = TextEdit
43
+ " @param cache = {} empty dict
44
+ " @returns {
45
+ " 'filename',
46
+ " 'lnum',
47
+ " 'col',
48
+ " 'text',
49
+ " }
50
+ function ! s: lsp_text_edit_item_to_vim (uri, text_edit, cache) abort
51
+ if ! lsp#utils#is_file_uri (a: uri )
52
+ return v: null
53
+ endif
54
+
55
+ let l: path = lsp#utils#uri_to_path (a: uri )
56
+ let l: range = a: text_edit [' range' ]
57
+ let [l: line , l: col ] = lsp#utils#position#lsp_to_vim (l: path , l: range [' start' ])
58
+
59
+ let l: index = l: line - 1
60
+ if has_key (a: cache , l: path )
61
+ let l: text = a: cache [l: path ][l: index ]
62
+ else
63
+ let l: contents = getbufline (l: path , 1 , ' $' )
64
+ if ! empty (l: contents )
65
+ let l: text = get (l: contents , l: index , ' ' )
66
+ else
67
+ let l: contents = readfile (l: path )
68
+ let a: cache [l: path ] = l: contents
69
+ let l: text = get (l: contents , l: index , ' ' )
70
+ endif
71
+ endif
72
+
73
+ return {
74
+ \ ' filename' : l: path ,
75
+ \ ' lnum' : l: line ,
76
+ \ ' col' : l: col ,
77
+ \ ' text' : l: text
78
+ \ }
79
+ endfunction
80
+
17
81
"
18
82
" _apply
19
83
"
0 commit comments