fix: handle non-file uris for lsp (#2604)

This commit is contained in:
TJ DeVries
2023-07-17 13:20:09 -04:00
committed by GitHub
parent 2ea8dcd17b
commit 47c755d737
2 changed files with 10 additions and 4 deletions

View File

@@ -53,7 +53,12 @@ lsp.references = function(opts)
local location = locations[1] local location = locations[1]
local bufnr = opts.bufnr local bufnr = opts.bufnr
if location.filename then if location.filename then
bufnr = vim.uri_to_bufnr(vim.uri_from_fname(location.filename)) local uri = location.filename
if not utils.is_uri(uri) then
uri = vim.uri_from_fname(uri)
end
bufnr = vim.uri_to_bufnr(uri)
end end
vim.api.nvim_win_set_buf(0, bufnr) vim.api.nvim_win_set_buf(0, bufnr)
vim.api.nvim_win_set_cursor(0, { location.lnum, location.col - 1 }) vim.api.nvim_win_set_cursor(0, { location.lnum, location.col - 1 })

View File

@@ -173,8 +173,9 @@ utils.is_path_hidden = function(opts, path_display)
or type(path_display) == "table" and (vim.tbl_contains(path_display, "hidden") or path_display.hidden) or type(path_display) == "table" and (vim.tbl_contains(path_display, "hidden") or path_display.hidden)
end end
local is_uri = function(filename) local URI_SCHEME_PATTERN = "^([a-zA-Z]+[a-zA-Z0-9.+-]*):.*"
return string.match(filename, "^%w+://") ~= nil utils.is_uri = function(filename)
return filename:match(URI_SCHEME_PATTERN) ~= nil
end end
local calc_result_length = function(truncate_len) local calc_result_length = function(truncate_len)
@@ -197,7 +198,7 @@ utils.transform_path = function(opts, path)
if path == nil then if path == nil then
return return
end end
if is_uri(path) then if utils.is_uri(path) then
return path return path
end end