@@ -94,7 +94,7 @@ export function preprocess(lines: string[], docURI: string) {
9494 allIncludes . forEach ( inc => allFiles . add ( inc . path ) )
9595
9696 const includeMap = new Map < string , IncludeObj > ( allIncludes . map ( obj => [ obj . path , obj ] ) as [ string , IncludeObj ] [ ] )
97-
97+
9898 lint ( docURI , lines , includeMap , diagnostics )
9999}
100100
@@ -159,7 +159,8 @@ export function getIncludes(uri: string, lines: string[]) {
159159}
160160
161161function ifInvalidFile ( inc : IncludeObj , lines : string [ ] , incStack : string [ ] , diagnostics : Map < string , Diagnostic [ ] > ) {
162- const range = calcRange ( inc . lineNumTopLevel - ( win ? 1 : 0 ) , incStack [ 0 ] )
162+ const file = incStack [ incStack . length - 1 ]
163+ const range = calcRange ( inc . lineNum - ( win ? 1 : 0 ) , file )
163164 diagnostics . set (
164165 inc . parent ,
165166 [
@@ -173,6 +174,8 @@ function ifInvalidFile(inc: IncludeObj, lines: string[], incStack: string[], dia
173174 ]
174175 )
175176 lines [ inc . lineNumTopLevel ] = ''
177+ // TODO fill in the actual data
178+ propogateDiagnostic ( file , 'ERROR' , inc . lineNum . toString ( ) , `${ inc . path . replace ( conf . shaderpacksPath , '' ) } is missing or an invalid file.` , diagnostics , null )
176179}
177180
178181function mergeInclude ( inc : IncludeObj , lines : string [ ] , incStack : string [ ] , diagnostics : Map < string , Diagnostic [ ] > , hasDirective : boolean ) {
@@ -210,16 +213,16 @@ function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diag
210213 lines . splice ( inc . lineNumTopLevel + 1 + dataLines . length , 0 , `#line ${ inc . lineNum + 1 } "${ inc . parent } "` )
211214}
212215
213- function lint ( uri : string , lines : string [ ] , includes : Map < string , IncludeObj > , diagnostics : Map < string , Diagnostic [ ] > ) {
216+ function lint ( docURI : string , lines : string [ ] , includes : Map < string , IncludeObj > , diagnostics : Map < string , Diagnostic [ ] > ) {
214217 console . log ( lines . join ( '\n' ) )
215218 let out : string = ''
216219 try {
217- execSync ( `${ conf . glslangPath } --stdin -S ${ ext . get ( path . extname ( uri ) ) } ` , { input : lines . join ( '\n' ) } )
220+ execSync ( `${ conf . glslangPath } --stdin -S ${ ext . get ( path . extname ( docURI ) ) } ` , { input : lines . join ( '\n' ) } )
218221 } catch ( e ) {
219222 out = e . stdout . toString ( )
220223 }
221224
222- if ( ! diagnostics . has ( uri ) ) diagnostics . set ( uri , [ ] )
225+ if ( ! diagnostics . has ( docURI ) ) diagnostics . set ( docURI , [ ] )
223226 includes . forEach ( obj => {
224227 if ( ! diagnostics . has ( obj . path ) ) diagnostics . set ( obj . path , [ ] )
225228 } )
@@ -229,28 +232,15 @@ function lint(uri: string, lines: string[], includes: Map<string, IncludeObj>, d
229232 let diag : Diagnostic = {
230233 severity : errorType ( type ) ,
231234 // had to do - 2 here instead of - 1, windows only perhaps?
232- range : calcRange ( parseInt ( line ) - ( win ? 2 : 1 ) , file . length - 1 ? file : uri ) ,
235+ range : calcRange ( parseInt ( line ) - ( win ? 2 : 1 ) , file . length - 1 ? file : docURI ) ,
233236 message : `Line ${ line } ${ replaceWords ( msg ) } ` ,
234237 source : 'mc-glsl'
235238 }
236239
237- diagnostics . get ( file . length - 1 ? file : uri ) . push ( diag )
240+ diagnostics . get ( file . length - 1 ? file : docURI ) . push ( diag )
238241
239242 // if is an include, highlight an error in the parents line of inclusion
240- let nextFile = file
241- while ( nextFile !== '0' && nextFile !== uri ) {
242- // TODO what if we dont know the top level parent? Feel like thats a non-issue given that we have uri
243- diag = {
244- severity : errorType ( type ) ,
245- range : calcRange ( includes . get ( nextFile ) . lineNum , includes . get ( nextFile ) . parent ) ,
246- message : `Line ${ line } ${ includes . get ( file ) . path . replace ( conf . shaderpacksPath , '' ) } ${ replaceWords ( msg ) } ` ,
247- source : 'mc-glsl'
248- }
249-
250- diagnostics . get ( includes . get ( nextFile ) . parent ) . push ( diag )
251-
252- nextFile = includes . get ( nextFile ) . parent
253- }
243+ propogateDiagnostic ( file , type , line , msg , diagnostics , includes )
254244 } )
255245
256246 daigsArray ( diagnostics ) . forEach ( d => {
@@ -259,6 +249,23 @@ function lint(uri: string, lines: string[], includes: Map<string, IncludeObj>, d
259249 } )
260250}
261251
252+ function propogateDiagnostic ( errorFile : string , type : string , line : string , msg : string , diagnostics : Map < string , Diagnostic [ ] > , includes : Map < string , IncludeObj > ) {
253+ let nextFile = errorFile
254+ while ( nextFile !== '0' ) {
255+ // TODO this doesnt deal with the fact that an include can have multiple parents :(
256+ const diag = {
257+ severity : errorType ( type ) ,
258+ range : calcRange ( includes . get ( nextFile ) . lineNum , includes . get ( nextFile ) . parent ) ,
259+ message : `Line ${ line } ${ includes . get ( errorFile ) . path . replace ( conf . shaderpacksPath , '' ) } ${ replaceWords ( msg ) } ` ,
260+ source : 'mc-glsl'
261+ }
262+
263+ diagnostics . get ( includes . get ( nextFile ) . parent ) . push ( diag )
264+
265+ nextFile = includes . get ( nextFile ) . parent
266+ }
267+ }
268+
262269export const replaceWords = ( msg : string ) => Array . from ( tokens . entries ( ) ) . reduce ( ( acc , [ key , value ] ) => acc . replace ( key , value ) , msg )
263270
264271const errorType = ( error : string ) => error === 'ERROR' ? DiagnosticSeverity . Error : DiagnosticSeverity . Warning
0 commit comments