Skip to content

Commit

Permalink
use show_document instead of jump to location
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-x committed Jan 10, 2025
1 parent b1d0da4 commit eb8216a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 0 additions & 4 deletions lua/navigator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ _NgConfigValues = {
diagnostic_virtual_text = true, -- show virtual for diagnostic message
diagnostic_update_in_insert = false, -- update diagnostic message in insert mode
diagnostic_scrollbar_sign = { '', '', '' }, -- set to nil to disable, set to {'╍', 'ﮆ'} to enable diagnostic status in scroll bar area
tsserver = {
-- filetypes = {'typescript'} -- disable javascript etc,
-- set to {} to disable the lspclient for all filetype
},
neodev = false,
lua_ls = {
-- sumneko_root_path = sumneko_root_path,
Expand Down
6 changes: 3 additions & 3 deletions lua/navigator/definition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local definition_hdlr = function(err, locations, ctx, _)
return
end

local oe = require('navigator.util').encoding(ctx.client_id)
local enc = require('navigator.util').encoding(ctx.client_id)

locations = util.dedup(locations)
log(locations)
Expand All @@ -43,7 +43,7 @@ local definition_hdlr = function(err, locations, ctx, _)
then
vim.lsp.buf.type_definition()
else
vim.lsp.util.jump_to_location(locations[1], oe)
vim.lsp.util.show_document(locations[1], enc, { focus = true })
end
end
else
Expand Down Expand Up @@ -191,8 +191,8 @@ local def = function()
local bufnr = vim.api.nvim_get_current_buf()

local ref_params = vim.lsp.util.make_position_params()
-- check if the pos is already a definition with treesitter
util.for_each_buffer_client(bufnr, function(client, _, _bufnr)
-- if client.resolved_capabilities.goto_definition then
if client.server_capabilities.definitionProvider then
client.request('textDocument/definition', ref_params, definition_hdlr, _bufnr)
return
Expand Down
11 changes: 8 additions & 3 deletions lua/navigator/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ local get_icon = function(kind)
return _NgConfigValues.icons.match_kinds[kind]
end
end
-- require'navigator.treesitter'.goto_definition()
function M.goto_definition(bufnr)

function M.is_definition(bufnr)
bufnr = bufnr or api.nvim_get_current_buf()
local node_at_point = ts_utils.get_node_at_cursor()

Expand All @@ -46,7 +46,12 @@ function M.goto_definition(bufnr)

local definition = locals.find_definition(node_at_point, bufnr)

if definition ~= node_at_point then
return definition == node_at_point
end

function M.goto_definition(bufnr)
if not M.is_definition(bufnr) then
local definition = locals.find_definition(node_at_point, bufnr)
log('def found:', definition:range())
ts_utils.goto_node(definition)
end
Expand Down

0 comments on commit eb8216a

Please sign in to comment.