fix: handle empty LSP glob patterns#702
Merged
stevearc merged 3 commits intostevearc:masterfrom Dec 29, 2025
Merged
Conversation
6ab8992 to
5e3715c
Compare
Owner
|
Seems fine to me. I made one tweak to make the pattern non-greedy (a bug with my original implementation). Thanks for the PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes: #672
I have a screencast of the issue + this patch.
The LSP spec for glob patterns defines the syntax for "group sub patterns" but doesn't mention anything about empty patterns.
Somehow (not investigated) we end up with an empty
sparameter being passed to ourglobfunction, so I assume that since such a pattern isn't explicitly forbidden, that language servers (TSserver, marksman, et al.) emit them?(Maybe this is worth checking up front if
sis empty, butif #filtered == 0 thencatches this. Might be even better to not call this function at all in some higher scopes but I'm not sure.)Imagine patterns such as:
**/*.{md,},**/*.{},**/*.{foo,,bar}.These patterns get rejected by the parser for
vim.glob.to_lpeg():Invalid glob: **/*.{}.This change replaces
globso that patterns are always sanitized and conditionally sorted before being passed toto_lpeg().So that
*.{}is treated like*,*.{md,}->*.{md},*.{foo,,bar}->*.{foo,bar}.I believe these are all permissible in the current spec, so we account for them.
There may be a better way to solve this, I'm not sure.
This works for me in my use case (
NVIM v0.12.0-dev-1908+g47aef025a7on Windows) but could use some testing from others.Older vim users, people reporting this issue on other platforms + LSP servers and scenarios, etc.
Hopefully this approach doesn't break any existing workflows.