@@ -22,11 +22,6 @@ const errorFilters = [
2222 / ( N o c o d e g e n e r a t e d ) / ,
2323 / ( c o m p i l a t i o n t e r m i n a t e d ) / ,
2424 / C o u l d n o t p r o c e s s i n c l u d e d i r e c t i v e f o r h e a d e r n a m e : / ,
25- / g l o b a l c o n s t i n i t i a l i z e r s m u s t b e c o n s t a n t / ,
26- ]
27-
28- const codeFilters = [
29- / # e x t e n s i o n G L _ E X T _ g p u _ s h a d e r 4 : r e q u i r e / ,
3025]
3126
3227export const includeGraph = new Graph ( )
@@ -154,10 +149,10 @@ function processIncludes(lines: string[], incStack: string[], allIncludes: Set<I
154149
155150function getIncludes ( uri : string , lines : string [ ] ) {
156151 const lineInfo : LinesProcessingInfo = {
157- total : - 1 ,
152+ total : 0 ,
158153 comment : Comment . State . No ,
159154 parStack : [ uri ] ,
160- count : [ - 1 ] ,
155+ count : [ 0 ] ,
161156 }
162157
163158 return lines . reduce < Map < string , IncludeObj > > ( ( out , line , i ) => processLine ( out , line , lines , i , lineInfo ) , new Map ( ) )
@@ -180,11 +175,12 @@ function processLine(includes: Map<string, IncludeObj>, line: string, lines: str
180175
181176 if ( line . startsWith ( '#line' ) ) {
182177 const inc = line . slice ( line . indexOf ( '"' ) + 1 , line . lastIndexOf ( '"' ) )
178+ if ( inc . length + 1 === line . length ) lines [ i ] = ''
183179 if ( inc === linesInfo . parStack [ linesInfo . parStack . length - 2 ] ) {
184180 linesInfo . count . pop ( )
185181 linesInfo . parStack . pop ( )
186182 } else {
187- linesInfo . count . push ( - 1 )
183+ linesInfo . count . push ( 0 )
188184 linesInfo . parStack . push ( inc )
189185 }
190186 return includes
@@ -197,8 +193,8 @@ function processLine(includes: Map<string, IncludeObj>, line: string, lines: str
197193 formatURI ( absPath ( linesInfo . parStack [ linesInfo . parStack . length - 1 ] , match [ 1 ] ) ) ,
198194 {
199195 path : formatURI ( absPath ( linesInfo . parStack [ linesInfo . parStack . length - 1 ] , match [ 1 ] ) ) ,
200- lineNum : linesInfo . count [ linesInfo . count . length - 1 ] ,
201- lineNumTopLevel : linesInfo . total ,
196+ lineNum : linesInfo . count [ linesInfo . count . length - 1 ] - 1 ,
197+ lineNumTopLevel : linesInfo . total - 1 ,
202198 parent : formatURI ( linesInfo . parStack [ linesInfo . parStack . length - 1 ] ) ,
203199 match
204200 }
@@ -260,11 +256,11 @@ function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diag
260256 // merge the lines of the file into the current document
261257 lines . splice ( inc . lineNumTopLevel + 1 , 0 , ...dataLines )
262258 // add the closing #line indicating we're re-entering a block a level up
263- lines . splice ( inc . lineNumTopLevel + 1 + dataLines . length , 0 , `#line ${ inc . lineNum } "${ inc . parent } "` )
259+ lines . splice ( inc . lineNumTopLevel + 1 + dataLines . length , 0 , `#line ${ inc . lineNum + 1 } "${ inc . parent } "` )
264260}
265261
266262function lint ( docURI : string , lines : string [ ] , diagnostics : Map < string , Diagnostic [ ] > , hasDirective : boolean ) {
267- lines . forEach ( ( l , i ) => { if ( codeFilters . some ( r => r . test ( l ) ) ) lines [ i ] = '' } )
263+ //console.log(lines.join('\n') )
268264
269265 let out : string = ''
270266 try {
@@ -282,20 +278,25 @@ function lint(docURI: string, lines: string[], diagnostics: Map<string, Diagnost
282278
283279 diagnostics . forEach ( ( diags , uri ) => {
284280 if ( diags . length === 0 ) return
285- linterLog . info ( ( ) => `found ${ diags . length } error(s) for ${ trimPath ( uri ) } ` )
281+ const errors = diags . filter ( d => d . severity === DiagnosticSeverity . Error )
282+ const warnings = diags . filter ( d => d . severity === DiagnosticSeverity . Warning )
283+ linterLog . info ( ( ) => `found ${ errors . length } error(s) and ${ warnings . length } warning(s) for ${ trimPath ( uri ) } ` )
286284 } )
287285
288286 const diagsList = daigsArray ( diagnostics )
289287
290288 if ( diagsList . filter ( d => d . diag . length > 0 ) . length === 0 ) linterLog . info ( ( ) => 'no errors found' )
291289
290+ //console.log(JSON.stringify(diagsList.filter(d => d.diag.length > 0), null, 2))
291+
292292 diagsList . forEach ( d => {
293293 if ( win ) d . uri = d . uri . replace ( 'file://C:' , 'file:///c%3A' )
294294 connection . sendDiagnostics ( { uri : d . uri , diagnostics : d . diag } )
295295 } )
296296}
297297
298298function processErrors ( out : string , docURI : string , diagnostics : Map < string , Diagnostic [ ] > , hasDirective : boolean ) {
299+ linterLog . debug ( ( ) => out . split ( '\n' ) . filter ( s => s . length > 2 ) . join ( '\n' ) )
299300 filterMatches ( out ) . forEach ( match => {
300301 const error : ErrorMatch = {
301302 type : errorType ( match [ 1 ] ) ,
@@ -308,9 +309,9 @@ function processErrors(out: string, docURI: string, diagnostics: Map<string, Dia
308309
309310 const diag : Diagnostic = {
310311 severity : error . type ,
311- range : calcRange ( error . line , fileName ) ,
312- // range: calcRange(error.line - ((!hasDirective && includeGraph.get(fileName).parents.size === 0) ? 2 : 1), fileName),
313- message : `Line ${ error . line + 1 } ${ replaceWords ( error . msg ) } ` ,
312+ // range: calcRange(error.line - 1 , fileName),
313+ range : calcRange ( error . line - ( ( ! hasDirective && includeGraph . get ( fileName ) . parents . size === 0 ) ? 2 : 1 ) , fileName ) ,
314+ message : `Line ${ error . line + ( ( ! hasDirective && includeGraph . get ( fileName ) . parents . size === 0 ) ? 2 : 1 ) } ${ replaceWords ( error . msg ) } ` ,
314315 source : 'mc-glsl'
315316 }
316317
@@ -353,7 +354,7 @@ const filterMatches = (output: string) => output
353354 . filter ( match => match && match . length === 5 )
354355
355356function calcRange ( lineNum : number , uri : string ) : Range {
356- linterLog . debug ( ( ) => `calculating range for ${ trimPath ( uri ) } at L${ lineNum + 1 } ` )
357+ linterLog . debug ( ( ) => `calculating range for ${ trimPath ( uri ) } at L${ lineNum + 1 } , index ${ lineNum } ` )
357358
358359 const lines = getDocumentContents ( uri ) . split ( '\n' )
359360 const line = lines [ Math . min ( Math . max ( lineNum , 0 ) , lines . length - 1 ) ]
0 commit comments