fix(defaults): silent gx if no textDocument/documentLink support #37969

Problem: If buffer has attached LSP servers and none of them supports
  `textDocument/documentLink` method, typing `gx` results in a warning
  about that.

Solution: Explicitly check that at least one server supports the target
  method before making the LSP request.
This commit is contained in:
Evgeni Chasnovski
2026-02-19 13:59:00 +02:00
committed by GitHub
parent f0137bf443
commit 9567fb0507

View File

@@ -204,20 +204,19 @@ function M._get_open_cmd()
end
end
--- Returns all URLs at cursor, if any.
--- @return string[]
function M._get_urls()
local urls = {} ---@type string[]
local bufnr = vim.api.nvim_get_current_buf()
local cursor = vim.api.nvim_win_get_cursor(0)
local row = cursor[1] - 1
local col = cursor[2]
-- Find LSP document links under the cursor.
--- @param bufnr integer
local get_lsp_urls = function(bufnr)
local has_lsp_support = false
for _, client in pairs(vim.lsp.get_clients({ bufnr = bufnr })) do
has_lsp_support = has_lsp_support or client:supports_method('textDocument/documentLink', bufnr)
end
if not has_lsp_support then
return {}
end
local params = { textDocument = vim.lsp.util.make_text_document_params(bufnr) }
local results = vim.lsp.buf_request_sync(bufnr, 'textDocument/documentLink', params)
local urls = {}
for client_id, result in pairs(results or {}) do
if result.error then
vim.lsp.log.error(result.error)
@@ -239,6 +238,20 @@ function M._get_urls()
end
end
end
return urls
end
--- Returns all URLs at cursor, if any.
--- @return string[]
function M._get_urls()
local urls = {} ---@type string[]
local bufnr = vim.api.nvim_get_current_buf()
local cursor = vim.api.nvim_win_get_cursor(0)
local row = cursor[1] - 1
local col = cursor[2]
urls = vim.list_extend(urls, get_lsp_urls(bufnr))
local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, -1, { row, col }, { row, col }, {
details = true,