Skip to content

Commit cb54373

Browse files
authored
Propagate errors from INCAFTER compiler option (#768)
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
1 parent 1530ade commit cb54373

3 files changed

Lines changed: 62 additions & 17 deletions

File tree

packages/language/src/validation/pp-validator.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { LSPIS001_standalone_skip_directive_not_supported } from "./language-ser
2222
import { DeprecateIncludes } from "./compiler/IBM2444Iff-deprecate";
2323
import { typeCheck } from "./type-check-validator";
2424
import { CompilationUnit } from "../workspace/compilation-unit";
25-
import { IncludeDirective } from "../syntax-tree/ast";
25+
import { IncludeDirective, IncludeItem } from "../syntax-tree/ast";
2626
import { DiagnosticCategory } from "./diagnostics-store";
2727
import { Severity } from "../language-server/types";
2828

@@ -48,20 +48,31 @@ function PropagateIncludeErrors(
4848
compilationUnit: CompilationUnit,
4949
): void {
5050
for (const item of includeDirective.items.filter((i) => i.filePath)) {
51-
const errors = [
52-
DiagnosticCategory.Lexer,
53-
DiagnosticCategory.Parser,
54-
DiagnosticCategory.CompilerOptions,
55-
].flatMap((category) =>
56-
compilationUnit.diagnostics.getByUri(category, item.filePath!),
57-
);
58-
if (errors.length > 0) {
59-
acceptor({
60-
uri: item.token?.uri?.toString(),
61-
range: item.range ?? undefined,
62-
message: `Included file '${item.relativeFilePath}' contains ${errors.length} errors.`,
63-
severity: Severity.E,
64-
});
65-
}
51+
PropagateIncludeItemErrors(item, acceptor, compilationUnit);
52+
}
53+
}
54+
55+
export function PropagateIncludeItemErrors(
56+
item: IncludeItem,
57+
acceptor: ValidationAcceptor,
58+
compilationUnit: CompilationUnit,
59+
): void {
60+
const errors = [
61+
DiagnosticCategory.Lexer,
62+
DiagnosticCategory.Parser,
63+
DiagnosticCategory.CompilerOptions,
64+
].flatMap((category) =>
65+
compilationUnit.diagnostics.getByUri(category, item.filePath!),
66+
);
67+
if (errors.length > 0 && item.token) {
68+
acceptor({
69+
uri: item.token.uri?.toString(),
70+
range: item.range ?? {
71+
start: item.token.startOffset,
72+
end: item.token.endOffset + 1,
73+
},
74+
message: `Included file '${item.relativeFilePath}' contains ${errors.length} errors.`,
75+
severity: Severity.E,
76+
});
6677
}
6778
}

packages/language/src/validation/validator.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import { forEachNode } from "../syntax-tree/ast-iterator";
1818
import { registerPliValidationChecks } from "./pli-validator";
1919
import { ScopeCache, ScopeCacheGroups } from "../linking/scope";
2020
import { LinkerErrorReporter } from "../linking/error";
21-
import { registerPreprocessorValidationChecks } from "./pp-validator";
21+
import {
22+
PropagateIncludeItemErrors,
23+
registerPreprocessorValidationChecks,
24+
} from "./pp-validator";
2225
import { DiagnosticCategory } from "./diagnostics-store";
2326

2427
/**
@@ -46,6 +49,12 @@ export function generatePreprocessorValidationDiagnostics(
4649
unit: CompilationUnit,
4750
): void {
4851
const acceptor = unit.diagnostics.getAcceptor(DiagnosticCategory.Validation);
52+
if (unit.compilerOptions.incAfter?.token) {
53+
const item = unit.compilerOptions.incAfter.token.element;
54+
if (item && item.kind === SyntaxKind.IncludeItemFile) {
55+
PropagateIncludeItemErrors(item, acceptor, unit);
56+
}
57+
}
4958
validateSyntaxNode(unit, unit.preprocessorAst, acceptor, ppValidations);
5059
}
5160

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*
10+
*/
11+
12+
/// <reference path="../../framework.ts" />
13+
14+
// @filename: cpy/lib.pli
15+
//// WRONG WRONG WRONG!!
16+
17+
// @filename: main.pli
18+
////*PROCESS <|1:INCAFTER(PROCESS(lib))|>;
19+
20+
verify.expectDiagnosticsAt(1, [
21+
{
22+
severity: 2,
23+
message: "Included file './cpy/lib.pli' contains 3 errors.",
24+
},
25+
]);

0 commit comments

Comments
 (0)