Skip to content

Commit 54e60f6

Browse files
author
Akos Kitta
committed
preferences how to reveal error position
Signed-off-by: Akos Kitta <[email protected]>
1 parent 15f1411 commit 54e60f6

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-preferences.ts

+36
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@ export enum UpdateChannel {
1313
Stable = 'stable',
1414
Nightly = 'nightly',
1515
}
16+
export const ErrorRevealStrategyLiterals = [
17+
/**
18+
* Scroll vertically as necessary and reveal a line.
19+
*/
20+
'auto',
21+
/**
22+
* Scroll vertically as necessary and reveal a line centered vertically.
23+
*/
24+
'center',
25+
/**
26+
* Scroll vertically as necessary and reveal a line close to the top of the viewport, optimized for viewing a code definition.
27+
*/
28+
'top',
29+
/**
30+
* Scroll vertically as necessary and reveal a line centered vertically only if it lies outside the viewport.
31+
*/
32+
'centerIfOutsideViewport',
33+
] as const;
34+
export type ErrorRevealStrategy = typeof ErrorRevealStrategyLiterals[number];
35+
export namespace ErrorRevealStrategy {
36+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
37+
export function is(arg: any): arg is ErrorRevealStrategy {
38+
return !!arg && ErrorRevealStrategyLiterals.includes(arg);
39+
}
40+
export const Default: ErrorRevealStrategy = 'centerIfOutsideViewport';
41+
}
1642

1743
export const ArduinoConfigSchema: PreferenceSchema = {
1844
type: 'object',
@@ -41,6 +67,15 @@ export const ArduinoConfigSchema: PreferenceSchema = {
4167
),
4268
default: false,
4369
},
70+
'arduino.compile.revealRange': {
71+
enum: [...ErrorRevealStrategyLiterals],
72+
description: nls.localize(
73+
'arduino/preferences/compile.revealRange',
74+
"Adjusts how compiler errors are revealed in the editor after a failed verify/upload. Possible values: 'auto': Scroll vertically as necessary and reveal a line. 'center': Scroll vertically as necessary and reveal a line centered vertically. 'top': Scroll vertically as necessary and reveal a line close to the top of the viewport, optimized for viewing a code definition. 'centerIfOutsideViewport': Scroll vertically as necessary and reveal a line centered vertically only if it lies outside the viewport. The default value is '{0}'.",
75+
ErrorRevealStrategy.Default
76+
),
77+
default: ErrorRevealStrategy.Default,
78+
},
4479
'arduino.compile.warnings': {
4580
enum: [...CompilerWarningLiterals],
4681
description: nls.localize(
@@ -189,6 +224,7 @@ export interface ArduinoConfiguration {
189224
'arduino.language.log': boolean;
190225
'arduino.compile.verbose': boolean;
191226
'arduino.compile.experimental': boolean;
227+
'arduino.compile.revealRange': ErrorRevealStrategy;
192228
'arduino.compile.warnings': CompilerWarnings;
193229
'arduino.upload.verbose': boolean;
194230
'arduino.upload.verify': boolean;

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
2525
import { MonacoToProtocolConverter } from '@theia/monaco/lib/browser/monaco-to-protocol-converter';
2626
import { ProtocolToMonacoConverter } from '@theia/monaco/lib/browser/protocol-to-monaco-converter';
2727
import { CoreError } from '../../common/protocol/core-service';
28-
import { ArduinoPreferences } from '../arduino-preferences';
28+
import {
29+
ArduinoPreferences,
30+
ErrorRevealStrategy,
31+
} from '../arduino-preferences';
2932
import { InoSelector } from '../ino-selectors';
3033
import { fullRange } from '../utils/monaco';
3134
import { Contribution } from './contribution';
@@ -94,6 +97,7 @@ export class CompilerErrors
9497
private readonly toDisposeOnCompilerErrorDidChange =
9598
new DisposableCollection();
9699
private shell: ApplicationShell | undefined;
100+
private revealStrategy = ErrorRevealStrategy.Default;
97101
private currentError: ErrorDecoration | undefined;
98102
private get currentErrorIndex(): number {
99103
const current = this.currentError;
@@ -127,6 +131,15 @@ export class CompilerErrors
127131
console.warn(`Failed to mark error ${error.id} as the current one.`);
128132
}
129133
});
134+
this.preferences.ready.then(() => {
135+
this.preferences.onPreferenceChanged(({ preferenceName, newValue }) => {
136+
if (preferenceName === 'arduino.compile.revealRange') {
137+
this.revealStrategy = ErrorRevealStrategy.is(newValue)
138+
? newValue
139+
: ErrorRevealStrategy.Default;
140+
}
141+
});
142+
});
130143
}
131144

132145
override registerCommands(registry: CommandRegistry): void {
@@ -429,7 +442,7 @@ export class CompilerErrors
429442
if (editor && this.shell) {
430443
// to avoid flickering, reveal the range here and not with `getByUri`, because it uses `at: 'center'` for the reveal option.
431444
// TODO: check the community reaction whether it is better to set the focus at the error marker. it might cause flickering even if errors are close to each other
432-
editor.editor.revealRange(range, { at: 'centerIfOutsideViewport' });
445+
editor.editor.revealRange(range, { at: this.revealStrategy });
433446
const activeWidget = await this.shell.activateWidget(editor.id);
434447
if (!activeWidget) {
435448
console.warn(

Diff for: i18n/en.json

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@
259259
"cloud.sketchSyncEnpoint": "The endpoint used to push and pull sketches from a backend. By default it points to Arduino Cloud API.",
260260
"compile": "compile",
261261
"compile.experimental": "True if the IDE should handle multiple compiler errors. False by default",
262+
"compile.revealRange": "Adjusts how compiler errors are revealed in the editor after a failed verify/upload. Possible values: 'auto': Scroll vertically as necessary and reveal a line. 'center': Scroll vertically as necessary and reveal a line centered vertically. 'top': Scroll vertically as necessary and reveal a line close to the top of the viewport, optimized for viewing a code definition. 'centerIfOutsideViewport': Scroll vertically as necessary and reveal a line centered vertically only if it lies outside the viewport. The default value is '{0}'.",
262263
"compile.verbose": "True for verbose compile output. False by default",
263264
"compile.warnings": "Tells gcc which warning level to use. It's 'None' by default",
264265
"compilerWarnings": "Compiler warnings",

0 commit comments

Comments
 (0)