Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Added optional neverFilter tag to suggestions #877

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

onelivesleft
Copy link

@onelivesleft onelivesleft commented Aug 2, 2017

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++ into foo = 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

  1. 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

  2. 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

If a suggestion has neverFilter = true then it will not be filtered out when the provider's filterSuggestions is true.
@nathansobo
Copy link
Contributor

@leroix Can you take a look at this? Not super versed on the API but it seems like this PR is fixing a bug and could enable much cooler autocomplete features.

@leroix
Copy link
Contributor

leroix commented Nov 2, 2017

@onelivesleft I've been trying to dig into this a little bit. I think maybe we shouldn't filter a suggestion just because the first character in the suggestion text doesn't match the first character of the prefix. I'm not sure what removing this would break though.

For the example you mentioned, I think you could add that functionality to the autocomplete-lua provider. The provider would check if the prefix matches the pattern you mentioned and return foo = foo + 1 as a suggestion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants