pmizio / typescript-tools.nvim

⚡ TypeScript integration NeoVim deserves ⚡
MIT License
1.45k stars 40 forks source link

`lsp.buf.rename` does not open affected buffers #261

Closed dan-cooke closed 5 months ago

dan-cooke commented 5 months ago

Renaming a symbol via lsp.buf.rename causes the symbol to be renamed - but the affected buffers are not opened. So I have to manually open them and save them.

I am sure this is a bug with my setup, as everywhere online suggests this works as expected with even just basic tsserver

Reproduction

With this keymap set

vim.keymap.set("n", "gr", ":lua vim.lsp.buf.rename() <cr>")

And the following Typescript files

foo.ts

const foo = 'bar';

baz.ts

import { foo } from './foo';

console.log(foo)

If I hover over foo and press gr ie. run lsp.buf.rename() and type hello

And now I run :ls I can only see foo.ts in here

But if i open baz.ts, i can see it has renamed the symbol- (it just doesnt open the buffer for me)

Expected result

I should see foo.ts and baz.ts in here

I'm nearly certain this is not an issue with your plugin, as this happens even with my vanilla tsserver setup

Here is my packer.lua

return require('packer').startup(function(use)
    -- Packer can manage itself
    use 'wbthomason/packer.nvim'

    use 'windwp/nvim-ts-autotag'
    use {
        'nvim-lualine/lualine.nvim',
        requires = { 'nvim-tree/nvim-web-devicons', opt = true }
    }

    use { 'nvim-orgmode/orgmode', config = function()
        require('orgmode').setup {}
    end
    }

    use('nvim-treesitter/nvim-treesitter', { run = ':TSUpdate' })
    use('traxys/tree-sitter-lalrpop')
    use 'nvim-pack/nvim-spectre'
    use 'folke/trouble.nvim'

    -- CMP
    --

    use 'hrsh7th/nvim-cmp'
    use 'hrsh7th/cmp-nvim-lsp'
    use 'L3MON4D3/LuaSnip'
    use 'saadparwaiz1/cmp_luasnip'

    -- COPILOT
    --
    use {
        "zbirenbaum/copilot.lua",
        cmd = "Copilot",
        event = "InsertEnter",
        config = function()
            local suggestion = require("copilot.suggestion");

            require("copilot").setup({

                panel = {
                    auto_refresh = false,
                    enabled = false
                },

                suggestion = {
                    auto_trigger = true,
                    enabled = true,
                    debounce = 40,
                    keymap = {
                        accept = "<Tab>",
                        accept_word = false,
                        accept_line = false,
                        next = "<C-x>",
                        prev = "<M-[>",
                        dismiss = "<C-]>",
                    },

                },

            })
        end,

    }

    use { "ellisonleao/gruvbox.nvim" }
    use 'ful1e5/onedark.nvim'
    use 'nvim-tree/nvim-tree.lua'
    use 'nvim-tree/nvim-web-devicons'
    use 'ThePrimeagen/harpoon'

    use({
        "ghillb/cybu.nvim",
        branch = "main",                                                     -- timely updates
        -- branch = "v1.x", -- won't receive breaking changes
        requires = { "nvim-tree/nvim-web-devicons", "nvim-lua/plenary.nvim" }, -- optional for icon support
    })

    use {
        'VonHeikemen/lsp-zero.nvim',
        branch = 'v2.x',

        requires = {
            -- LSP Support
            { 'neovim/nvim-lspconfig' }, -- Required
            {                         -- Optional
                'williamboman/mason.nvim',
                run = function()
                    pcall(vim.cmd, 'MasonUpdate')
                end,
            },
            { 'williamboman/mason-lspconfig.nvim' }, -- Optional

            -- Autocompletion
            { 'hrsh7th/nvim-cmp' },  -- Required
            { 'hrsh7th/cmp-nvim-lsp' }, -- Required
            { 'L3MON4D3/LuaSnip' },  -- Required

            { 'jose-elias-alvarez/null-ls.nvim' },
            { 'MunifTanjim/prettier.nvim' }
        }
    }

    use 'christoomey/vim-tmux-navigator'

    use { "catppuccin/nvim", as = "catppuccin" }

    use 'm4xshen/autoclose.nvim'

    use "lunarvim/horizon.nvim"
    use {
        "pmizio/typescript-tools.nvim",
        requires = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" },
        config = function()
            require("typescript-tools").setup {

            }
        end,
    }

    use 'HiPhish/rainbow-delimiters.nvim'
    use 'terrortylor/nvim-comment'

    require('packer').use({
        'weilbith/nvim-code-action-menu',
        cmd = 'CodeActionMenu',
    })
    use { 'kosayoda/nvim-lightbulb' }

    use 'simrat39/rust-tools.nvim'
    use 'saecki/crates.nvim'

    use 'onsails/lspkind.nvim'

    use 'ray-x/go.nvim'
    use 'ray-x/guihua.lua' -- recommended if need floating window support

    use({
        "kylechui/nvim-surround",
        tag = "*", -- Use for stability; omit to use `main` branch for the latest features
        config = function()
            require("nvim-surround").setup({
                -- Configuration here, or leave empty to use defaults
            })
        end
    })

    use 'joerdav/templ.vim'

    use { "ibhagwan/fzf-lua",
        -- optional for icon support
        requires = { "nvim-tree/nvim-web-devicons" }
    }

    use 'stevearc/profile.nvim'

    use "stevearc/oil.nvim"
end)

And my lsp setup

local lsp = require('lsp-zero').preset({
})

lsp.ensure_installed({
    'eslint',
    'rust_analyzer',
})

lsp.on_attach(function(client, bufnr)
    local capabilities = vim.lsp.protocol.make_client_capabilities()
    capabilities.textDocument.completion.completionItem.snippetSupport = true
    lsp.default_keymaps({ buffer = bufnr })
    lsp.buffer_autoformat()
end)

vim.keymap.set("n", "gr", ":lua vim.lsp.buf.rename() <cr>")
vim.keymap.set("n", "<leader>g", ":lua vim.lsp.buf.hover() <cr>")
vim.keymap.set("n", "<leader>]", ":lua vim.diagnostic.goto_next() <cr>")
vim.keymap.set("n", "<leader>[", ":lua vim.diagnostic.goto_prev() <cr>")
vim.keymap.set("n", "gh", ":lua vim.diagnostic.open_float() <cr>")
vim.keymap.set("n", "gd", ":lua vim.lsp.buf.definition() <cr>")
vim.diagnostic.config({
    virtual_text = false,
    root_dir = require("lspconfig.util").root_pattern(".git")
})

lsp.format_on_save({
    format_opts = {
        async = false,
        timeout_ms = 10000,
    },
    servers = {
        ['rust_analyzer'] = { 'rust' },
        ['prettier'] = { 'css', 'html', 'javascript', 'javascriptreact', 'json', 'less', 'scss', 'typescript', 'typescriptreact', 'vue' },
    }
})

lsp.set_server_config({
    on_init = function(client)
        client.server_capabilities.semanticTokensProvider = nil
    end,
})

lsp.set_sign_icons({
    error = '✘',
    warn = '▲',
    hint = '⚑',
    info = '»'
})

lsp.setup()

Thanks for the great plugin btw! Any advice/help is appreciated - thank you

dan-cooke commented 5 months ago

Never mind, I am closing this - the issue was with tsserver I was still using tsserver instead

Fixed it by uninstalling tsserver via mason