Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

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

Open
2 tasks done
samtipton opened this issue May 26, 2022 · 3 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@samtipton
Copy link

FAQ

Issues

  • 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 samtipton added the bug Something isn't working label May 26, 2022
@samtipton
Copy link
Author

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,
})

@jose-elias-alvarez
Copy link
Owner

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.

@samtipton
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants