-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add internal pkg filtering and enhanced document url address ma…
…tching rules
- Loading branch information
Showing
1 changed file
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,20 +13,48 @@ local function is_gopls_attached() | |
return #vim.lsp.get_clients({ name = "gopls" }) > 0 | ||
end | ||
|
||
local function get_mode_name() | ||
local files = vim.fs.find("go.mod", { upward = true }) | ||
if #files == 0 or vim.tbl_isempty(files) then | ||
return "" | ||
end | ||
|
||
local mod = files[1] | ||
for line in io.lines(mod) do | ||
local name = line:match("^module%s+([^\n]+)") | ||
return name | ||
end | ||
|
||
return "" | ||
end | ||
|
||
local function request_hover_info() | ||
local method = "textDocument/hover" | ||
local params = vim.lsp.util.make_position_params() | ||
-- The default timeout is 1000ms | ||
return vim.lsp.buf_request_sync(0, method, params) | ||
end | ||
|
||
-- TODO check if it is an internal pkg | ||
local function get_link_from_response(res_tbl) | ||
local res = res_tbl[1] | ||
if res and res.result then | ||
local value = res.result.contents.value | ||
return value:match("https://pkg%.go%.dev[%w.#/]+") | ||
-- Test case | ||
-- https://pkg.go.dev/github.com/json-iterator/[email protected]#API.Unmarshal | ||
-- https://pkg.go.dev/context#Context | ||
local link = value:match("%(https://pkg%.go%.dev[%w%p]+%)") | ||
if not link then | ||
return | ||
end | ||
link = link:sub(2, -2) | ||
|
||
local mod = get_mode_name() | ||
if link:find(mod) then | ||
return nil | ||
end | ||
return link | ||
end | ||
|
||
return nil | ||
end | ||
|
||
|