0

I'm using Neovim 0.9 and lsp-zero to edit Typescript files. tsserver has an organize imports feature. How do I map that back through LSP to a user-defined key? Basically, I'd like to add a new keybinding as shown in the lsp-zero "create keybindings" docs, but I don't know how to access the tsserver-specific functionality from vim.lsp.whatever:

lsp.on_attach(function(client, bufnr)
  local opts = {buffer = bufnr, remap = false}

  vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
  ...
  
  -- *** my new keymap here (does not work) ***
  vim.keymap.set("n", "<C-i>", function() vim.lsp.buf.organize_imports() end, opts)
end)

If possible I'd like to stay in the lsp-zero ecosystem here, but whatever works is fine. Ideally of course the mapping would only apply in ts(x) files.

2
  • If the "organize imports" feature is an LSP extension that's not part of the spec, I doubt it will be available in this way. (For example: I happen to know that ALE has to do some special casing for tsserver-related things, because it has non-LSP features.)
    – D. Ben Knoble
    Mar 14, 2023 at 13:50
  • this thread might be helpful: reddit.com/r/neovim/comments/lwz8l7/…
    – grenmester
    Aug 1, 2023 at 13:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.