nvim-lsp-ts-utils icon indicating copy to clipboard operation
nvim-lsp-ts-utils copied to clipboard

[BUG] :TsLsImportCurrent and :TsLspImportAll do not work on library code

Open samtipton opened this issue 3 years ago • 3 comments

FAQ

Issues

  • [X] I have checked existing issues and there are no issues with the same problem.

Neovim Version

0.7.0

Steps to reproduce

Create react basic app, install a 3rd party library, go about using a component from that library, go to auto complete the missing symbol. Observe that :TsLsImportCurrent nor :TsLspImportAll import the missing symbol.

Expected behavior

A code action window appears with options

Actual behavior

'No code actions available'

Debug log

command git exited with code 0

Help

No

Implementation help

No response

samtipton avatar May 26 '22 20:05 samtipton

My config

local lspconfig = require("lspconfig")
local null_ls = require("null-ls")
local buf_map = function(bufnr, mode, lhs, rhs, opts)
    vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts or {
        silent = true,
    })
end
local on_attach = function(client, bufnr)
    vim.cmd("command! LspDef lua vim.lsp.buf.definition()")
    vim.cmd("command! LspFormatting lua vim.lsp.buf.formatting()")
    vim.cmd("command! LspCodeAction lua vim.lsp.buf.code_action()")
    vim.cmd("command! LspHover lua vim.lsp.buf.hover()")
    vim.cmd("command! LspRename lua vim.lsp.buf.rename()")
    vim.cmd("command! LspRefs lua vim.lsp.buf.references()")
    vim.cmd("command! LspTypeDef lua vim.lsp.buf.type_definition()")
    vim.cmd("command! LspImplementation lua vim.lsp.buf.implementation()")
    vim.cmd("command! LspDiagPrev lua vim.diagnostic.goto_prev()")
    vim.cmd("command! LspDiagNext lua vim.diagnostic.goto_next()")
    vim.cmd("command! LspDiagLine lua vim.diagnostic.open_float()")
    vim.cmd("command! LspSignatureHelp lua vim.lsp.buf.signature_help()")
    buf_map(bufnr, "n", "g2", ":LspRename<CR>")
    buf_map(bufnr, "n", "gy", ":LspTypeDef<CR>")
    buf_map(bufnr, "n", "[a", ":LspDiagPrev<CR>")
    buf_map(bufnr, "n", "]a", ":LspDiagNext<CR>")
    buf_map(bufnr, "n", "<Leader>a", ":LspDiagLine<CR>")
    buf_map(bufnr, "i", "<C-x><C-x>", "<cmd> LspSignatureHelp<CR>")
    if client.resolved_capabilities.document_formatting then
        vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()")
    end
end
lspconfig.tsserver.setup({
    on_attach = function(client, bufnr)
        client.resolved_capabilities.document_formatting = false
        client.resolved_capabilities.document_range_formatting = false
        local ts_utils = require("nvim-lsp-ts-utils")
        ts_utils.setup({enable_import_on_completion = false, debug = true})
        ts_utils.setup_client(client)
        buf_map(bufnr, "n", "gs", ":TSLspOrganize<CR>")
        buf_map(bufnr, "n", "go", ":TSLspRenameFile<CR>")
        buf_map(bufnr, "n", "go", ":TSLspImportAll<CR>")
        buf_map(bufnr, "n", "gi", ":TSLspImportCurrent<CR>")
        on_attach(client, bufnr)
    end,
})
null_ls.setup({
    sources = {
        null_ls.builtins.diagnostics.eslint_d,
        null_ls.builtins.code_actions.eslint_d,
        null_ls.builtins.formatting.prettier,
    },
    on_attach = on_attach,
})

samtipton avatar May 26 '22 20:05 samtipton

I can't really act on this given your reproduction instructions, since there's so many variables that could be affecting this (project structure, TypeScript / LSP versions, etc.). This plugin is in maintenance mode, so I recommend trying typescript.nvim, which has a much cleaner implementation of the same functionality.

If you run into issues there, too, please make sure to provide version numbers as well as a minimal project that I can clone to replicate the issue on my end.

jose-elias-alvarez avatar May 26 '22 21:05 jose-elias-alvarez

I understand, it randomly worked this morning using my normal work flow. Opened another file and it didn't work. Thanks for responding.

samtipton avatar May 27 '22 14:05 samtipton