[英]How to add a new file to the workspace when developing a new vscode extension?
[英]How to pass Error Details and line number from QuickFix while developing an extension in VSCode?
我正在嘗試開發一個插件,它顯示與特定行相關的問題。
我能夠實施Quick Fix
。 在這里它解析問題並顯示它:
const uri = vscode.Uri.file(path);
const doc = await vscode.workspace.openTextDocument(uri);
//fix ranges to not include whitespace
issues.forEach((issue) => {
codeActions.push({
title: "Uppercase the keyword",
kind: CodeActionKind.QuickFix,
diagnostics: [issue]
});
const line = doc.lineAt(issue.range.start.line);
issue.range = new vscode.Range(
new vscode.Position(line.range.start.line, line.firstNonWhitespaceCharacterIndex),
line.range.end
);
});
collection.set(uri, issues);
缺少 CodeActionProvider:
import * as vscode from 'vscode';
export class ApexCodeActionProvider implements vscode.CodeActionProvider {
public provideCodeActions(
document: vscode.TextDocument,
_range: vscode.Range,
_context: vscode.CodeActionContext,
_token: vscode.CancellationToken
): vscode.ProviderResult<vscode.CodeAction[]> {
const autoFixQuickFix = new vscode.CodeAction('AutoFix QuickFix', vscode.CodeActionKind.QuickFix);
autoFixQuickFix.command = {
title: 'AutoFix QuickFix',
command: 'apex-pmd.fixFile'
};
return [autoFixQuickFix];
}
}
在 extension.ts 中注冊
context.subscriptions.push(
vscode.languages.registerCodeActionsProvider(supportedLanguageCodes, new ApexCodeActionProvider(), {
providedCodeActionKinds: [vscode.CodeActionKind.QuickFix]
})
);
但我無法傳遞錯誤詳細信息和行號? 知道如何通過嗎? 以及如何從文本編輯器編輯或更改文本?
您需要提供一個vscode.CodeActionProvider
。
調用此CodeActionProvider
時會返回vscode.CodeAction
對象的列表。
在CodeAction
中,您設置了vscode.WorkspaceEdit
和/或vscode.Command
。
在WorkspaceEdit
中,您定義要快速修復的刪除/插入/替換。
在Command
中,您可以設置arguments
屬性,您可以在其中放置命令 arguments。 該數組將是命令的參數之一。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.