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 2 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
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
1 change: 1 addition & 0 deletions client/src/common/codeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class CodeActionFeature extends TextDocumentLanguageFeature<boolean | Cod
cap.isPreferredSupport = true;
cap.disabledSupport = true;
cap.dataSupport = true;
cap.llmGeneratedSupport = true;
// We can only resolve the edit property.
cap.resolveSupport = {
properties: ['edit', 'command']
Expand Down
2 changes: 2 additions & 0 deletions client/src/common/codeConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ 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 !== undefined) { result.llmGenerated = item.isAI; }
return result;
}

Expand All @@ -756,6 +757,7 @@ 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 !== undefined) { result.llmGenerated = item.isAI; }
return result;
}

Expand Down
1 change: 1 addition & 0 deletions client/src/common/protocolConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ 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.llmGenerated !== undefined) { result.isAI = item.llmGenerated; }
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;
}
}
22 changes: 22 additions & 0 deletions protocol/metaModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -5812,6 +5812,17 @@
"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": "llmGenerated",
"type": {
"kind": "base",
"name": "boolean"
},
"optional": true,
"documentation": "A boolean flag indicating whether the code action is generated by an LLM.\n\nThis property helps distinguish between code actions suggested by an AI model and those generated by static analysis.\n\n@since 3.18.0 - proposed",
"since": "3.17.0",
"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 @@ -12681,6 +12692,17 @@
"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": "llmGeneratedSupport",
"type": {
"kind": "base",
"name": "boolean"
},
"optional": true,
"documentation": "Whether code action supports the `llmGenerated` property.\n\n@since 3.18.0 - proposed",
"since": "3.17.0",
"proposed": true
}
],
"documentation": "The Client Capabilities of a {@link CodeActionRequest}."
Expand Down
7 changes: 7 additions & 0 deletions protocol/src/common/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3300,6 +3300,13 @@ export interface CodeActionClientCapabilities {
* @proposed
*/
documentationSupport?: boolean;

/**
* Whether code action supports the `llmGenerated` property.
*
* @since 3.17.0 - proposed
*/
llmGeneratedSupport?: boolean;
}

/**
Expand Down
14 changes: 13 additions & 1 deletion types/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3446,6 +3446,17 @@ export interface CodeAction {
* @since 3.16.0
*/
data?: LSPAny;

/**
* A boolean flag indicating whether the code action is generated by an
* LLM.
*
* This property helps distinguish between code actions suggested by an AI
* model and those generated by static analysis.
*
* @since 3.17.0 - proposed
StellaHuang95 marked this conversation as resolved.
Show resolved Hide resolved
*/
llmGenerated?: boolean;
}

export namespace CodeAction {
Expand Down Expand Up @@ -3499,7 +3510,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.llmGenerated === undefined || Is.boolean(candidate.llmGenerated));
}
}

Expand Down