inlay eol display issue #396

pull/399/head
ray-x 7 months ago
parent 57a3c3e748
commit b4cd53de46

File diff suppressed because one or more lines are too long

@ -58,6 +58,7 @@ _GO_NVIM_CFG = {
-- lsp_diag_signs = true,
lsp_inlay_hints = {
enable = true,
style = 'inline', -- 'default', 'inline', or 'eol'
-- Only show inlay hints for the current line
only_current_line = false,

@ -8,7 +8,8 @@ local utils = require('go.utils')
local log = utils.log
local trace = utils.trace
local config
local nvim10 = vim.fn.has('nvim-0.10') == 1
local nvim10 = vim.fn.has('nvim-0.10') == 1 and _GO_NVIM_CFG.lsp_inlay_hints.style == 'inlay'
-- local nvim10 = true
-- whether the hints are enabled or not
local enabled = nil
-- Update inlay hints when opening a new buffer and when writing a buffer to a
@ -178,47 +179,6 @@ function nvim10_inline_hints(bufnr, vtext, hint, cfg)
end)
end
local function handler_inline(err, result, ctx)
trace(result, ctx)
if err or result == nil then
return
end
local bufnr = ctx.bufnr
if vim.api.nvim_get_current_buf() ~= bufnr then
return
end
local function unpack_label(label)
local labels = ''
for _, value in pairs(label) do
labels = labels .. ' ' .. value.value
end
return utils.trim(labels)
end
-- clean it up at first
M.disable_inlay_hints()
local parsed = parseHints(result)
trace(parsed)
-- parsed is a map of line numbers to hints,
-- hint includes label, range, and kind
-- I only plan to deal gopls response
for key, value in pairs(parsed) do
trace(key, value)
for _, hint in pairs(value) do
trace(hint)
local label = unpack_label(hint.label)
trace(bufnr, namespace, label, hint, config)
nvim10_inline_hints(bufnr, label, hint, config)
end
end
end
local function handler(err, result, ctx)
trace(result, ctx)
if err then
@ -374,25 +334,32 @@ function M.set_inlay_hints()
end
end
if not found then
log('gopls not found')
return
end
if vim.wo.diff then
return
end
local fname = fn.expand('%:p')
local filetime = fn.getftime(fname)
if nvim10 then
local bufnr = vim.api.nvim_get_current_buf()
return vim.lsp.inlay_hint(bufnr, enabled)
local wrap = utils.throttle(function()
vim.lsp.inlay_hint(bufnr, enabled)
should_update[fname] = filetime
end, 300)
wrap()
end
trace('old style inlay')
local fname = fn.expand('%:p')
local filetime = fn.getftime(fname)
if should_update[fname] == filetime then
trace('already updated')
return
end
local h = handler
vim.defer_fn(function()
local wrap = utils.throttle(function()
trace('inlay hints buf req', bufnr)
vim.lsp.buf_request(bufnr, 'textDocument/inlayHint', get_params(), h)
should_update[fname] = filetime
end, 100)
end, 300)
wrap()
end
return M
@ -421,3 +388,44 @@ return M
}
]]
--
-- local function handler_inline(err, result, ctx)
-- trace(result, ctx)
--
-- if err or result == nil then
-- return
-- end
-- local bufnr = ctx.bufnr
--
-- if vim.api.nvim_get_current_buf() ~= bufnr then
-- return
-- end
--
-- local function unpack_label(label)
-- local labels = ''
-- for _, value in pairs(label) do
-- labels = labels .. ' ' .. value.value
-- end
--
-- return utils.trim(labels)
-- end
--
-- -- clean it up at first
-- M.disable_inlay_hints()
--
-- local parsed = parseHints(result)
-- trace(parsed)
-- -- parsed is a map of line numbers to hints,
-- -- hint includes label, range, and kind
-- -- I only plan to deal gopls response
--
-- for key, value in pairs(parsed) do
-- trace(key, value)
-- for _, hint in pairs(value) do
-- trace(hint)
-- local label = unpack_label(hint.label)
-- trace(bufnr, namespace, label, hint, config)
-- nvim10_inline_hints(bufnr, label, hint, config)
-- end
-- end
-- end

@ -18,7 +18,8 @@ end
local codelens_enabled = false
local on_attach = function(client, bufnr)
log('go.nvim on_on_attach', client, bufnr)
log('go.nvim on_on_attach', bufnr)
trace('go.nvim gopls info', client)
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end

@ -1,6 +1,7 @@
local vim, vfn = vim, vim.fn
local utils = require('go.utils')
local log = utils.log
local trace = utils.trace
local extract_filepath = utils.extract_filepath
local null_ls = require('null-ls')
@ -22,7 +23,7 @@ local function handler()
return
end
log(msg.method)
trace(msg.method)
-- log(msg)
local msgs = msg.output
msgs = vim.split(msgs, '\n', true)
@ -33,7 +34,7 @@ local function handler()
local verbose = true
local failure = {}
if #msgs > 100 then -- lua is slow
log('reduce')
trace('reduce')
verbose = false
local fname = vfn.expand('%:t:r')
local reduce = {}
@ -78,7 +79,7 @@ local function handler()
if vfn.empty(entry.Output) == 1 or false then
output = ''
else
log(idx, entry)
trace(idx, entry)
entry.Output = utils.trim(entry.Output)
entry.Output = entry.Output:gsub('\t', ' ')
local found = false
@ -96,18 +97,18 @@ local function handler()
else -- not found or format is correct
output = output .. (entry.Output or '')
end
log(found, filename, lnum)
trace(found, filename, lnum)
if entry.Output:find('FAIL') or entry.Output:find('panic') then
table.insert(panic, entry.Output)
end
log(idx, filename, output or 'nil')
trace(idx, filename, output or 'nil')
end
elseif entry.Action == 'pass' or entry.Action == 'skip' then
-- log(entry)
-- reset
output = ''
elseif entry.Action == 'fail' and vfn.empty(output) == 0 then
log(idx, entry, filename, output)
log('action failed', idx, entry, filename, output)
if filename and filename:find(vfn.expand('%:t:r')) then -- can be output from other files
table.insert(diags, {
file = filename,
@ -148,9 +149,9 @@ local function handler()
if #qf > 0 then
local efm = require('go.gotest').efm()
vfn.setqflist({}, ' ', { title = 'gotest', lines = qf, efm = efm })
log(qf, efm)
trace(qf, efm)
end
log(diags)
trace(diags)
if #diags > 0 or test_failed then
vim.schedule(function()
@ -189,7 +190,7 @@ return {
format = 'raw',
args = function()
local rfname = vfn.fnamemodify(vfn.expand('%'), ':~:.')
log(rfname) -- repplace $FILENAME ?
trace(rfname) -- repplace $FILENAME ?
golangci_diags = {} -- CHECK: is here the best place to call
return {
'run',
@ -221,7 +222,7 @@ return {
end)
end
log(msg.method)
trace(msg.method)
if msg.output == nil then
return
end
@ -235,7 +236,7 @@ return {
if vfn.empty(m) == 0 then
local entry = vfn.json_decode(m)
if entry['Report'] and entry['Report']['Error'] then
log(entry['Report']['Error'])
trace('report', entry['Report']['Error'])
return golangci_diags
end
local issues = entry['Issues']
@ -243,7 +244,7 @@ return {
if type(issues) == 'table' then
for _, d in ipairs(issues) do
if d.Pos then --and d.Pos.Filename == bufname then
log(d)
trace('issues', d)
table.insert(golangci_diags, {
source = string.format('golangci-lint:%s', d.FromLinter),
row = d.Pos.Line,
@ -284,7 +285,7 @@ return {
local gt = require('go.gotest')
local a = { 'test', '-json' }
local tests = gt.get_test_cases()
log(tests)
trace('tests', tests)
local pkg = require('go.gotest').get_test_path()
pkg_path = pkg
@ -296,15 +297,20 @@ return {
table.insert(a, tests)
table.insert(a, pkg)
end
log(a)
trace('result', a)
return a
end,
method = methods.internal.DIAGNOSTICS_ON_SAVE,
format = 'raw',
timeout = 5000,
check_exit_code = function(code, stderr)
local success = code <= 1
log(code, stderr)
local success = code < 1
if not success then
-- vim.schedule(function()
-- vim.notify('go test failed: ' .. tostring(stderr), vim.log.levels.WARN)
-- end)
log('failed to run to test', code, stderr)
end
-- if not success then
-- -- can be noisy for things that run often (e.g. diagnostics), but can
-- -- be useful for things that run on demand (e.g. formatting)
@ -314,7 +320,7 @@ return {
-- end
return true
end,
on_output = handler(pkg_path),
on_output = handler(),
},
factory = h.generator_factory,
})
@ -348,7 +354,7 @@ return {
end
local fname = gt.get_test_func_name()
log(fname)
trace('run for ', fname)
if fname then
-- local mode = vim.api.nvim_get_mode().mode
table.insert(actions, {

@ -1,7 +1,8 @@
local util = {}
local fn = vim.fn
local os_name = vim.loop.os_uname().sysname
local uv = vim.loop
local os_name = uv.os_uname().sysname
local is_windows = os_name == 'Windows' or os_name == 'Windows_NT'
local is_git_shell = is_windows
and (vim.fn.exists('$SHELL') and vim.fn.expand('$SHELL'):find('bash.exe') ~= nil)
@ -266,7 +267,7 @@ util.log = function(...)
local info = debug.getinfo(2, 'Sl')
str = str .. info.short_src .. ':' .. info.currentline
local _, ms = vim.loop.gettimeofday()
local _, ms = uv.gettimeofday()
str = string.format('[%s %d] %s', os.date(), ms, str)
for i, v in ipairs(arg) do
if type(v) == 'table' then
@ -801,17 +802,16 @@ function util.quickfix(cmd)
end
end
util.debounce = function(func, duration)
local timer = vim.loop.new_timer()
local function inner(args)
timer:stop()
timer:start(
duration,
0,
vim.schedule_wrap(function()
func(args)
end)
)
util.throttle = function(func, duration)
local timer = uv.new_timer()
-- util.log(func, duration)
local function inner(...)
-- util.log('throttle', ...)
if not timer:is_active() then
timer:start(duration, 0, function() end)
pcall(vim.schedule_wrap(func), select(1, ...))
end
end
local group = vim.api.nvim_create_augroup('gonvim__CleanupLuvTimers', {})
@ -831,7 +831,7 @@ util.debounce = function(func, duration)
end,
})
return timer, inner
return inner, timer
end
local namepath = {}

Loading…
Cancel
Save