Fix: Handle vim.fn.getcompletion errors gracefully with pcall #132
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! 🙏