I believe you don't have the distinction declaration and definition in typescript like you have it in C or C++.
myfile.h
// declaration
int myfunction(int a, char *name);
myfile.c
// definition
int myfunction(int a, char *name)
{
return a * a;
}
In typescript you have only a definition that that is probably why gD
is not working but gd
should do the job for you.
To open the definition in a new tab if it is another file you could do:
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'gD', function()
local org_path = vim.api.nvim_buf_get_name(0)
-- Go to definition:
vim.api.nvim_command('normal gd')
-- Wait LSP server response
vim.wait(100, function() end)
local new_path = vim.api.nvim_buf_get_name(0)
if not (org_path == new_path) then
-- Create a new tab for the original file
vim.api.nvim_command('0tabnew %')
-- Restore the cursor position
vim.api.nvim_command('b ' .. org_path)
vim.api.nvim_command('normal! `"')
-- Switch to the original tab
vim.api.nvim_command('normal! gt')
end
end, bufopts)