Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: autostart=false: attach when editing new, nonexistent file #2712
## Problem Currently, `nvim-lspconfig` tries to attach servers automatically via two autocommands: 1. Created if `config.autostart == true` and triggered by `FileType`, if `config.filetypes` is set, else `BufReadPost`. Calls `try_add()`. 2. Created for each workspace root, triggered by `BufReadPost` matching paths starting with the root. Calls `try_add_wrapper()`. `BufReadPost` does not fire when creating a buffer for a file that doesn't exist. This means that if `config.autostart == true` and `config.filetypes` is set and includes the detected filetype for the buffer, the server is attached automatically regardless of whether the file exists, but in all other cases the server is only attached for existing files. ## Solution 1. Where these autocommands trigger on `BufReadPost`, also trigger on `BufNewFile`. 2. Wrap the autocommand callbacks in `vim.schedule()` to ensure `filetype` is set first, as the `BufReadPost`/`BufNewFile` autocommands will trigger before `FileType` if `nvim-lspconfig` is set up early enough during Nvim init (see neovim/neovim#7367 and #2712 (comment)). I did consider including a test with this PR, but there doesn't seem to be any existing test infrastructure for tests involving actually running a language server (or a mock of one). Fixes #2711
- Loading branch information
fb453a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Facing the following error, after this commit:
fb453a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reporting. Reverted: #3347