Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix: autostart=false: attach when editing new, nonexistent file" #3347

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

glepnir
Copy link
Member

@glepnir glepnir commented Oct 4, 2024

Reverts #2712

@glepnir
Copy link
Member Author

glepnir commented Oct 4, 2024

this pr will cause invalid buffer id . If possible, it would be best to import the test suite from core so that lspconfig can test some buffer and server connection behaviors.

@glepnir glepnir merged commit 3f9fe72 into master Oct 4, 2024
9 checks passed
@glepnir glepnir deleted the revert-2712-autocmd_fix branch October 4, 2024 06:59
justinmk referenced this pull request Oct 4, 2024
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant