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

Support llmGenerated property on CodeAction #1557

Merged
merged 8 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions client-node-tests/src/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,26 @@ suite('Code Converter', () => {
strictEqual(result.triggerKind, proto.CodeActionTriggerKind.Automatic);
});

test('CodeAction - LLMGenerated tag c2p', () => {
const item: vscode.CodeAction = {
title: 'title',
isAI: true
};

const result = c2p.asCodeActionSync(item);
strictEqual(result.tags![0], proto.CodeActionTag.LLMGenerated);
});

test('CodeAction - LLMGenerated tag p2c', async () => {
const item: proto.CodeAction = {
title: 'title',
tags: [proto.CodeActionTag.LLMGenerated]
};

const result = await p2c.asCodeAction(item);
strictEqual(result.isAI, true);
});

test('Uri Rewrite', () => {
const converter = codeConverter.createConverter((value: vscode.Uri) => {
return `${value.toString()}.vscode`;
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"bugs": {
"url": "https://github.com/Microsoft/vscode-languageserver-node/issues"
},
"enabledApiProposals": [],
"enabledApiProposals": ["codeActionAI"],
"exports": {
".": {
"types": "./lib/common/api.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions client/src/common/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
/// <reference path="../../typings/vscode.proposed.codeActionAI.d.ts" />
StellaHuang95 marked this conversation as resolved.
Show resolved Hide resolved

import {
workspace as Workspace, window as Window, languages as Languages, version as VSCodeVersion, TextDocument, Disposable, OutputChannel,
FileSystemWatcher as VFileSystemWatcher, DiagnosticCollection, Diagnostic as VDiagnostic, Uri, CancellationToken, WorkspaceEdit as VWorkspaceEdit,
Expand Down
8 changes: 8 additions & 0 deletions client/src/common/codeConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,10 @@ export function createConverter(uriConverter?: URIConverter): Converter {
if (item.command !== undefined) { result.command = asCommand(item.command); }
if (item.isPreferred !== undefined) { result.isPreferred = item.isPreferred; }
if (item.disabled !== undefined) { result.disabled = { reason: item.disabled.reason }; }
if (item.isAI) {
result.tags ??= [];
result.tags.push(proto.CodeActionTag.LLMGenerated);
}
return result;
}

Expand All @@ -756,6 +760,10 @@ export function createConverter(uriConverter?: URIConverter): Converter {
if (item.command !== undefined) { result.command = asCommand(item.command); }
if (item.isPreferred !== undefined) { result.isPreferred = item.isPreferred; }
if (item.disabled !== undefined) { result.disabled = { reason: item.disabled.reason }; }
if (item.isAI) {
result.tags ??= [];
result.tags.push(proto.CodeActionTag.LLMGenerated);
}
return result;
}

Expand Down
4 changes: 4 additions & 0 deletions client/src/common/protocolConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,10 @@ export function createConverter(
if (item.command !== undefined) { result.command = asCommand(item.command); }
if (item.isPreferred !== undefined) { result.isPreferred = item.isPreferred; }
if (item.disabled !== undefined) { result.disabled = { reason: item.disabled.reason }; }
if (item.tags?.includes(ls.CodeActionTag.LLMGenerated)) {
result.isAI = true;
}

return result;
}

Expand Down
16 changes: 16 additions & 0 deletions client/typings/vscode.proposed.codeActionAI.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module 'vscode' {

export interface CodeAction {
/**
* Marks this as an AI action.
*
* Ex: A quick fix should be marked AI if it invokes AI.
*/
isAI?: boolean;
}
}
31 changes: 31 additions & 0 deletions protocol/metaModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -5812,6 +5812,20 @@
"optional": true,
"documentation": "A data entry field that is preserved on a code action between\na `textDocument/codeAction` and a `codeAction/resolve` request.\n\n@since 3.16.0",
"since": "3.16.0"
},
{
"name": "tags",
"type": {
"kind": "array",
"element": {
"kind": "reference",
"name": "CodeActionTag"
}
},
"optional": true,
"documentation": "Tags for this code action.\n\n@since 3.18.0 - proposed",
"since": "3.18.0 - proposed",
"proposed": true
}
],
"documentation": "A code action represents a change that can be performed in code, e.g. to fix a problem or\nto refactor code.\n\nA CodeAction must set either `edit` and/or a `command`. If both are supplied, the `edit` is applied first, then the `command` is executed."
Expand Down Expand Up @@ -14772,6 +14786,23 @@
"supportsCustomValues": true,
"documentation": "A set of predefined code action kinds"
},
{
"name": "CodeActionTag",
"type": {
"kind": "base",
"name": "uinteger"
},
"values": [
{
"name": "LLMGenerated",
"value": 1,
"documentation": "Render a code action as LLM-generated, usually using a sparkle icon."
}
],
"documentation": "Code action tags are extra annotations that tweak the rendering of a code action.\n\n@since 3.18.0",
"since": "3.18.0",
"proposed": true
},
{
"name": "TraceValue",
"type": {
Expand Down
30 changes: 29 additions & 1 deletion types/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3372,6 +3372,26 @@ export type CodeActionDisabled = {
reason: string;
};

/**
* Code action tags are extra annotations that tweak the rendering of a code action.
StellaHuang95 marked this conversation as resolved.
Show resolved Hide resolved
*
* @since 3.18.0 - proposed
*/
export namespace CodeActionTag {
/**
* Render a code action as LLM-generated, usually using a sparkle icon.
StellaHuang95 marked this conversation as resolved.
Show resolved Hide resolved
*/
export const LLMGenerated = 1;

/**
* Checks whether the given literal conforms to the {@link CodeActionTag} interface.
*/
export function is(value: any): value is CodeActionTag {
return Is.defined(value) && value === CodeActionTag.LLMGenerated;
}
}
export type CodeActionTag = 1;

/**
* A code action represents a change that can be performed in code, e.g. to fix a problem or
* to refactor code.
Expand Down Expand Up @@ -3446,6 +3466,13 @@ export interface CodeAction {
* @since 3.16.0
*/
data?: LSPAny;

/**
* Tags for this code action.
*
* @since 3.18.0 - proposed
*/
tags?: CodeActionTag[];
}

export namespace CodeAction {
Expand Down Expand Up @@ -3499,7 +3526,8 @@ export namespace CodeAction {
(candidate.edit !== undefined || candidate.command !== undefined) &&
(candidate.command === undefined || Command.is(candidate.command)) &&
(candidate.isPreferred === undefined || Is.boolean(candidate.isPreferred)) &&
(candidate.edit === undefined || WorkspaceEdit.is(candidate.edit));
(candidate.edit === undefined || WorkspaceEdit.is(candidate.edit)) &&
(candidate.tags === undefined || Is.typedArray(candidate.tags, CodeActionTag.is));
}
}

Expand Down