@@ -120,6 +120,26 @@ function! s:open_new_buffer(ctx, server, type, data) abort
120
120
execute ' call cursor(' . l: line . ' ,' . l: col . ' )'
121
121
endfunction
122
122
123
+ function ! s: normalize_target_uris (result) abort
124
+ " When run `:LspDenoDefinition` at Deno's built-in function like `console`
125
+ " `targetUri` is `deno:/asset/lib.deno.shared_globals.d.ts`.
126
+ " Run `:LspDenoDefinition` again,
127
+ " Deno targetUri is `file:///path/to/deno/project/deno%3A/asset/lib.deno.shared_globals.d.ts`
128
+ " and it contains extra file path before `deno:/`
129
+ " Remove unecessary path from all targetUri for display the definition.
130
+ for item in a: result
131
+ if ! has_key (item, ' targetUri' )
132
+ continue
133
+ endif
134
+ let l: target_uri = item[' targetUri' ]
135
+ if match (l: target_uri , ' ^file:///.*/deno%3A/.*' ) != -1
136
+ let l: deno_path = matchstr (l: target_uri , ' deno%3A/.*' )
137
+ let item[' targetUri' ] = substitute (l: deno_path , ' deno%3A' , ' deno:' , ' ' )
138
+ endif
139
+ endfor
140
+ return a: result
141
+ endfunction
142
+
123
143
function ! s: handle_deno_location (ctx, server, type , data) abort " ctx = {counter, list, last_command_id, jump_if_one, mods, in_preview}
124
144
" " Based on vim-lsp/autoload/lsp/ui/vim.vim s:handle_location()
125
145
if a: ctx [' last_command_id' ] != lsp#_last_command ()
@@ -130,7 +150,13 @@ function! s:handle_deno_location(ctx, server, type, data) abort "ctx = {counter,
130
150
if lsp#client#is_error (a: data [' response' ]) || ! has_key (a: data [' response' ], ' result' )
131
151
call lsp#utils#error (' Failed to retrieve ' . a: type . ' for ' . a: server . ' : ' . lsp#client#error_message (a: data [' response' ]))
132
152
return
153
+ elseif type (a: data [' response' ][' result' ]) == type (v: null )
154
+ " e.g.
155
+ " `import` response v:null
156
+ call lsp#utils#error (' Failed to retrieve ' . a: type . ' for ' . a: server . ' : response is null' )
157
+ return
133
158
else
159
+ let a: data [' response' ][' result' ] = s: normalize_target_uris (a: data [' response' ][' result' ])
134
160
let a: ctx [' list' ] = a: ctx [' list' ] + lsp#utils#location#_lsp_to_vim_list (a: data [' response' ][' result' ])
135
161
endif
136
162
0 commit comments