yegappan / lsp

Language Server Protocol (LSP) plugin for Vim9
MIT License
473 stars 57 forks source link

An auto-import may trigger twice when using multiple LSP servers and multiple buffers #527

Open moussetf opened 4 months ago

moussetf commented 4 months ago

When using multiple LSP servers for the same file type, one of which provides completions/auto-imports, and when working with multiple buffers (using set hidden), an auto-import may trigger twice.

Setup. I am using the following vimrc with VIM 9.1.16, not using any packages besides lsp:

vim9script
set hidden
var lspServers = [
    { name: 'python-pyright', filetype: ['python'], path: 'pyright-langserver', args: ['--stdio'],
        workspaceConfig: {
            python: { pythonPath: 'python', analysis: { autoImportCompletions: true }
            }
        }
    },
    { name: 'efm-languageserver', filetype: ['python'], path: 'efm-langserver', args: [] }
]
autocmd User LspSetup call LspAddServer(lspServers)

As you can see, I am using pyright together with a second language server defined for the python file type, which does not really do anything in this case.

Steps to reproduce. Open a new python file using vim foo.py and type some text (e.g. get_cache_) and accept the auto-import suggestion. The function get_cache_token is imported once as expected. Now open a second buffer with :e bar.py and then do the same thing (type get_cache_ and accept the auto-import suggestion). Now the same function is imported twice.

Some notes:

  1. When the second language server is not present, the issue does not appear.
  2. Although the example above uses pyright/efm-langserver, I can reproduce the same issue with other combinations of LSP servers (I have also tested pyright/pylsp and typescript-language-server/efm-langserver for the typescript filetype). So this seems like it is not connected to a particular LSP server.

I believe this is a different issue than #522.