Skip to content

Commit 183974d

Browse files
committed
fix: stop file path validation firing on commented out lines
Allow top-level string assignments (eg single `IncludeFile` calls)
1 parent d6b5bbc commit 183974d

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

packages/server/src/validations/validateFilePath.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ export function validateFilePaths(textDocument: TextDocument): Diagnostic[] {
1111

1212
// The validator creates diagnostics for all uppercase words length 2 and more
1313
const text = textDocument.getText();
14+
1415
const pattern =
15-
/(\t*(?:ScriptPath|IncludeFile|LogoFile|FilePath|SkinFile)\s*=\s*)(.*)/dg;
16+
/(?:\/\*.*?(?=\*\/))|(\t*(?:ScriptPath|IncludeFile|LogoFile|FilePath|SkinFile)\s*=\s*)(.*?)(?=(?:$|\/\/|\/\*|(?:\s+(?:\/\/.*|\/\*.*))))/dgms;
17+
18+
const commentPattern = /(\/\/[^\n]*\n)|(\/\*.*?\*\/)/dgms;
19+
const commentRanges = text.matchAll(commentPattern);
20+
1621
let m: RegExpExecArray | null;
1722

1823
let problems = 0;
@@ -22,8 +27,21 @@ export function validateFilePaths(textDocument: TextDocument): Diagnostic[] {
2227
(m = pattern.exec(text)) &&
2328
problems < configService.globalSettings.maxNumberOfProblems
2429
) {
25-
const normalizedPath = normalize(m[2]);
26-
if (!checkIfPathExists(normalizedPath)) {
30+
let skip = false;
31+
for (const comment of commentRanges) {
32+
if (!(comment.index && comment.length)) {
33+
continue;
34+
}
35+
skip =
36+
(comment.index < m.index && comment.index + comment.length > m.index) ||
37+
(comment.index > m.index && comment.index < m.index + m.length);
38+
}
39+
40+
if (skip) {
41+
continue;
42+
}
43+
const normalizedPath = m[2] ? normalize(m[2].trim()) : null;
44+
if (normalizedPath && !checkIfPathExists(normalizedPath)) {
2745
problems++;
2846
const diagnostic: Diagnostic = {
2947
severity: DiagnosticSeverity.Error,

packages/syntaxes/src/ccini.tmLanguage.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ repository:
4040
patterns:
4141
- { include: '#comments' }
4242
- { include: '#classNames' }
43+
- { include: '#strings' }
4344

4445
patterns:
4546
- { include: '#comments' }

0 commit comments

Comments
 (0)