@@ -335,20 +335,27 @@ export class CompilerErrors
335
335
console . log (
336
336
`Handling selection change in editor ${ uri } . New (monaco) selection: ${ monacoSelection . toJSON ( ) } `
337
337
) ;
338
- const intersectsError = (
338
+ const calculatePriority = (
339
339
candidateErrorRange : monaco . Range ,
340
340
currentSelection : monaco . Range
341
341
) => {
342
342
console . trace ( `Candidate error range: ${ candidateErrorRange . toJSON ( ) } ` ) ;
343
343
console . trace ( `Current selection range: ${ currentSelection . toJSON ( ) } ` ) ;
344
- // if editor selection intersects with the error range or the selection is in one of the lines of an error.
345
- const result =
346
- candidateErrorRange . intersectRanges ( currentSelection ) ||
347
- ( candidateErrorRange . startLineNumber <=
344
+ if ( candidateErrorRange . intersectRanges ( currentSelection ) ) {
345
+ console . trace ( 'Intersects.' ) ;
346
+ return { score : 2 } ;
347
+ }
348
+ if (
349
+ candidateErrorRange . startLineNumber <=
348
350
currentSelection . startLineNumber &&
349
- candidateErrorRange . endLineNumber >= currentSelection . endLineNumber ) ;
350
- console . trace ( `Intersects: ${ result } ` ) ;
351
- return result ;
351
+ candidateErrorRange . endLineNumber >= currentSelection . endLineNumber
352
+ ) {
353
+ console . trace ( 'Same line.' ) ;
354
+ return { score : 1 } ;
355
+ }
356
+
357
+ console . trace ( 'No match' ) ;
358
+ return undefined ;
352
359
} ;
353
360
const error = (
354
361
await Promise . all (
@@ -363,15 +370,18 @@ export class CompilerErrors
363
370
. map ( async ( { error, rangeOf } ) => {
364
371
const range = await rangeOf ;
365
372
if ( range ) {
366
- if ( intersectsError ( range , monacoSelection ) ) {
367
- return error ;
373
+ const priority = calculatePriority ( range , monacoSelection ) ;
374
+ if ( priority ) {
375
+ return { ...priority , error } ;
368
376
}
369
377
}
370
378
return undefined ;
371
379
} )
372
380
)
373
381
)
374
382
. filter ( notEmpty )
383
+ . sort ( ( left , right ) => right . score - left . score ) // highest first
384
+ . map ( ( { error } ) => error )
375
385
. shift ( ) ;
376
386
if ( error ) {
377
387
this . markAsCurrentError ( error ) ;
0 commit comments