-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
import * as vscode from "vscode"; | ||
|
||
export class AutoDevCodeActionProvider implements vscode.CodeActionProvider { | ||
provideCodeActions( | ||
document: vscode.TextDocument, | ||
range: vscode.Range | vscode.Selection, | ||
context: vscode.CodeActionContext, | ||
token: vscode.CancellationToken | ||
): vscode.ProviderResult<(vscode.CodeAction | vscode.Command)[]> { | ||
throw new Error("Method not implemented."); | ||
} | ||
export class AutoDocumentationCodeActionProvider | ||
implements vscode.CodeActionProvider | ||
{ | ||
provideCodeActions( | ||
document: vscode.TextDocument, | ||
range: vscode.Range | vscode.Selection, | ||
context: vscode.CodeActionContext, | ||
token: vscode.CancellationToken | ||
): vscode.ProviderResult<vscode.CodeAction[]> { | ||
// 获取用户选择的代码范围 | ||
const selectedCode = document.getText(range); | ||
|
||
resolveCodeAction?( | ||
codeAction: vscode.CodeAction, | ||
token: vscode.CancellationToken | ||
): vscode.ProviderResult<vscode.CodeAction> { | ||
throw new Error("Method not implemented."); | ||
} | ||
// 分析选中的代码,生成文档注释 | ||
const documentation = this.generateDocumentation(selectedCode); | ||
|
||
// 创建修复建议 | ||
const codeAction = new vscode.CodeAction( | ||
"Generate Documentation", | ||
vscode.CodeActionKind.QuickFix | ||
); | ||
codeAction.edit = new vscode.WorkspaceEdit(); | ||
codeAction.edit.insert(document.uri, range.end, "\n\n" + documentation); // 在代码后面插入生成的文档注释 | ||
|
||
return [codeAction]; | ||
} | ||
|
||
private generateDocumentation(code: string): string { | ||
// 实现根据选中的代码生成文档注释的逻辑 | ||
// 这里是一个示例,您可能需要根据您的语言和需求进行修改 | ||
// 例如,您可以使用代码解析工具来分析代码结构并生成相应的文档注释 | ||
return `/** | ||
* This function/method does something. | ||
* @param {string} param1 Description of parameter 1. | ||
* @returns {number} Description of the return value. | ||
*/`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters