Skip to content

fix: handle empty LSP glob patterns#702

Merged
stevearc merged 3 commits intostevearc:masterfrom
djdv:fix/lsp-pattern-globs
Dec 29, 2025
Merged

fix: handle empty LSP glob patterns#702
stevearc merged 3 commits intostevearc:masterfrom
djdv:fix/lsp-pattern-globs

Conversation

@djdv
Copy link
Contributor

@djdv djdv commented Dec 27, 2025

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 s parameter being passed to our glob function, 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 s is empty, but if #filtered == 0 then catches 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 glob so that patterns are always sanitized and conditionally sorted before being passed to to_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+g47aef025a7 on 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.

@github-actions github-actions bot requested a review from stevearc December 27, 2025 21:20
@djdv djdv mentioned this pull request Dec 27, 2025
3 tasks
@djdv djdv force-pushed the fix/lsp-pattern-globs branch from 6ab8992 to 5e3715c Compare December 27, 2025 21:45
@stevearc
Copy link
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!

@stevearc stevearc merged commit 963c8d2 into stevearc:master Dec 29, 2025
10 checks passed
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.

bug: Invalid glob: **/*.{}

2 participants