diff options
| author | Ilia Choly <ilia.choly@gmail.com> | 2025-12-03 12:11:49 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-03 12:11:49 -0500 |
| commit | 0e121b5e0bb9c23507aafe9e44255c9f225ae291 (patch) | |
| tree | b6d787fb06c27dc6b963b30acd4398d409a2d0ad | |
| parent | fix(buf_ls): restrict reuse_client to buf_ls clients only #4221 (diff) | |
| download | nvim-lspconfig-0e121b5e0bb9c23507aafe9e44255c9f225ae291.tar nvim-lspconfig-0e121b5e0bb9c23507aafe9e44255c9f225ae291.tar.gz nvim-lspconfig-0e121b5e0bb9c23507aafe9e44255c9f225ae291.tar.bz2 nvim-lspconfig-0e121b5e0bb9c23507aafe9e44255c9f225ae291.tar.lz nvim-lspconfig-0e121b5e0bb9c23507aafe9e44255c9f225ae291.tar.xz nvim-lspconfig-0e121b5e0bb9c23507aafe9e44255c9f225ae291.tar.zst nvim-lspconfig-0e121b5e0bb9c23507aafe9e44255c9f225ae291.zip | |
feat(ts_ls): add LspTypescriptGoToSourceDefinition command #4225
| -rw-r--r-- | lsp/ts_ls.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lsp/ts_ls.lua b/lsp/ts_ls.lua index df8e34fa..23ac144e 100644 --- a/lsp/ts_ls.lua +++ b/lsp/ts_ls.lua @@ -33,6 +33,8 @@ --- - organize imports --- - remove unused code --- +--- Use the `:LspTypescriptGoToSourceDefinition` command to navigate to the source definition of a symbol (e.g., jump to the original implementation instead of type definitions). +--- --- ### Monorepo support --- --- `ts_ls` supports monorepos by default. It will automatically find the `tsconfig.json` or `jsconfig.json` corresponding to the package you are working on. @@ -128,5 +130,26 @@ return { }, }) end, {}) + + -- Go to source definition command + vim.api.nvim_buf_create_user_command(bufnr, 'LspTypescriptGoToSourceDefinition', function() + local win = vim.api.nvim_get_current_win() + local params = vim.lsp.util.make_position_params(win, client.offset_encoding) + client:exec_cmd({ + command = '_typescript.goToSourceDefinition', + title = 'Go to source definition', + arguments = { params.textDocument.uri, params.position }, + }, { bufnr = bufnr }, function(err, result) + if err then + vim.notify('Go to source definition failed: ' .. err.message, vim.log.levels.ERROR) + return + end + if not result or vim.tbl_isempty(result) then + vim.notify('No source definition found', vim.log.levels.INFO) + return + end + vim.lsp.util.show_document(result[1], client.offset_encoding, { focus = true }) + end) + end, { desc = 'Go to source definition' }) end, } |
