Skip to content

Commit 4f486cb

Browse files
author
Akos Kitta
committed
Added core when updating error onSelection change
Signed-off-by: Akos Kitta <[email protected]>
1 parent 6149cff commit 4f486cb

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/compiler-errors.ts

+20-10
Original file line numberDiff line numberDiff line change
@@ -335,20 +335,27 @@ export class CompilerErrors
335335
console.log(
336336
`Handling selection change in editor ${uri}. New (monaco) selection: ${monacoSelection.toJSON()}`
337337
);
338-
const intersectsError = (
338+
const calculatePriority = (
339339
candidateErrorRange: monaco.Range,
340340
currentSelection: monaco.Range
341341
) => {
342342
console.trace(`Candidate error range: ${candidateErrorRange.toJSON()}`);
343343
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 <=
348350
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;
352359
};
353360
const error = (
354361
await Promise.all(
@@ -363,15 +370,18 @@ export class CompilerErrors
363370
.map(async ({ error, rangeOf }) => {
364371
const range = await rangeOf;
365372
if (range) {
366-
if (intersectsError(range, monacoSelection)) {
367-
return error;
373+
const priority = calculatePriority(range, monacoSelection);
374+
if (priority) {
375+
return { ...priority, error };
368376
}
369377
}
370378
return undefined;
371379
})
372380
)
373381
)
374382
.filter(notEmpty)
383+
.sort((left, right) => right.score - left.score) // highest first
384+
.map(({ error }) => error)
375385
.shift();
376386
if (error) {
377387
this.markAsCurrentError(error);

0 commit comments

Comments
 (0)