Does tsserver have auto import feature ? I mean, it autocompletes with other workspace variables, but it doesn’t auto import it, the pyright lsp does mark symbols with an “Auto-import” at the end and it actually make the auto import.
Yes, it does. Which completion framework you’re using? I use nvim-compe
and it can autoimport stuff for me.
I’m using the same nvim-completion, auto import works for python but not for javascript.
FYI completion.nvim != nvim-compe (I almost typed ~= but realized that would be confusing )
3 Likes
tsserver can support it, just needs to be wired up into your config.
nvim-compe provides it out of the box, but you can add it via this snippet
local function completionItemResolveCB(err, _, result)
if err or not result then
return
end
local bufnr = vim.api.nvim_get_current_buf()
if result.additionalTextEdits then
vim.lsp.util.apply_text_edits(result.additionalTextEdits, bufnr)
end
end
local function requestCompletionItemResolve(bufnr, item)
vim.lsp.buf_request(bufnr, "completionItem/resolve", item, completionItemResolveCB)
end
function M.on_complete_done()
local bufnr = vim.api.nvim_get_current_buf()
local completed_item_var = vim.v.completed_item
if
completed_item_var and completed_item_var.user_data and completed_item_var.user_data.nvim and
completed_item_var.user_data.nvim.lsp and
completed_item_var.user_data.nvim.lsp.completion_item
then
local item = completed_item_var.user_data.nvim.lsp.completion_item
requestCompletionItemResolve(bufnr, item)
end
if
completed_item_var and completed_item_var.user_data and completed_item_var.user_data and
completed_item_var.user_data.lsp and
completed_item_var.user_data.lsp.completion_item
then
local item = completed_item_var.user_data.lsp.completion_item
requestCompletionItemResolve(bufnr, item)
end
end
local on_attach = function(client, bufnr)
....
autocmd("CompleteDone", "<buffer>", "lua require('mh.lsp').on_complete_done()")
end
lspconfig.tsserver.setup {
on_attach = on_attach,
capabilities = capabilities,
}
4 Likes
is there a similar solution for nvim-completion
edit changed to compe and above snippet didn’t work for me even after going through your dotfiles probably still doing something wrong
The snippet he posted is for completion.nvim