Skip to content

Commit d8ba3e2

Browse files
committed
remove nvim 9 support
1 parent 94d7291 commit d8ba3e2

File tree

2 files changed

+12
-54
lines changed

2 files changed

+12
-54
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LSPLINKS
22

3-
> Support for [document links](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentLink) for neovim **0.9+**.
3+
> Support for [document links](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentLink) for neovim **0.10+**.
44
55
### Usage
66

lua/lsplinks.lua

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,6 @@ local function in_range(pos, range)
5656
end
5757
end
5858

59-
---@param name string
60-
---@return boolean
61-
local function lsp_has_capability(name)
62-
local clients = nil
63-
if vim.lsp.get_clients then
64-
local bufnr = api.nvim_get_current_buf()
65-
clients = vim.lsp.get_clients({ bufnr = bufnr })
66-
else
67-
clients = vim.lsp.buf_get_clients()
68-
end
69-
for _, client in ipairs(clients) do
70-
if client.server_capabilities[name] then
71-
return true
72-
end
73-
end
74-
return false
75-
end
7659

7760
local augroup = api.nvim_create_augroup("lsplinks", { clear = true })
7861

@@ -108,18 +91,6 @@ function M.current()
10891
return nil
10992
end
11093

111-
--- Return the uri without the fragment
112-
---
113-
---@param uri string
114-
---@return string
115-
local function remove_uri_fragment(uri)
116-
local fragment_index = uri:find("#")
117-
if fragment_index ~= nil then
118-
uri = uri:sub(1, fragment_index - 1)
119-
end
120-
return uri
121-
end
122-
12394
--- Open the link under the cursor if one exists.
12495
--- The return value indicates if a link was found.
12596
---
@@ -131,26 +102,13 @@ function M.open(uri)
131102
return false
132103
end
133104
if uri:find("^file:/") then
134-
util.show_document({ uri = remove_uri_fragment(uri) }, "utf-8", { reuse_win = true, focus = true })
105+
util.show_document({ uri = uri }, "utf-8", { reuse_win = true, focus = true })
135106
local line_no, col_no = uri:match(".-#(%d+),(%d+)")
136107
if line_no then
137108
api.nvim_win_set_cursor(0, { tonumber(line_no), tonumber(col_no) - 1 })
138109
end
139110
else
140-
if vim.ui.open then
141-
vim.ui.open(uri)
142-
else
143-
-- for nvim earlier than 0.10
144-
local opener
145-
if vim.fn.has("macunix") == 1 then
146-
opener = "open"
147-
elseif vim.fn.has("linux") == 1 then
148-
opener = "xdg-open"
149-
elseif vim.fn.has("win64") == 1 or vim.fn.has("win32") == 1 then
150-
opener = "start"
151-
end
152-
vim.fn.system(string.format("%s '%s' >/dev/null 2>&1", opener, uri))
153-
end
111+
vim.ui.open(uri)
154112
end
155113
return true
156114
end
@@ -164,9 +122,6 @@ end
164122

165123
-- Refresh the links for the current buffer
166124
function M.refresh()
167-
if not lsp_has_capability("documentLinkProvider") then
168-
return
169-
end
170125
local params = { textDocument = util.make_text_document_params() }
171126
vim.lsp.buf_request(0, "textDocument/documentLink", params, function(err, result, ctx)
172127
if err then
@@ -190,7 +145,8 @@ function M.refresh()
190145
if options.highlight then
191146
M.display()
192147
end
193-
end)
148+
end, function() end
149+
)
194150
end
195151

196152
--- Get links for bufnr
@@ -217,13 +173,15 @@ end
217173
function M.display()
218174
api.nvim_buf_clear_namespace(0, ns, 0, -1)
219175
for _, link in ipairs(M.get()) do
220-
local start_lnum = link.range.start.line
221-
local end_lnum = link.range["end"].line
176+
local start_row = link.range.start.line
177+
local start_col = translate(start_row, link.range.start.character)
178+
local end_row = link.range["end"].line
179+
local end_col = translate(end_row, link.range["end"].character)
222180
-- sometimes the buffer is changed before we get here and the link
223181
-- ranges are invalid, so we ignore the error.
224-
pcall(api.nvim_buf_set_extmark, 0, ns, start_lnum, translate(start_lnum, link.range.start.character), {
225-
end_row = end_lnum,
226-
end_col = translate(end_lnum, link.range["end"].character),
182+
pcall(api.nvim_buf_set_extmark, 0, ns, start_row, start_col, {
183+
end_row = end_row,
184+
end_col = end_col,
227185
hl_group = options.hl_group,
228186
})
229187
end

0 commit comments

Comments
 (0)