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

Suggestions are being dropped when they have the same text. #615

Closed
ghost opened this issue Nov 16, 2015 · 7 comments
Closed

Suggestions are being dropped when they have the same text. #615

ghost opened this issue Nov 16, 2015 · 7 comments

Comments

@ghost
Copy link

ghost commented Nov 16, 2015

Hello

I have a provider that supplies multiple suggestions that share the same text property, but that are in fact different suggestions. However, autocomplete-plus seems to be filtering them out. If I prefix them with something to ensure they are unique strings, they suddenly do show up. This behavior seems unwanted as it's the provider's responsibility to ensure the suggestions are unique when they need to be, i.e. it would be bug in my code.

(More information about my specific use case:) I'm autocompleting PHP class names using their FQCN (fully qualified class name, separated by slashes) such as Foo\Class1 and Foo\Bar\Class1. These full names are passed as displayText, but when the user selects the suggestion, I only complete the last part of the class name. A use (import) statement is then automatically added on top. Hence, Foo\Class1 and Foo\Bar\Class1 will both share the same text property, but a different displayText, and they will also be treated differently on onDidInsertSuggestion.

Thanks in advance

@nwolverson
Copy link

Any workaround for this? I'm hitting exactly the same issue (same text, different display, want to do something on insert).

@Gmousse
Copy link

Gmousse commented Apr 18, 2016

+1 I had the same problem.
I just add a tricky trick to avoid this.

When I detect suggestions with the same text, I add a token after each text.
Example:

                if (completions.filter(completion => completion.text === proposition.text).length > 0) {
                    proposition.text += '#?';
                }
                completions.push(Object.assign({}, proposition));

Then, autocomplete-plus provides each suggestion.
Then, I use onDidInsertSuggestion to delete this token on user editor:

    onDidInsertSuggestion({editor, triggerPosition, suggestion}) {
        if (suggestion.text.includes('#?')) {
            const line = editor.lineTextForBufferRow(triggerPosition.row);
            const replacement = line.split('#?').join('');
            editor.setTextInBufferRange([[triggerPosition.row, 0], [triggerPosition.row, line.length]], replacement);
        }
    }

Maybe it will helps you...

@nwolverson
Copy link

I tried inserting a qualifier and removing it on onDidInsertSuggestion, but this made undo bad. In the end I'm using both text and snippet, giving unique text and relying on snippet being inserted

@noseglid
Copy link

noseglid commented May 6, 2016

Also ran into this issue. In Java it's very common that the same class exists in a multitude of packages List, Decoder, Array are some examples. I want to insert List in the editor, but I want to display all entries (if they're from java.util, java.awt, etc).

I'm using the text/snippet workaround by @nwolverson (thanks!), but this is undocumented and feels quite hacky. A supported fix for this issue would be nice!

@torkiljohnsen
Copy link

👍 In PHP too

Two classes with identical names, but different namespaces:
Vendor\Package\Json
OtherVendor\Package\Json

… only one of them are shown when typing "Json" and autocompleting.

@ghost
Copy link
Author

ghost commented May 22, 2016

On a related note, I'm wondering if it would be interesting to take this one step further and provide a filterText property for each suggestion that should be used during fuzzy matching rather than the text property. For example, with two classes that I can autocomplete: Foo\Class and Bar\Class, they:

  • ... both have text Class (the appropriate use statement is added after insertion).
  • ... have different displayText properties displaying their complete name.

The problem is now that if I type Foo\ or Bar\, no suggestions show up. I think this happens because the fuzzy matching happens on the text property, which is now just Class. If this is too much work, fuzzy matching could also be happening on the displayText, because that is the one being highlighted in the suggestions window, after all. But this may not be desired behavior if you display method parameter lists during completion that you do not want to make part of the matching process.

All of this could also be solved by just using the full class names everywhere (as suggested above) and doing some magic after insertion to remove the "incorrect" inserted text, but this becomes a hassle to manage for multiple cursors.

@hultberg
Copy link

Bumping this. Any solution to the issue? As @torkiljohnsen is pointing out, autocomplete must allow multiple text to be able suggested.

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

No branches or pull requests

6 participants