Skip to content

Commit d6b5bbc

Browse files
committed
feat: ensure filepath validation accounts for image paths with trailing frame numbers
1 parent c09b4ff commit d6b5bbc

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

packages/server/src/sampleServer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
7070

7171
if (configService.hasWorkspaceFolderCapability && params.workspaceFolders) {
7272
fileSystemService.registerWorkspaces(params.workspaceFolders);
73-
fileSystemService.moduleFileList.forEach((file) => {
74-
connection.console.log(file);
75-
});
73+
// fileSystemService.moduleFileList.forEach((file) => {
74+
// connection.console.log(file);
75+
// });
7676
}
7777

7878
if (configService.hasWorkspaceFolderCapability) {

packages/server/src/validations/validateFilePath.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { normalize } from 'path';
1+
import { extname, normalize } from 'path';
22
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver';
33
import { TextDocument } from 'vscode-languageserver-textdocument';
44
import { configService } from '../services/configuration.service';
55
import { fileSystemService } from '../services/fs.service';
6+
import { imageFileExtensions } from 'shared';
67

78
export function validateFilePaths(textDocument: TextDocument): Diagnostic[] {
89
// In this simple example we get the settings for every validate run.
@@ -22,7 +23,7 @@ export function validateFilePaths(textDocument: TextDocument): Diagnostic[] {
2223
problems < configService.globalSettings.maxNumberOfProblems
2324
) {
2425
const normalizedPath = normalize(m[2]);
25-
if (!fileSystemService.moduleFileList.includes(normalizedPath)) {
26+
if (!checkIfPathExists(normalizedPath)) {
2627
problems++;
2728
const diagnostic: Diagnostic = {
2829
severity: DiagnosticSeverity.Error,
@@ -52,3 +53,22 @@ export function validateFilePaths(textDocument: TextDocument): Diagnostic[] {
5253
// Send the computed diagnostics to VSCode.
5354
return diagnostics;
5455
}
56+
57+
function checkIfPathExists(filePath: string): boolean {
58+
if (fileSystemService.moduleFileList.includes(filePath)) {
59+
return true;
60+
}
61+
62+
if (imageFileExtensions.includes(extname(filePath))) {
63+
const index = filePath.lastIndexOf('.');
64+
if (index < 0) {
65+
return false;
66+
}
67+
68+
filePath = filePath.substring(0, index) + '000' + filePath.substring(index);
69+
70+
return fileSystemService.moduleFileList.includes(filePath);
71+
}
72+
73+
return false;
74+
}

0 commit comments

Comments
 (0)