Skip to content

Commit

Permalink
Make MonacoPane calls createDecorationsCollection in a single place…
Browse files Browse the repository at this point in the history
… instead of forcing many subclasses to remember to call `initDecorations`. Some subclasses never use DecorationsCollection and call init for no reason now, but it still seems healthier.

Also remove the depracated `deltaDecorations` from stack-usage-view.
  • Loading branch information
OfekShilon committed May 3, 2024
1 parent 9f5906a commit 08395d9
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 15 deletions.
1 change: 0 additions & 1 deletion static/colour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const schemes: ColourSchemeInfo[] = [
},
];

// In every MonacoPane-child that needs to use this, make sure `createEditor` calls `this.initDecorations()`
export function applyColours(
colours: Record<number, number>,
schemeName: string,
Expand Down
1 change: 0 additions & 1 deletion static/panes/ast-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export class Ast extends MonacoPane<monaco.editor.IStandaloneCodeEditor, AstStat
lineNumbersMinChars: 3,
}),
);
this.initDecorations();
}

override getPrintName() {
Expand Down
1 change: 0 additions & 1 deletion static/panes/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.settings,
),
);
this.initDecorations();
}

override getPrintName() {
Expand Down
1 change: 0 additions & 1 deletion static/panes/device-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export class DeviceAsm extends MonacoPane<monaco.editor.IStandaloneCodeEditor, D
lineNumbersMinChars: 3,
}),
);
this.initDecorations();
}

override getPrintName() {
Expand Down
1 change: 0 additions & 1 deletion static/panes/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ export class Editor extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Edit
);

this.editor.getModel()?.setEOL(monaco.editor.EndOfLineSequence.LF);
this.initDecorations();
}

override getPrintName() {
Expand Down
1 change: 0 additions & 1 deletion static/panes/ir-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export class Ir extends MonacoPane<monaco.editor.IStandaloneCodeEditor, IrState>
lineNumbersMinChars: 3,
}),
);
this.initDecorations();
}

override getPrintName() {
Expand Down
1 change: 0 additions & 1 deletion static/panes/opt-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class Opt extends MonacoPane<monaco.editor.IStandaloneCodeEditor, OptStat
glyphMargin: true,
}),
);
this.initDecorations();
}

override getPrintName() {
Expand Down
5 changes: 1 addition & 4 deletions static/panes/pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export abstract class MonacoPane<E extends monaco.editor.IEditor, S> extends Pan
override registerButtons(state: S): void {
const editorRoot = this.domRoot.find('.monaco-placeholder')[0];
this.createEditor(editorRoot);
this.editorDecorations = this.editor.createDecorationsCollection();
this.fontScale = new FontScale(this.domRoot, state, this.editor);
}

Expand Down Expand Up @@ -329,10 +330,6 @@ export abstract class MonacoPane<E extends monaco.editor.IEditor, S> extends Pan
*/
abstract createEditor(editorRoot: HTMLElement): void;

initDecorations(): void {
this.editorDecorations = this.editor.createDecorationsCollection();
}

protected override onSettingsChange(settings: SiteSettings) {
super.onSettingsChange(settings);
this.editor.updateOptions({
Expand Down
7 changes: 3 additions & 4 deletions static/panes/stack-usage-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {CompilerInfo} from '../compiler.interfaces.js';
import {unwrap} from '../assert.js';

export class StackUsage extends MonacoPane<monaco.editor.IStandaloneCodeEditor, StackUsageState> {
currentDecorations: string[] = [];
// Note: bool | undef here instead of just bool because of an issue with field initialization order
isCompilerSupported?: boolean;

Expand Down Expand Up @@ -129,7 +128,7 @@ export class StackUsage extends MonacoPane<monaco.editor.IStandaloneCodeEditor,
}

showStackUsageResults(results: suCodeEntry[]) {
const su: monaco.editor.IModelDeltaDecoration[] = [];
const suDecorations: monaco.editor.IModelDeltaDecoration[] = [];

const groupedResults = _.groupBy(results, x => x.DebugLoc.Line);

Expand All @@ -145,7 +144,7 @@ export class StackUsage extends MonacoPane<monaco.editor.IStandaloneCodeEditor,
return 'Mixed';
}, '');
const contents = value.map(this.getDisplayableOpt);
su.push({
suDecorations.push({
range: new monaco.Range(linenumber, 1, linenumber, Infinity),
options: {
isWholeLine: true,
Expand All @@ -156,7 +155,7 @@ export class StackUsage extends MonacoPane<monaco.editor.IStandaloneCodeEditor,
});
}

this.currentDecorations = this.editor.deltaDecorations(this.currentDecorations, su);
this.editorDecorations.set(suDecorations);
}

override onCompiler(id: number, compiler) {
Expand Down

0 comments on commit 08395d9

Please sign in to comment.