This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
Added optional neverFilter tag to suggestions #877
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.
If a suggestion has neverFilter = true then it will not be filtered out when the provider's filterSuggestions is true.
Description of the Change
Right now if you have
filterSuggestions = true
in your provider then any suggestion with a replacementPrefix will be filtered out unless the snippet also matches the replacement prefix. Take this example:Lua does not support ++ or -- operators. I want to make a suggestion which will expand the user typing
foo++
intofoo = foo + 1
. However, in this case we want to replace "++" with "= ..."; this works OK if filterSuggestions is disabled, but when it is enabled the filter eats this suggestion.This fix works by checking for a neverFilter property in the suggestion; if it's set to true then the suggestion is kept by the filter method.
Alternate Designs
Never filter a suggestion list when it contains only one suggestion. Add this as the first line in filterSuggestions:
if (suggestions.length == 1) return suggestions
Reverse this line:
const text = (suggestion.snippet || suggestion.text)
so it reads
const text = (suggestion.text || suggestion.snippet)
The user can then set the text property so that it matches the replacementPrefix, but keep the snippet property as what they want to appear (the snippet takes precedence for completion).
Both of these feel like they'd have unintentional knock-on effects, and neither are particularly obvious to the user.
Benefits
Gives the provider maker the ability to "force-through" a suggestion, ensuring it does not get filtered by filterSuggestions.
Possible Drawbacks
Unlike the two alternative designs, there is very little chance of adverse effect here. Slight bloat to the Provider suggestion api as it gains a property.
Applicable Issues
#777, can possibly be used to work around #781 and #615