Skip to content

Commit

Permalink
Use vim.ui.open
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy committed Feb 26, 2024
1 parent e8f70b7 commit c36a98e
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions lua/lsplinks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,13 @@ local function lsp_has_capability(name)
end

---@param uri string
local function open_file(uri)
local function open_uri(uri)
local file_uri, line_no, col_no = uri:match("(.-)#(%d+),(%d+)")
if file_uri then
vim.lsp.util.jump_to_location({ uri = file_uri }, "utf-8", true)
api.nvim_win_set_cursor(0, { tonumber(line_no), tonumber(col_no) - 1 })
else
vim.lsp.util.jump_to_location({ uri = uri }, "utf-8", true)
end
end

---@param uri string
local function open_browser(uri)
local quoted_uri = '"' .. uri .. '"'
if jit.os == "Windows" then
vim.fn.system("start " .. quoted_uri)
elseif jit.os == "OSX" then
vim.fn.system("open " .. quoted_uri)
else
vim.fn.system("xdg-open " .. quoted_uri)
end
end

---@param uri string
local function open_uri(uri)
if uri:match("^file://") then
open_file(uri)
else
open_browser(uri)
vim.ui.open(uri)
end
end

Expand Down

0 comments on commit c36a98e

Please sign in to comment.