@@ -12,6 +12,8 @@ import { getParentDocumentDirectory } from "../kv-core/source-fs";
12
12
import { config } from "../main" ;
13
13
import { isFloatValue , isScalarValue } from "../kv-core/kv-string-util" ;
14
14
import { getColorMatches , ColorMatchDescription , ColorMatchParenthesisType } from "../kv-core/kv-color" ;
15
+ import { exists , existsSync , fstat } from "fs" ;
16
+ import path from "path" ;
15
17
16
18
export const filterVmtSaved : DocumentFilter = {
17
19
language : "vmt" ,
@@ -135,6 +137,12 @@ export class VmtSemanticTokenProvider extends KvTokensProviderBase {
135
137
tokensBuilder . push ( range , "keyword" ) ;
136
138
return ;
137
139
}
140
+ const materialDir = getParentDocumentDirectory ( kvDoc . document . uri . fsPath , "materials" ) ;
141
+ if ( materialDir != null ) {
142
+ if ( ! existsSync ( path . join ( materialDir , kv . value + ".vtf" ) ) ) {
143
+ this . diagnostics . push ( new Diagnostic ( range , "Texture not found on disk" , DiagnosticSeverity . Warning ) ) ;
144
+ }
145
+ }
138
146
139
147
tokensBuilder . push ( range , "string" ) ;
140
148
}
@@ -217,7 +225,7 @@ export class ShaderParamCompletionItemProvider implements CompletionItemProvider
217
225
}
218
226
219
227
220
- if ( kv . valueRange . contains ( position ) && kv . value === "" ) {
228
+ if ( kv . valueRange . contains ( position ) ) {
221
229
const param = shaderParams . find ( p => p . name == kv . key ) ;
222
230
223
231
const completions = new CompletionList ( ) ;
@@ -256,23 +264,40 @@ export class ShaderParamCompletionItemProvider implements CompletionItemProvider
256
264
completions . items . push ( completion ) ;
257
265
} ) ;
258
266
259
- const materialRoot = getParentDocumentDirectory ( document . uri . path , "material" ) ;
267
+ const materialRoot = getParentDocumentDirectory ( document . uri . fsPath , "materials" ) ;
268
+ if ( materialRoot == null ) return ;
260
269
261
- if ( materialRoot != null ) {
262
-
263
- const textureFiles = listFilesSync ( materialRoot , "vtf" ) ;
264
- textureFiles . forEach ( t => {
265
- const filePath = t . substring ( materialRoot . length + 1 ) ;
266
- const filePathWithoutExtension = filePath . substring ( 0 , filePath . length - 4 ) ;
267
-
268
- const completion = new CompletionItem ( filePath ) ;
269
- completion . insertText = filePathWithoutExtension ;
270
- completion . detail = "Texture Path" ;
271
- completion . kind = CompletionItemKind . File ;
272
- completion . preselect = true ;
273
- completions . items . push ( completion ) ;
274
- } ) ;
270
+ // Exit early if file already exists
271
+ if ( existsSync ( path . join ( materialRoot , kv . value + ".vtf" ) ) ) {
272
+ return ;
273
+ }
274
+
275
+ let cursorStartDir ;
276
+ if ( kv . value . endsWith ( "\\" ) || kv . value . endsWith ( "/" ) ) {
277
+ cursorStartDir = kv . value ;
278
+ } else {
279
+ cursorStartDir = path . dirname ( kv . value ) ;
275
280
}
281
+ const startDir = path . join ( materialRoot , cursorStartDir ) ;
282
+
283
+ if ( ! existsSync ( startDir ) ) return ;
284
+
285
+ const textureFiles = listFilesSync ( startDir , "vtf" ) ;
286
+ textureFiles . forEach ( t => {
287
+ let filePath = t . substring ( startDir . length ) ;
288
+ if ( filePath . startsWith ( "\\" ) || filePath . startsWith ( "/" ) ) {
289
+ filePath = filePath . slice ( 1 ) ;
290
+ }
291
+ const filePathWithoutExtension = filePath . substring ( 0 , filePath . length - 4 ) . replace ( "\\" , "/" ) ;
292
+
293
+ const completion = new CompletionItem ( filePathWithoutExtension ) ;
294
+ completion . insertText = filePathWithoutExtension ;
295
+ completion . detail = "Texture Path" ;
296
+ completion . kind = CompletionItemKind . File ;
297
+ completion . preselect = true ;
298
+ completions . items . push ( completion ) ;
299
+ } ) ;
300
+
276
301
}
277
302
}
278
303
0 commit comments