diff options
| author | Simon Engmann <github@sl.engmann.dev> | 2025-07-06 17:12:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-06 08:12:47 -0700 |
| commit | 7fac9025a967a4d0846660f751cd392fac6bb788 (patch) | |
| tree | 943419fe38eb35a07f02661c2179a67060638947 /lsp/ts_ls.lua | |
| parent | docs: update configs.md (diff) | |
| download | nvim-lspconfig-7fac9025a967a4d0846660f751cd392fac6bb788.tar nvim-lspconfig-7fac9025a967a4d0846660f751cd392fac6bb788.tar.gz nvim-lspconfig-7fac9025a967a4d0846660f751cd392fac6bb788.tar.bz2 nvim-lspconfig-7fac9025a967a4d0846660f751cd392fac6bb788.tar.lz nvim-lspconfig-7fac9025a967a4d0846660f751cd392fac6bb788.tar.xz nvim-lspconfig-7fac9025a967a4d0846660f751cd392fac6bb788.tar.zst nvim-lspconfig-7fac9025a967a4d0846660f751cd392fac6bb788.zip | |
feat(ts_ls): implement codelens support #3938
Implement the `editor.action.showReferences` client command, which is
used by the references and implementation code lenses that TypeScript
Language Server provides.
I've mostly based the implementation on the existing code for
`vim.lsp.buf.references()`. The main visible difference is that the
latter includes the item being referenced at the top of the list.
Although, if desired, this could be emulated by manually inserting the
position passed along in the command arguments at the top of the list.
Diffstat (limited to 'lsp/ts_ls.lua')
| -rw-r--r-- | lsp/ts_ls.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lsp/ts_ls.lua b/lsp/ts_ls.lua index 33cb5995..20f750b3 100644 --- a/lsp/ts_ls.lua +++ b/lsp/ts_ls.lua @@ -97,6 +97,32 @@ return { return vim.NIL end, }, + commands = { + ['editor.action.showReferences'] = function(command, ctx) + local client = assert(vim.lsp.get_client_by_id(ctx.client_id)) + local file_uri, position, references = unpack(command.arguments) + + local quickfix_items = vim.lsp.util.locations_to_items(references, client.offset_encoding) + vim.fn.setqflist({}, ' ', { + title = command.title, + items = quickfix_items, + context = { + command = command, + bufnr = ctx.bufnr, + }, + }) + + vim.lsp.util.show_document({ + uri = file_uri, + range = { + start = position, + ['end'] = position, + }, + }, client.offset_encoding) + + vim.cmd('botright copen') + end, + }, on_attach = function(client, bufnr) -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in -- `vim.lsp.buf.code_action()` if specified in `context.only`. |
