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

Add a callback function for the Accept button of inline suggestion toolbar #198721

Closed
gugeonmo opened this issue Nov 21, 2023 · 5 comments
Closed
Assignees

Comments

@gugeonmo
Copy link

Inline Suggestion Toolbar

drawing

Current Feature

export interface InlineCompletionItemProvider {
/**
* @param completionItem The completion item that was shown.
* @param updatedInsertText The actual insert text (after brackets were fixed).
*/
// eslint-disable-next-line local/vscode-dts-provider-naming
handleDidShowCompletionItem?(completionItem: InlineCompletionItem, updatedInsertText: string): void;
/**
* Is called when an inline completion item was accepted partially.
* @param acceptedLength The length of the substring of the inline completion that was accepted already.
*/
// eslint-disable-next-line local/vscode-dts-provider-naming
handleDidPartiallyAcceptCompletionItem?(completionItem: InlineCompletionItem, acceptedLength: number): void;
}

When we click "Accept Word" of the inline suggestion toolbar,
the function handleDidPartiallyAcceptCompletionItem is called
so that we can handle the event for partially accepted suggestion.

For the "Accept" button, however, we don't have a corresponding function.

New Feature

Can we add a function that is called when an inline completion item was fully accepted by the "Accept" button of the inline suggestion toolbar?

The function would look like as follows:

/**
* Is called when an inline completion item was fully accepted.
* @param completionItem The completion item that was shown.
*/
handleDidFullyAcceptCompletionItem?(completionItem: InlineCompletionItem): void;
@hediet
Copy link
Member

hediet commented Nov 21, 2023

You can set a command which is then called.

@hediet hediet closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2023
@gugeonmo
Copy link
Author

@hediet Thank you for replying!

I am not sure if I understood your answer correctly.
Does setting a command mean writing a function body as follows?

handleDidPartiallyAcceptCompletionItem(completionItem: vscode.InlineCompletionItem, acceptedLength: number): void {
	console.log('handleDidPartiallyAcceptCompletionItem');
},

Then, how can I add a command for "full" accept event? (i.e., event for the Accept button was clicked)

@hediet
Copy link
Member

hediet commented Nov 22, 2023

there is a command propert yon the inline completion item itself

@gugeonmo
Copy link
Author

@hediet I see. Thank you for the answer.

For those who need explanation, here is the main part of the code for handling the accept event using the property on the inline completion item.

export function activate(context: vscode.ExtensionContext) {
  function handleAccept() {
    console.log("Accepted");
  }
  vscode.commands.registerCommand('accept.command1', handleAccept);
  const provider: vscode.InlineCompletionItemProvider = {
    async provideInlineCompletionItems(document, position, context, token) {
      const result: vscode.InlineCompletionList = {
        items: [],
        commands: [],
      };
      // TODO: make suggestion text, position_range, and completeBracketPairs
      result.items.push({
        insertText: text,
        range: position_range,
        completeBracketPairs,
        command: {command: 'accept.command1', title: 'my title'},
      });
     return result
  }
};

@hediet
Copy link
Member

hediet commented Nov 23, 2023

dont forget to unregister your temporary commands!

@github-actions github-actions bot locked and limited conversation to collaborators Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants