feat: update tag workflow
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import * as vscode from "vscode";
|
||||
import { isTaskFileName, TASK_LANGUAGE_ID } from "@/model/taskFile";
|
||||
import { parseUnknownTagFromDiagnosticCode } from "./taskDiagnostics";
|
||||
|
||||
/**
|
||||
* Quick Fix on unknown-tag warnings: «Add tag "…" to project».
|
||||
*/
|
||||
export class TaskCodeActionProvider implements vscode.CodeActionProvider {
|
||||
static readonly providedCodeActionKinds = [vscode.CodeActionKind.QuickFix];
|
||||
|
||||
provideCodeActions(
|
||||
document: vscode.TextDocument,
|
||||
_range: vscode.Range | vscode.Selection,
|
||||
context: vscode.CodeActionContext,
|
||||
): vscode.CodeAction[] {
|
||||
if (
|
||||
document.languageId !== TASK_LANGUAGE_ID &&
|
||||
!isTaskFileName(document.fileName)
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const actions: vscode.CodeAction[] = [];
|
||||
const uri = document.uri.toString();
|
||||
|
||||
for (const diagnostic of context.diagnostics) {
|
||||
if (diagnostic.source !== "xboctuk-flow") continue;
|
||||
const tag = parseUnknownTagFromDiagnosticCode(diagnostic.code);
|
||||
if (!tag) continue;
|
||||
|
||||
const action = new vscode.CodeAction(
|
||||
`Add tag "${tag}" to project`,
|
||||
vscode.CodeActionKind.QuickFix,
|
||||
);
|
||||
action.diagnostics = [diagnostic];
|
||||
action.isPreferred = true;
|
||||
action.command = {
|
||||
command: "xboctukFlow.addTagToProject",
|
||||
title: `Add tag "${tag}" to project`,
|
||||
arguments: [uri, tag],
|
||||
};
|
||||
actions.push(action);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
}
|
||||
|
||||
export function registerTaskCodeActions(
|
||||
context: vscode.ExtensionContext,
|
||||
): void {
|
||||
const selector: vscode.DocumentSelector = [
|
||||
{ language: TASK_LANGUAGE_ID },
|
||||
{ pattern: "**/*.xflow.md" },
|
||||
];
|
||||
context.subscriptions.push(
|
||||
vscode.languages.registerCodeActionsProvider(
|
||||
selector,
|
||||
new TaskCodeActionProvider(),
|
||||
{
|
||||
providedCodeActionKinds:
|
||||
TaskCodeActionProvider.providedCodeActionKinds,
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user