@@ -22,11 +22,6 @@ const errorFilters = [
22
22
/ ( N o c o d e g e n e r a t e d ) / ,
23
23
/ ( c o m p i l a t i o n t e r m i n a t e d ) / ,
24
24
/ 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 / ,
30
25
]
31
26
32
27
export const includeGraph = new Graph ( )
@@ -154,10 +149,10 @@ function processIncludes(lines: string[], incStack: string[], allIncludes: Set<I
154
149
155
150
function getIncludes ( uri : string , lines : string [ ] ) {
156
151
const lineInfo : LinesProcessingInfo = {
157
- total : - 1 ,
152
+ total : 0 ,
158
153
comment : Comment . State . No ,
159
154
parStack : [ uri ] ,
160
- count : [ - 1 ] ,
155
+ count : [ 0 ] ,
161
156
}
162
157
163
158
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
180
175
181
176
if ( line . startsWith ( '#line' ) ) {
182
177
const inc = line . slice ( line . indexOf ( '"' ) + 1 , line . lastIndexOf ( '"' ) )
178
+ if ( inc . length + 1 === line . length ) lines [ i ] = ''
183
179
if ( inc === linesInfo . parStack [ linesInfo . parStack . length - 2 ] ) {
184
180
linesInfo . count . pop ( )
185
181
linesInfo . parStack . pop ( )
186
182
} else {
187
- linesInfo . count . push ( - 1 )
183
+ linesInfo . count . push ( 0 )
188
184
linesInfo . parStack . push ( inc )
189
185
}
190
186
return includes
@@ -197,8 +193,8 @@ function processLine(includes: Map<string, IncludeObj>, line: string, lines: str
197
193
formatURI ( absPath ( linesInfo . parStack [ linesInfo . parStack . length - 1 ] , match [ 1 ] ) ) ,
198
194
{
199
195
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 ,
202
198
parent : formatURI ( linesInfo . parStack [ linesInfo . parStack . length - 1 ] ) ,
203
199
match
204
200
}
@@ -260,11 +256,11 @@ function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diag
260
256
// merge the lines of the file into the current document
261
257
lines . splice ( inc . lineNumTopLevel + 1 , 0 , ...dataLines )
262
258
// 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 } "` )
264
260
}
265
261
266
262
function 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') )
268
264
269
265
let out : string = ''
270
266
try {
@@ -282,20 +278,25 @@ function lint(docURI: string, lines: string[], diagnostics: Map<string, Diagnost
282
278
283
279
diagnostics . forEach ( ( diags , uri ) => {
284
280
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 ) } ` )
286
284
} )
287
285
288
286
const diagsList = daigsArray ( diagnostics )
289
287
290
288
if ( diagsList . filter ( d => d . diag . length > 0 ) . length === 0 ) linterLog . info ( ( ) => 'no errors found' )
291
289
290
+ //console.log(JSON.stringify(diagsList.filter(d => d.diag.length > 0), null, 2))
291
+
292
292
diagsList . forEach ( d => {
293
293
if ( win ) d . uri = d . uri . replace ( 'file://C:' , 'file:///c%3A' )
294
294
connection . sendDiagnostics ( { uri : d . uri , diagnostics : d . diag } )
295
295
} )
296
296
}
297
297
298
298
function processErrors ( out : string , docURI : string , diagnostics : Map < string , Diagnostic [ ] > , hasDirective : boolean ) {
299
+ linterLog . debug ( ( ) => out . split ( '\n' ) . filter ( s => s . length > 2 ) . join ( '\n' ) )
299
300
filterMatches ( out ) . forEach ( match => {
300
301
const error : ErrorMatch = {
301
302
type : errorType ( match [ 1 ] ) ,
@@ -308,9 +309,9 @@ function processErrors(out: string, docURI: string, diagnostics: Map<string, Dia
308
309
309
310
const diag : Diagnostic = {
310
311
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 ) } ` ,
314
315
source : 'mc-glsl'
315
316
}
316
317
@@ -353,7 +354,7 @@ const filterMatches = (output: string) => output
353
354
. filter ( match => match && match . length === 5 )
354
355
355
356
function 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 } ` )
357
358
358
359
const lines = getDocumentContents ( uri ) . split ( '\n' )
359
360
const line = lines [ Math . min ( Math . max ( lineNum , 0 ) , lines . length - 1 ) ]
0 commit comments