0fe31c6656
* Setup CodeActions and add quickfix for missing inputs * PR feedback * Update languageservice/src/code-actions/quickfix/add-missing-inputs.ts Co-authored-by: Salman Chishti <salmanmkc@GitHub.com> * Fix indentSize detection for code actions after rebase - Add indentSize to MissingInputsDiagnosticData interface - Pass indentSize parameter from validate.ts to validateActionReference - Detect indentSize from workflow structure (jobs key to first child) - Fall back to detecting from with: block children when available * update typescript * formatting * linting * Gate missing inputs quickfix behind feature flag * Address PR review: rename files, move position calculation to quickfix - Rename index.ts files to follow repo patterns: - code-actions/index.ts → code-actions/code-actions.ts - code-actions/quickfix/index.ts → quickfix/quickfix-providers.ts - Move position calculation from validation to quickfix: - MissingInputsDiagnosticData now passes raw token ranges - Quickfix computes insertion position and indentation at code action time - detectIndentSize moved from validate.ts to validate-action-reference.ts * wip * Remove pointless comment --------- Co-authored-by: Salman Chishti <salmanmkc@GitHub.com>
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import {FeatureFlags} from "@actions/expressions";
|
|
import {CodeAction, CodeActionKind, Diagnostic} from "vscode-languageserver-types";
|
|
import {CodeActionContext, CodeActionProvider} from "./types.js";
|
|
import {getQuickfixProviders} from "./quickfix/quickfix-providers.js";
|
|
|
|
export interface CodeActionParams {
|
|
uri: string;
|
|
documentContent: string;
|
|
diagnostics: Diagnostic[];
|
|
only?: string[];
|
|
featureFlags?: FeatureFlags;
|
|
}
|
|
|
|
export function getCodeActions(params: CodeActionParams): CodeAction[] {
|
|
const actions: CodeAction[] = [];
|
|
const context: CodeActionContext = {
|
|
uri: params.uri,
|
|
documentContent: params.documentContent,
|
|
featureFlags: params.featureFlags
|
|
};
|
|
|
|
// Build providers map based on feature flags
|
|
const providersByKind: Map<string, CodeActionProvider[]> = new Map([
|
|
[CodeActionKind.QuickFix, getQuickfixProviders(params.featureFlags)]
|
|
// [CodeActionKind.Refactor, getRefactorProviders(params.featureFlags)],
|
|
// [CodeActionKind.Source, getSourceProviders(params.featureFlags)],
|
|
// etc
|
|
]);
|
|
|
|
// Filter to requested kinds, or use all if none specified
|
|
const requestedKinds = params.only;
|
|
const kindsToCheck = requestedKinds
|
|
? [...providersByKind.keys()].filter(kind => requestedKinds.some(requested => kind.startsWith(requested)))
|
|
: [...providersByKind.keys()];
|
|
|
|
for (const diagnostic of params.diagnostics) {
|
|
for (const kind of kindsToCheck) {
|
|
const providers = providersByKind.get(kind) ?? [];
|
|
for (const provider of providers) {
|
|
if (provider.diagnosticCodes.includes(diagnostic.code)) {
|
|
const action = provider.createCodeAction(context, diagnostic);
|
|
if (action) {
|
|
action.kind = kind;
|
|
action.diagnostics = [diagnostic];
|
|
actions.push(action);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return actions;
|
|
}
|
|
|
|
export type {CodeActionContext, CodeActionProvider} from "./types.js";
|