jose-elias-alvarez / nvim-lsp-ts-utils

Utilities to improve the TypeScript development experience for Neovim's built-in LSP client.
The Unlicense
438 stars 18 forks source link

NOT AN EDITOR COMMAND! #50

Closed JS-junky closed 3 years ago

JS-junky commented 3 years ago

i installed the plugin and all of it's dependencies, copied the config form the repo into my lsp-config. but every time i run a command i get this message as if the plugin wasn't installed at all!

jose-elias-alvarez commented 3 years ago

Could you post your tsserver config? Also, which plugin manager are you using? If you're using Packer, did you run :PackerSync after setting everything up?

JS-junky commented 3 years ago

i use vim-plug and here is my tsserver config:

nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> gv :vs<CR><cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> gs :sp<CR><cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> gt :sp<CR><cmd>lua vim.lsp.buf.definition()<CR><C-W>T
nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> <A-n> <cmd>lua vim.lsp.diagnostic.goto_prev()<CR>
nnoremap <silent> <A-m> <cmd>lua vim.lsp.diagnostic.goto_next()<CR>
nnoremap <silent> <A-r> <cmd>lua vim.lsp.buf.rename()<CR>

" auto-format
autocmd BufWritePre *.js lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.jsx lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.ts lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.json lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.html lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.css lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.sql lua vim.lsp.buf.formatting_sync(nil, 100)

lua << EOF
  local nvim_lsp = require("lspconfig")
nvim_lsp.tsserver.setup {
    on_attach = function(client, bufnr)
        local ts_utils = require("nvim-lsp-ts-utils")
        -- defaults
        ts_utils.setup {
            debug = true,
            disable_commands = false,
            enable_import_on_completion = true,

            -- import all
            import_all_timeout = 5000, -- ms
            import_all_priorities = {
                buffers = 4, -- loaded buffer names
                buffer_content = 3, -- loaded buffer content
                local_files = 2, -- git files or files with relative path markers
                same_file = 1, -- add to existing import statement
            },
            import_all_scan_buffers = 100,
            import_all_select_source = false,

            -- update imports on file move
            update_imports_on_move = false,
            require_confirmation_on_move = false,
            watch_dir = nil,
        }

        -- required to fix code action ranges
        ts_utils.setup_client(client)
    end
}
EOF

PS: i also did move all of my configs to a lua file... still didn't work :)

jose-elias-alvarez commented 3 years ago

It looks like you’ve specifically set disable_commands to true, which is most likely the cause of what you’re seeing. Can you try deleting that line and see if it works?

On Jul 25, 2021, at 7:22 PM, JS-junky @.***> wrote:

 i use vim-plug and here is my tsserver config:

nnoremap gd lua vim.lsp.buf.definition() nnoremap gv :vslua vim.lsp.buf.definition() nnoremap gs :splua vim.lsp.buf.definition() nnoremap gt :splua vim.lsp.buf.definition()T nnoremap gD lua vim.lsp.buf.declaration() nnoremap gr lua vim.lsp.buf.references() nnoremap gi lua vim.lsp.buf.implementation() nnoremap K lua vim.lsp.buf.hover() nnoremap lua vim.lsp.diagnostic.goto_prev() nnoremap lua vim.lsp.diagnostic.goto_next() nnoremap lua vim.lsp.buf.rename()

" auto-format autocmd BufWritePre .js lua vim.lsp.buf.formatting_sync(nil, 100) autocmd BufWritePre .jsx lua vim.lsp.buf.formatting_sync(nil, 100) autocmd BufWritePre .py lua vim.lsp.buf.formatting_sync(nil, 100) autocmd BufWritePre .ts lua vim.lsp.buf.formatting_sync(nil, 100) autocmd BufWritePre .json lua vim.lsp.buf.formatting_sync(nil, 100) autocmd BufWritePre .html lua vim.lsp.buf.formatting_sync(nil, 100) autocmd BufWritePre .css lua vim.lsp.buf.formatting_sync(nil, 100) autocmd BufWritePre .sql lua vim.lsp.buf.formatting_sync(nil, 100)

lua << EOF local nvim_lsp = require("lspconfig") nvim_lsp.tsserver.setup { on_attach = function(client, bufnr) local ts_utils = require("nvim-lsp-ts-utils") -- defaults ts_utils.setup { debug = true, disable_commands = true, enable_import_on_completion = true,

    -- import all
    import_all_timeout = 5000, -- ms
    import_all_priorities = {
        buffers = 4, -- loaded buffer names
        buffer_content = 3, -- loaded buffer content
        local_files = 2, -- git files or files with relative path markers
        same_file = 1, -- add to existing import statement
    },
    import_all_scan_buffers = 100,
    import_all_select_source = false,

    -- update imports on file move
    update_imports_on_move = false,
    require_confirmation_on_move = false,
    watch_dir = nil,
}

-- required to fix code action ranges
ts_utils.setup_client(client)

end } EOF

PS: i also did move all of my configs to a lua file... still didn't work :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

JS-junky commented 3 years ago

actually no i tried both, true and false... still got the same result :)

jose-elias-alvarez commented 3 years ago

Sorry, I'm not sure I can help with this one. Your tsserver config is fine – I've used it (both via Lua and directly in Vimscript) to successfully load the plugin and verified that the commands are created.

If the Lua block in your configuration is running properly, there's no reason why the commands wouldn't be created, so I think the issue has to do with your plugin / config setup. I would verify that on_attach is actually running, since that's the likeliest culprit, but other than that, there are too many variables for me to help out here.

Edit: also, are you by any chance calling tsserver.setup more than once? If so, that would explain why your LSP configuration is (presumably) working, but on_attach isn't getting called, so that might be worth looking into.

JS-junky commented 3 years ago

yeah that was it... i was calling tsserver.setup more than once thanks for the help man :) now i gotta try out ur plugin :D

jose-elias-alvarez commented 3 years ago

Great! Glad we were able to figure out.