Skip to content

Commit

Permalink
Add setting to disable vmt texture path validation
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanH-AT committed Jun 14, 2024
1 parent 9e03ccb commit 0f4dddb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@
"type": "boolean",
"default": true,
"description": "Whether to put { on a newline after the key"
},
"sourceEngine.vmt.validateTexturePaths": {
"type": "boolean",
"default": true,
"description": "Warn when the file of a texture property can't be found"
}
}
},
Expand Down
14 changes: 9 additions & 5 deletions src/language/VmtSemanticTokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Token, isFloatValue, isScalarValue } from "@sourcelib/kv";
import { shaderParams, internalTextures } from "@sourcelib/vmt";
import { KvSemanticProcessor, KvSemanticProcessorParams } from "./KvSemanticProcessor";
import { KvPair } from "../Kv";
import * as main from "../main";
import fs from "fs";
import path from "path";

Expand Down Expand Up @@ -113,11 +114,14 @@ export class VmtSemanticTokenProvider extends KvTokensProviderBase {
tokensBuilder.push(range, "keyword");
return;
}
const materialDir = getParentDocumentDirectory(kvDoc.document.uri.fsPath, "materials");
if (materialDir != null) {
const materialPath: string = path.join(materialDir, kv.value.content + ".vtf");
if (!fs.existsSync(materialPath)) {
this.diagnostics.push(new vscode.Diagnostic(range, "Texture not found on disk", vscode.DiagnosticSeverity.Warning));
const validationEnabled = main.config.get<boolean>("vmt.validateTexturePaths");
if(validationEnabled) {
const materialDir = getParentDocumentDirectory(kvDoc.document.uri.fsPath, "materials");
if (materialDir != null) {
const materialPath: string = path.join(materialDir, kv.value.content + ".vtf");
if (!fs.existsSync(materialPath)) {
this.diagnostics.push(new vscode.Diagnostic(range, "Texture not found on disk", vscode.DiagnosticSeverity.Warning));
}
}
}

Expand Down

0 comments on commit 0f4dddb

Please sign in to comment.