Skip to content

Commit

Permalink
fix issue #508. inlay-hint set to disable in cfg not working
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-x committed Oct 31, 2024
1 parent 43e284e commit 9c6deb7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ require('go').setup({
-- set to true: use gopls to format
-- false if you want to use other formatter tool(e.g. efm, nulls)
lsp_inlay_hints = {
enable = true, -- this might be only field apply to neovim > 0.10
enable = true, -- this is the only field apply to neovim > 0.10

-- following are used for neovim < 0.10 which does not implement inlay hints
-- hint style, set to 'eol' for end-of-line hints, 'inlay' for inline hints
Expand Down Expand Up @@ -1189,7 +1189,8 @@ The plugin injects the tmpl to html syntax so you should see this:

![image](https://github.com/ray-x/go.nvim/assets/1681295/7d11eb96-4803-418b-b056-336163ed492b)

To get highlighting for other templated languages check out the docs of [tree-sitter-go-template](https://github.com/ngalaiko/tree-sitter-go-template).
To get highlighting for other templated languages check out the docs of
[tree-sitter-go-template](https://github.com/ngalaiko/tree-sitter-go-template).

## Integrate null-ls

Expand Down
8 changes: 5 additions & 3 deletions lua/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ function go.setup(cfg)
_GO_NVIM_CFG.disable_defaults = true
_GO_NVIM_CFG.diagnostic = false
end

_GO_NVIM_CFG = vim.tbl_deep_extend('force', _GO_NVIM_CFG, cfg)

if vim.fn.empty(_GO_NVIM_CFG.go) == 1 then
Expand Down Expand Up @@ -294,11 +295,12 @@ function go.setup(cfg)
require('snips.all')
end
end
if _GO_NVIM_CFG.lsp_inlay_hints.enable then
require('go.inlay').setup()
end
end, 2)

vim.defer_fn(function()
require('go.inlay').setup()
end, 1)

go.doc_complete = require('go.godoc').doc_complete
go.package_complete = require('go.package').complete
go.dbg_complete = require('go.complete').dbg_complete
Expand Down
2 changes: 1 addition & 1 deletion lua/go/gopls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ M.setups = function()
setups.settings.gopls.buildFlags = { tags }
end

if _GO_NVIM_CFG.lsp_inlay_hints.enable and vim.fn.has('nvim-0.10') then
if vim.fn.has('nvim-0.10') then
setups.settings.gopls = vim.tbl_deep_extend('keep', setups.settings.gopls, {
hints = {
assignVariableTypes = true,
Expand Down
32 changes: 18 additions & 14 deletions lua/go/inlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local inlay_display = vim.fn.has('nvim-0.10') == 1
and _GO_NVIM_CFG.lsp_inlay_hints.style == 'inlay'
and vim.lsp.inlay_hint
and type(vim.lsp.inlay_hint) == 'table'

if type(vim.lsp.inlay_hint) == 'function' then
utils.warn('unsupported neovim nightly, please upgrade')
end
Expand All @@ -25,21 +26,19 @@ local enabled = {}
local should_update = {}
function M.setup()
local events = { 'BufWritePost', 'BufEnter', 'InsertLeave', 'FocusGained', 'CursorHold' }
config = _GO_NVIM_CFG.lsp_inlay_hints
if not config or config.enable == false then -- disabled
return
end
local bufnr = tostring(vim.api.nvim_get_current_buf())
if config.enable then
enabled[bufnr] = true
end
if config.only_current_line then

config = _GO_NVIM_CFG.lsp_inlay_hints or {}
if config.only_current_line then -- only show hints on the current line, deprecated
local user_events = vim.split(config.only_current_line_autocmd, ',')
events = vim.tbl_extend('keep', events, user_events)
end

api.nvim_create_user_command('GoToggleInlay', function(_)
require('go.inlay').toggle_inlay_hints()
end, { desc = 'toggle gopls inlay hints' })

local cmd_group = api.nvim_create_augroup('gopls_inlay', {})
api.nvim_create_autocmd({ 'BufEnter', 'InsertLeave', 'FocusGained', 'CursorHold' }, {
api.nvim_create_autocmd(events, {
group = cmd_group,
pattern = { '*.go', '*.mod' },
callback = function()
Expand All @@ -64,12 +63,17 @@ function M.setup()
})
end

api.nvim_create_user_command('GoToggleInlay', function(_)
require('go.inlay').toggle_inlay_hints()
end, { desc = 'toggle gopls inlay hints' })
if not config.enable then -- disabled
M.disable_inlay_hints(true)
return
end
local bufnr = tostring(vim.api.nvim_get_current_buf())
enabled[bufnr] = true


vim.defer_fn(function()
require('go.inlay').set_inlay_hints()
end, 1000)
end, 100)
end

local function get_params()
Expand Down
2 changes: 1 addition & 1 deletion lua/go/ts/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ M.get_func_method_node_at_pos = function(bufnr)

local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn)
if ns == nil then
warn('function not found')
debug('function not found')
return nil
end
return ns[#ns]
Expand Down
2 changes: 1 addition & 1 deletion lua/go/ts/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ M.nodes_at_cursor = function(query, default, bufnr, ntype)
ulog('Unable to find any nodes. place your cursor on a go symbol and try again')
return nil
end
ulog(#ns)
-- ulog(#ns)
local nodes_at_cursor = M.sort_nodes(M.intersect_nodes(ns, row, col))
if not nodes_at_cursor then
-- cmp-command-line will causing cursor to move to end of line
Expand Down

0 comments on commit 9c6deb7

Please sign in to comment.