Fix: Handle vim.fn.getcompletion errors gracefully with pcall#132
Open
esmuellert wants to merge 1 commit intohrsh7th:mainfrom
Open
Fix: Handle vim.fn.getcompletion errors gracefully with pcall#132esmuellert wants to merge 1 commit intohrsh7th:mainfrom
esmuellert wants to merge 1 commit intohrsh7th:mainfrom
Conversation
vim.fn.getcompletion() can throw errors when the cmdline contains
malformed or incomplete patterns (e.g., unmatched braces like 'HEAD@{}',
incomplete regex patterns like '\(foo', etc).
This causes crashes with error messages like:
- E220: Missing }
- E54: Unmatched \(
- E869: Unknown operator
This fix wraps the getcompletion call with pcall to handle errors
gracefully, returning an empty completion list instead of crashing.
Fixes hrsh7th#73
Fixes hrsh7th#101
Related to hrsh7th#102
|
this would be an amazing fix, thank you for the work |
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.
Fix: Handle vim.fn.getcompletion errors gracefully
Problem
vim.fn.getcompletion()throws errors when the command line contains malformed or incomplete patterns. This is a common occurrence during normal typing and causes frequent crashes.Reproduction cases:
Unmatched braces (Git users hit this constantly):
:CodeDiff HEAD@{Error:
E220: Missing }Incomplete regex patterns:
Error:
E54: Unmatched \(Other pattern errors:
Error:
E869: Unknown operatorImpact:
}error when typing:e {#73, Error when callingvim.fn.getcompletion()for cmdline has unfinished regex patterns #101)Solution
Wrap
vim.fn.getcompletion()withpcall()to catch errors gracefully.Changes:
Why this is the correct fix:
Testing
Before fix:
After fix:
Related Issues
}error when typing:e {#73 - E220: Missing}error (opened Nov 2022)vim.fn.getcompletion()for cmdline has unfinished regex patterns #101 - Error with unfinished regex patterns (opened Jun 2023)Please Review
This is a simple, 3-line fix for a 3-year-old bug affecting many users in common workflows (Git commands, regex patterns, etc).
The fix has been tested by users and is already being used as a local workaround in the community.
Thank you for maintaining this essential plugin! 🙏