microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.49k stars 28.1k forks source link

Invoked inlineCompletion not working when IntelliSense is open #213658

Open viktomas opened 1 month ago

viktomas commented 1 month ago

Does this issue occur when all extensions are disabled?: Yes

Problem

The problem is that if IntelliSense is open and the InlineCompletionProvider is Invoked and returns multiple items, only the first one is shown, and the suggestion toolbar doesn't show a counter.

show-simplified-inline-completion-issue

This issue happens in VS Code. I created a minimal extension to reproduce the issue here https://gitlab.com/viktomas/vscode-extension-itellisensense-inline-completion-issue

Steps to Reproduce:

  1. Clone the example extension git clone https://gitlab.com/viktomas/vscode-extension-itellisensense-inline-completion-issue.git
  2. Run it in development mode
  3. Open any typescript file (the example extension hardcodes typescript, but this issue is not related to the language)
  4. It will complete "Hello World" text when the IntelliSense is open
  5. When you hover over the suggestion (or invoke with Option+]), the completion provider implementation returns multiple options
  6. VS Code only shows the first option, and the toolbar is missing a counter

Considerations

It's possible that I misunderstood the documentation and I craft the vscode.InlineCompletionItem incorrectly. However, then I would expect that the inline item won't show even if the completion is Automatically invoked.

Example implementation

For completeness, I also include the relevant part of the extension.ts file from the example extension.

The full example code can be checked here https://gitlab.com/viktomas/vscode-extension-itellisensense-inline-completion-issue/-/commit/d8f156fac429ce713b02c020be573eed068d7b61, it's 36 lines.

vscode.languages.registerInlineCompletionItemProvider(
    { scheme: 'file', language: 'typescript' },
    {
      async provideInlineCompletionItems(
        document: vscode.TextDocument,
        position: vscode.Position,
        context: vscode.InlineCompletionContext,
        token: vscode.CancellationToken
      ): Promise<vscode.InlineCompletionItem[]> {
        const items: vscode.InlineCompletionItem[] = [
          { insertText: 'Hello World' },
          { insertText: 'Hello World 1' },
          { insertText: 'Hello World 2' },
        ];

        // we only care about the case when IntelliSense is open
        if (!context.selectedCompletionInfo) {
          return [];
        }

        // the items have to start with the IntelliSense text and they replace the original intellisense range
        const result = items.map((i) => ({
          insertText: `${context.selectedCompletionInfo!.text} ${i.insertText}`,
          range: context.selectedCompletionInfo!.range,
        }));

        // only return one item if the completion is automatically invoked
        if (
          context.triggerKind === vscode.InlineCompletionTriggerKind.Automatic
        ) {
          return [result[0]];
        }
        return result;
      },
    }
  );
hediet commented 1 month ago

The problem is that if IntelliSense is open and the InlineCompletionProvider is Invoked and returns multiple items, only the first one is shown, and the suggestion toolbar doesn't show a counter.

At the moment, for suggest augmentations, we only consider the first inline suggestion that augments the selected suggest item:

https://github.com/microsoft/vscode/blob/3ea4e9e7ef2609624a4b6ac24b2cac04212a214c/src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsModel.ts#L258-L272

VSCodeTriageBot commented 1 month ago

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!