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

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

@ -75,7 +75,7 @@ M.show_diagnostic = function()
end end
log(display_items) log(display_items)
if #display_items > 0 then 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 end
end end

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

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

@ -40,7 +40,6 @@ local lsp_status_cfg = {
end end
} }
-- local gopls = {} -- local gopls = {}
-- gopls["ui.completion.usePlaceholders"] = true -- gopls["ui.completion.usePlaceholders"] = true
@ -65,7 +64,26 @@ local golang_setup = {
--"-remote.debug=:0", --"-remote.debug=:0",
--"-rpc.trace", --"-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) root_dir = function(fname)
local util = require("lspconfig").util local util = require("lspconfig").util
return util.root_pattern("go.mod", ".git")(fname) or util.path.dirname(fname) return util.root_pattern("go.mod", ".git")(fname) or util.path.dirname(fname)
@ -143,7 +161,7 @@ local lua_cfg = {
library = { library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true, [vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.expand("$VIMRUNTIME/lua/vim")] = 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 -- [vim.fn.expand("~/repos/nvim/lua")] = true
} }
} }

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

Loading…
Cancel
Save