Skip to content

Commit fa9be15

Browse files
committed
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
1 parent f6750a6 commit fa9be15

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

languageservice/src/validate-action-reference.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export interface MissingInputsDiagnosticData {
2222
// Indentation of the `with:` key if present, or the step's base indentation
2323
withIndent?: number;
2424
stepIndent: number;
25+
// Indentation size (spaces per level)
26+
indentSize: number;
2527
// Position where new content should be inserted
2628
insertPosition: {line: number; character: number};
2729
}
@@ -33,7 +35,8 @@ export async function validateActionReference(
3335
diagnostics: Diagnostic[],
3436
stepToken: TemplateToken,
3537
step: Step | undefined,
36-
config: ValidationConfig | undefined
38+
config: ValidationConfig | undefined,
39+
indentSize: number = 2
3740
): Promise<void> {
3841
if (!isMapping(stepToken) || !step || !isActionStep(step) || !config?.actionsMetadataProvider) {
3942
return;
@@ -116,6 +119,15 @@ export async function validateActionReference(
116119
const stepIndent = stepToken.range ? stepToken.range.start.column - 1 : 0; // 0-indexed
117120
const withIndent = withKey?.range ? withKey.range.start.column - 1 : undefined;
118121

122+
// Calculate actual indentSize from the first child of with: block, or use the provided default
123+
let actualIndentSize = indentSize;
124+
if (withToken && isMapping(withToken) && withToken.count > 0) {
125+
const firstChild = withToken.get(0);
126+
if (firstChild?.key.range && withKey?.range) {
127+
actualIndentSize = firstChild.key.range.start.column - withKey.range.start.column;
128+
}
129+
}
130+
119131
// Calculate insert position
120132
// For withToken, we need to handle empty mappings specially - insert after the with: line
121133
let insertPosition: {line: number; character: number};
@@ -146,6 +158,7 @@ export async function validateActionReference(
146158
hasWithKey: withKey !== undefined,
147159
withIndent,
148160
stepIndent,
161+
indentSize: actualIndentSize,
149162
insertPosition
150163
};
151164

languageservice/src/validate.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {splitAllowedContext} from "@actions/workflow-parser/templates/allowed-co
88
import {BasicExpressionToken} from "@actions/workflow-parser/templates/tokens/basic-expression-token";
99
import {StringToken} from "@actions/workflow-parser/templates/tokens/string-token";
1010
import {TemplateToken} from "@actions/workflow-parser/templates/tokens/template-token";
11+
import {MappingToken} from "@actions/workflow-parser/templates/tokens/mapping-token";
1112
import {TokenRange} from "@actions/workflow-parser/templates/tokens/token-range";
1213
import {File} from "@actions/workflow-parser/workflows/file";
1314
import {FileProvider} from "@actions/workflow-parser/workflows/file-provider";
@@ -169,7 +170,8 @@ async function additionalValidations(
169170
// Validate action metadata (inputs, required fields) for regular steps
170171
if (token.definition?.key === "regular-step" && token.range) {
171172
const context = getProviderContext(documentUri, template, root, token.range);
172-
await validateActionReference(diagnostics, token, context.step, config);
173+
const indentSize = detectIndentSize(root as MappingToken);
174+
await validateActionReference(diagnostics, token, context.step, config, indentSize);
173175
}
174176

175177
// Validate job-level reusable workflow uses field format
@@ -823,4 +825,31 @@ function getStaticConcurrencyGroup(token: TemplateToken | undefined): StringToke
823825
return undefined;
824826
}
825827

828+
/**
829+
* Detects the indentation size used in the workflow file by examining the
830+
* difference between the "jobs" key column and its first child's column.
831+
*/
832+
function detectIndentSize(rootToken: MappingToken): number {
833+
// Find the "jobs" key in the root mapping to get its column position
834+
let jobsKeyColumn: number | undefined;
835+
let jobsValue: TemplateToken | undefined;
836+
837+
for (const {key, value} of rootToken) {
838+
if (key.toString() === "jobs") {
839+
jobsKeyColumn = key.range?.start.column;
840+
jobsValue = value;
841+
break;
842+
}
843+
}
844+
845+
if (jobsKeyColumn !== undefined && jobsValue && isMapping(jobsValue) && jobsValue.count > 0) {
846+
const firstJob = jobsValue.get(0);
847+
if (firstJob?.key.range) {
848+
return firstJob.key.range.start.column - jobsKeyColumn;
849+
}
850+
}
851+
852+
return 2; // fallback
853+
}
854+
826855

0 commit comments

Comments
 (0)