update gopls settings

neovim_0_5
ray-x 3 years ago
parent 16259eb4e7
commit 7e0b1a67a9

@ -57,6 +57,7 @@ function code_action.code_action_handler(err, _, actions, num, _, _, customSelec
pos = 2
end
local l = data[pos]
return l
-- log("on move", l)
end
}
@ -86,7 +87,6 @@ local function _update_virtual_text(line)
if line then
local icon_with_indent = " " .. config.code_action_icon
-- log("updat text", line, icon_with_indent)
api.nvim_buf_set_extmark(
0,
namespace,
@ -127,7 +127,6 @@ local need_check_diagnostic = {
function code_action:render_action_virtual_text(line, diagnostics)
return function(_, _, actions)
if actions == nil or type(actions) ~= "table" or vim.tbl_isempty(actions) then
if config.code_action_prompt.virtual_text then
_update_virtual_text(nil)

@ -24,6 +24,7 @@ local function definition_hdlr(_, _, locations, _, bufnr)
end
local function def_preview(timeout_ms)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running")
local method = "textDocument/definition"
local params = vim.lsp.util.make_position_params()
local result = vim.lsp.buf_request_sync(0, method, params, timeout_ms or 2000)

@ -75,7 +75,7 @@ M.show_diagnostic = function()
end
log(display_items)
if #display_items > 0 then
gui.new_list_view({items = display_items, api = 'Diagnostic'})
gui.new_list_view({items = display_items, api = ' Diagnostic'})
end
end
end

@ -1,7 +1,6 @@
local M = {}
local ListView = require "guihua.listview"
local TextView = require "guihua.textview"
local View = require "guihua.view"
local util = require "navigator.util"
local log = require "navigator.util".log
local verbose = require "navigator.util".verbose

@ -8,6 +8,8 @@ local M = {}
local function call_hierarchy_handler(direction, err, _, result, _, _, error_message)
-- log('call_hierarchy')
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
if err ~= nil then
print("ERROR: " .. error_message)
return
@ -46,6 +48,7 @@ local call_hierarchy_handler_from = partial(call_hierarchy_handler, "from")
local call_hierarchy_handler_to = partial(call_hierarchy_handler, "to")
local function incoming_calls_handler(bang, err, method, result, client_id, bufnr)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
local results = call_hierarchy_handler_from(err, method, result, client_id, bufnr, "Incoming calls not found")
gui.new_list_view({items = results, api = ''})
end
@ -59,6 +62,7 @@ end
function M.incoming_calls(bang, opts)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
if not lsphelper.check_capabilities("call_hierarchy") then
return
end
@ -68,6 +72,7 @@ function M.incoming_calls(bang, opts)
end
function M.outgoing_calls(bang, opts)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
if not lsphelper.check_capabilities("call_hierarchy") then
return
end

@ -40,7 +40,6 @@ local lsp_status_cfg = {
end
}
-- local gopls = {}
-- gopls["ui.completion.usePlaceholders"] = true
@ -65,7 +64,26 @@ local golang_setup = {
--"-remote.debug=:0",
--"-rpc.trace",
},
settings = {},
settings = {
gopls = {
analyses = {
unusedparams = true,
unreachable = false
},
codelenses = {
generate = true, -- show the `go generate` lens.
gc_details = true -- // Show a code lens toggling the display of gc's choices.
},
usePlaceholders = true,
completeUnimported = true,
staticcheck = true,
matcher = "fuzzy",
symbolMatcher = "fuzzy",
gofumpt = true,
buildFlags = {"-tags", "integration"}
-- buildFlags = {"-tags", "functional"}
}
},
root_dir = function(fname)
local util = require("lspconfig").util
return util.root_pattern("go.mod", ".git")(fname) or util.path.dirname(fname)
@ -143,7 +161,7 @@ local lua_cfg = {
library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.expand("$VIMRUNTIME/lua/vim")] = true,
[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true,
[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true
-- [vim.fn.expand("~/repos/nvim/lua")] = true
}
}

@ -2,6 +2,7 @@ local M = {}
local util = require "navigator.util"
local lsp = require "vim.lsp"
local log = require "navigator.util".log
local symbol_kind = require "navigator.lspclient.lspkind".symbol_kind
function M.lines_from_locations(locations, include_filename)
local fnamemodify = (function(filename)
if include_filename then
@ -22,6 +23,37 @@ function M.lines_from_locations(locations, include_filename)
return lines
end
function M.symbols_to_items(result)
local locations = {}
-- log(result)
for i = 1, #result do
local item = result[i].location
if item ~= nil and item.range ~= nil then
item.kind = result[i].kind
local kind = symbol_kind(item.kind)
item.name = result[i].name --symbol name
item.text = result[i].name
if kind ~= nil then
item.text = kind .. ": " .. item.text
end
item.filename = vim.uri_to_fname(item.uri)
if item.range == nil or item.range.start == nil then
log(result[i], item)
end
item.lnum = item.range.start.line
if item.containerName ~= nil then
item.text = "" .. item.containerName .. item.text
end
table.insert(locations, item)
end
end
-- local items = locations_to_items(locations)
log(locations[1])
return locations
end
local function extract_result(results_lsp)
if results_lsp then
local results = {}
@ -150,6 +182,4 @@ function M.symbol_to_items(locations)
return items
end
return M

@ -914,3 +914,44 @@ definition.lua:9: { {
}
}
} }
-- workspace request
{
[2] = {
result = { {
kind = 13,
location = {
range = {
end = {
character = 7,
line = 0
},
start = {
character = 6,
line = 0
}
},
uri = "file:///usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua"
},
name = "a",
range = { 7, 7 }
},{
kind = 13,
location = {
range = {
end = {
character = 14,
line = 1
},
start = {
character = 6,
line = 1
}
},
uri = "file:///usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua"
},
name = "language",
range = { 25, 32 }
},
}}

@ -1,17 +1,19 @@
local gui = require "navigator.gui"
local M = {}
local log = require "navigator.util".log
local verbose = require "navigator.util".debug
local lsphelper = require "navigator.lspwrapper"
local locations_to_items = lsphelper.locations_to_items
local clone = require "guihua.util".clone
local symbol_kind = require "navigator.lspclient.lspkind".symbol_kind
local symbols_to_items = lsphelper.symbols_to_items
function M.document_symbols(opts)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running")
opts = opts or {}
local params = vim.lsp.util.make_position_params()
params.context = {includeDeclaration = true}
params.query = ""
local results_lsp = vim.lsp.buf_request_sync(0, "textDocument/documentSymbol", params, opts.timeout or 5000)
local results_lsp = vim.lsp.buf_request_sync(0, "textDocument/documentSymbol", params, opts.timeout or 3000)
local locations = {}
log(results_lsp)
for _, server_results in pairs(results_lsp) do
@ -34,25 +36,36 @@ end
function M.workspace_symbols(opts)
opts = opts or {}
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running")
local lspopts = {
loc = "top_center",
prompt = true,
rawdata = true,
api = "華 "
}
vim.list_extend(lspopts, opts)
local params = vim.lsp.util.make_position_params()
params.context = {includeDeclaration = true}
params.query = ""
local results_lsp = vim.lsp.buf_request_sync(0, "workspace/symbol", params, opts.timeout or 15000)
log(results_lsp)
local locations = {}
for _, server_results in pairs(results_lsp) do
if server_results.result then
vim.list_extend(locations, vim.lsp.util.symbols_to_items(server_results.result) or {})
params.query = opts.prompt or ""
local results_lsp = vim.lsp.buf_request_sync(0, "workspace/symbol", params, lspopts.timeout or 15000)
if not results_lsp or vim.tbl_isempty(results_lsp) then
print(bufnr, "symbol not found for buf")
return
end
-- result_lsp
local result = {}
for i = 1, #results_lsp do
if results_lsp[i] ~= nil and results_lsp[i].result ~= nil and #results_lsp[i].result > 0 then
result = results_lsp[i].result
end
end
local lines = {}
for _, loc in ipairs(locations) do
table.insert(lines, string.format("%s:%s:%s", loc.filename, loc.lnum, loc.text))
end
if #lines > 0 then
gui.new_list_view({data = lines})
local items = symbols_to_items(result)
-- verbose(results_lsp)
if #items > 0 then
lspopts.data = items
gui.new_list_view(lspopts)
else
print("symbols not found")
end
@ -72,7 +85,7 @@ function M.document_symbol_handler(err, _, result, _, bufnr)
local fname = vim.fn.expand("%:p:f")
local uri = vim.uri_from_fname(fname)
-- vim.list_extend(locations, vim.lsp.util.symbols_to_items(result) or {})
-- log(locations)
log(result[1])
for i = 1, #result do
local item = {}
item.kind = result[i].kind
@ -81,17 +94,19 @@ function M.document_symbol_handler(err, _, result, _, bufnr)
item.range = result[i].range
item.uri = uri
item.selectionRange = result[i].selectionRange
item.detail = result[i].detail or ''
if item.detail == '()' then item.detail = 'func' end
item.detail = result[i].detail or ""
if item.detail == "()" then
item.detail = "func"
end
item.lnum = result[i].range.start.line + 1
item.text = "[" .. kind .. "]" .. item.detail .. " " .. item.name
item.text = "[" .. kind .. "]" .. item.detail .. " " .. item.name
item.filename = fname
table.insert(locations, item)
if result[i].children ~= nil then
for _, c in pairs (result[i].children) do
for _, c in pairs(result[i].children) do
local child = {}
child.kind = c.kind
child.name = c.name
@ -101,7 +116,7 @@ function M.document_symbol_handler(err, _, result, _, bufnr)
child.fname = fname
child.uri = uri
child.lnum = c.range.start.line + 1
child.detail = c.detail or ''
child.detail = c.detail or ""
child.text = "  [" .. ckind .. "] " .. child.detail .. " " .. child.name
table.insert(locations, child)
end
@ -109,7 +124,7 @@ function M.document_symbol_handler(err, _, result, _, bufnr)
end
-- verbose(locations)
-- local items = locations_to_items(locations)
gui.new_list_view({items = locations, prompt = true, rawdata = true, api = '華 '})
gui.new_list_view({items = locations, prompt = true, rawdata = true, api = "華 "})
-- if locations == nil or vim.tbl_isempty(locations) then
-- print "References not found"
@ -140,21 +155,23 @@ function M.workspace_symbol_handler(err, _, result, _, bufnr)
print(bufnr, "symbol not found for buf")
return
end
log(result)
local locations = {}
for i = 1, #result do
local item = result[i].location or {}
item.kind = result[i].kind
item.containerName = result[i].containerName
item.name = result[i].name
item.text = result[i].name
if #item.containerName > 0 then
item.text = item.text:gsub(item.containerName, "", 1)
end
table.insert(locations, item)
end
local items = locations_to_items(locations)
gui.new_list_view({items = items, prompt = true, api = '華 '})
log(result[1])
local items = symbols_to_items(result)
log(items[1])
-- local locations = {}
-- for i = 1, #result do
-- local item = result[i].location or {}
-- item.kind = result[i].kind
-- item.containerName = result[i].containerName or ""
-- item.name = result[i].name
-- item.text = result[i].name
-- if #item.containerName > 0 then
-- item.text = item.text:gsub(item.containerName, "", 1)
-- end
-- table.insert(locations, item)
-- end
-- local items = locations_to_items(locations)
gui.new_list_view({items = items, prompt = true, rowdata = true, api = "華 "})
-- if locations == nil or vim.tbl_isempty(locations) then
-- print "References not found"

Loading…
Cancel
Save