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 all 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
6 changes: 5 additions & 1 deletion client/src/common/codeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
} from 'vscode';

import {
ClientCapabilities, CancellationToken, ServerCapabilities, DocumentSelector, CodeActionRequest, CodeActionOptions, CodeActionRegistrationOptions, CodeActionParams, CodeActionResolveRequest, CodeActionKind
ClientCapabilities, CancellationToken, ServerCapabilities, DocumentSelector, CodeActionRequest, CodeActionOptions, CodeActionRegistrationOptions, CodeActionParams, CodeActionResolveRequest, CodeActionKind,
CodeActionTag
} from 'vscode-languageserver-protocol';

import * as UUID from './utils/uuid';
Expand Down Expand Up @@ -63,6 +64,9 @@ export class CodeActionFeature extends TextDocumentLanguageFeature<boolean | Cod
};
cap.honorsChangeAnnotations = true;
cap.documentationSupport = true;
cap.tagSupport = {
valueSet: [CodeActionTag.LLMGenerated]
};
}

public initialize(capabilities: ServerCapabilities, documentSelector: DocumentSelector): void {
Expand Down
9 changes: 9 additions & 0 deletions client/src/common/codeConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* 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" />

import * as code from 'vscode';
import * as proto from 'vscode-languageserver-protocol';
Expand Down Expand Up @@ -742,6 +743,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 +761,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
5 changes: 5 additions & 0 deletions client/src/common/protocolConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* 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" />

import * as code from 'vscode';
import * as ls from 'vscode-languageserver-protocol';
Expand Down Expand Up @@ -1020,6 +1021,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;
}
}
57 changes: 57 additions & 0 deletions protocol/metaModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -5812,6 +5812,19 @@
"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"
}
],
"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 @@ -12681,6 +12694,16 @@
"documentation": "Whether the client supports documentation for a class of\ncode actions.\n\n@since 3.18.0\n@proposed",
"since": "3.18.0",
"proposed": true
},
{
"name": "tagSupport",
"type": {
"kind": "reference",
"name": "CodeActionTagOptions"
},
"optional": true,
"documentation": "Client supports the tag property on a code action. Clients\nsupporting tags have to handle unknown tags gracefully.\n\n@since 3.18.0 - proposed",
"since": "3.18.0 - proposed"
}
],
"documentation": "The Client Capabilities of a {@link CodeActionRequest}."
Expand Down Expand Up @@ -13624,6 +13647,24 @@
"documentation": "@since 3.18.0",
"since": "3.18.0"
},
{
"name": "CodeActionTagOptions",
"properties": [
{
"name": "valueSet",
"type": {
"kind": "array",
"element": {
"kind": "reference",
"name": "CodeActionTag"
}
},
"documentation": "The tags supported by the client."
}
],
"documentation": "@since 3.18.0 - proposed",
"since": "3.18.0 - proposed"
},
{
"name": "ClientCodeLensResolveOptions",
"properties": [
Expand Down Expand Up @@ -14772,6 +14813,22 @@
"supportsCustomValues": true,
"documentation": "A set of predefined code action kinds"
},
{
"name": "CodeActionTag",
"type": {
"kind": "base",
"name": "uinteger"
},
"values": [
{
"name": "LLMGenerated",
"value": 1,
"documentation": "Marks the code action as LLM-generated."
}
],
"documentation": "Code action tags are extra annotations that tweak the behavior of a code action.\n\n@since 3.18.0 - proposed",
"since": "3.18.0 - proposed"
},
{
"name": "TraceValue",
"type": {
Expand Down
21 changes: 20 additions & 1 deletion protocol/src/common/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
Hover, SignatureHelp, Definition, DefinitionLink, ReferenceContext, DocumentHighlight, SymbolInformation,
CodeLens, CodeActionContext, FormattingOptions, DocumentLink, MarkupKind, SymbolKind, CompletionItemKind,
CodeAction, CodeActionKind, DocumentSymbol, CompletionItemTag, DiagnosticTag, SymbolTag, uinteger, integer,
InsertTextMode, LSPAny, WorkspaceSymbol, URI, WorkspaceFolder
InsertTextMode, LSPAny, WorkspaceSymbol, URI, WorkspaceFolder,
CodeActionTag
} from 'vscode-languageserver-types';

import * as Is from './utils/is';
Expand Down Expand Up @@ -3300,8 +3301,26 @@ export interface CodeActionClientCapabilities {
* @proposed
*/
documentationSupport?: boolean;

/**
* Client supports the tag property on a code action. Clients
* supporting tags have to handle unknown tags gracefully.
*
* @since 3.18.0 - proposed
*/
tagSupport?: CodeActionTagOptions;
}

/**
* @since 3.18.0 - proposed
*/
export type CodeActionTagOptions = {
/**
* The tags supported by the client.
*/
valueSet: CodeActionTag[];
};

/**
* The parameters of a {@link CodeActionRequest}.
*/
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 behavior of a code action.
*
* @since 3.18.0 - proposed
*/
export namespace CodeActionTag {
/**
* Marks the code action as LLM-generated.
*/
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