Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when writing a new CompletionItemProvider it is very hard debug as to why the item is not being offered #41022

Open
capaj opened this issue Jan 2, 2018 · 6 comments
Assignees
Labels
feature-request Request for new features or functionality suggest IntelliSense, Auto Complete
Milestone

Comments

@capaj
Copy link

capaj commented Jan 2, 2018

Whenever I try to write a new CompletionItemProvider, I always have to bang my head against the table many times because there are many rules which hide your item from the completion menu.

I get that these rules are needed, but it is often frustrating for a developer to just see his completion items disappear. Could we get some kind of debug mode for CompletionItemProvider so that we can more easily see what is going on with our Completion items?

It would be great to have it something like:

class CompletionItemProvider {
  static debug = true
  provideCompletionItems(document, position: Position, token) {}
}

then VSCode would log all reasons why any completion item from this provider was hidden.
Could we have this feature please?

@vscodebot vscodebot bot added the debug Debug viewlet, configurations, breakpoints, adapter issues label Jan 2, 2018
@isidorn isidorn removed the debug Debug viewlet, configurations, breakpoints, adapter issues label Jan 2, 2018
@isidorn isidorn assigned jrieken and unassigned isidorn Jan 2, 2018
@jrieken jrieken added extensions Issues concerning extensions suggest IntelliSense, Auto Complete labels Jan 3, 2018
@jrieken
Copy link
Member

jrieken commented Jan 3, 2018

Yeah, I was thinking about something similar a while back. We could always show all items, without sorting or filtering, and then show their assigned rank and the word that have been matched against...

@jrieken jrieken added feature-request Request for new features or functionality and removed extensions Issues concerning extensions labels Jul 27, 2018
@jrieken jrieken added this to the Backlog milestone Jan 13, 2020
@michaeljones
Copy link

Is there a way to start to understand what VS Code is doing? I have a situation with a custom extension where we're providing completions for after an & of:

&arduino_adc
&arduino_header

And if the user then types an a then it narrows down to just:

&arduino_adc

And highlights the a after the underscore instead of keeping them both and highlighting the a after the &.

It might well be something that we're doing but I can't understand it from our perspective. The completions only seem to be asked for once and then the narrowing down with addition keypresses seems to be down by VS Code so it seems that VS Code is matching after the underscore instead of the start.

Of course, general completions don't seem to be doing that but I am struggling to understand why this one would be. I would welcome any information. Perhaps there is a bit of the code base where the narrowing is done that I might try to understand?

@michaeljones
Copy link

Sorry, as ever, you figure it out after posting for help.

I didn't have the filterText on the CompletionItems set properly. The CompletionItem label included the & but the & is already in the file so we don't want it in the final completion and so I needed to set the filter text to be the label without the leading &.

@jrieken
Copy link
Member

jrieken commented Mar 16, 2022

Shout to this related (may duplicated) issue that is actually implemented since a while: #75500


There is the "explain mode" for suggest. Do this

  • trigger suggest
  • select Cmd+? (Ctrl+? on windows/linux)
  • the suggest details pane will now show details about ranking and sorting

You will see something similar to the screen shot below:

  • the extension/provider from which the suggestion is from
  • the score that ranking computed
  • which prefix was ranked against what text (either filterText or label of the suggestion)
  • the initial sort order (as defined by sortText)
  • also the commit characters and if the item was boosted based on locality)

Screenshot 2022-03-16 at 08 46 26


What's not implemented is a way to get this information for items that aren't showing in suggest, e.g those that have been filtered out because no match has been computed.

@tbazant
Copy link

tbazant commented Sep 4, 2023

Sorry, as ever, you figure it out after posting for help.

I didn't have the filterText on the CompletionItems set properly. The CompletionItem label included the & but the & is already in the file so we don't want it in the final completion and so I needed to set the filter text to be the label without the leading &.

Hi, can you provide example on the filterText property that solved your problem? I'm fighting with this...microsoft/vscode-discussions#797

@michaeljones
Copy link

I've not worked on that code for a while now. Here is a slice of it:

    // If the string before the completion ends in an '&' then we assume that the characters that the user is typing to
    // match against the label do not include the initial '&' so we make sure not to include it in the filtering and
    // insert logic
    const filterTextIncludesAmp = !before?.endsWith('&');

    return labels.map((l) => {
        const ampersandLabel = `&${l.label}`;
        const completion = new vscode.CompletionItem(
            ampersandLabel,
            vscode.CompletionItemKind.Class
        );

        if (!filterTextIncludesAmp) {
            // Handle completion based off the label name without the initial '&' as that '&' is already in the
            // document. We want to include the '&' in the labels though as it is clearer for users what they are
            // completing.
            completion.filterText = l.label;
        }

Where before is the text leading up to the cursor, I guess.

I guess the main completion value should include the & but the filterText shouldn't if the & has already been written. Not sure. I forget the details. I hope it helps though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality suggest IntelliSense, Auto Complete
Projects
None yet
Development

No branches or pull requests

5 participants