diff --git a/static/event-hub.ts b/static/event-hub.ts index 14afa1191..606aa29e0 100644 --- a/static/event-hub.ts +++ b/static/event-hub.ts @@ -89,26 +89,4 @@ export class EventHub { } this.subscriptions = []; } - - public mediateDependentCalls( - dependent: EventHubCallback, - dependency: EventHubCallback, - ): DependencyProxies { - let hasDependencyExecuted = false; - let lastDependentArguments: unknown[] | null = null; - const dependencyProxy = function (this: unknown, ...args: unknown[]) { - dependency.apply(this, args); - hasDependencyExecuted = true; - if (lastDependentArguments) { - dependent.apply(this, lastDependentArguments); - } - }; - const dependentProxy = function (this: unknown, ...args: unknown[]) { - if (hasDependencyExecuted) { - dependent.apply(this, args); - } - lastDependentArguments = args; - }; - return {dependencyProxy, dependentProxy}; - } } diff --git a/static/panes/ast-view.ts b/static/panes/ast-view.ts index bd5edefd0..ad24cf1c1 100644 --- a/static/panes/ast-view.ts +++ b/static/panes/ast-view.ts @@ -56,9 +56,11 @@ type AstCodeEntry = { }; export class Ast extends MonacoPane { + // TODO: eliminate deprecated deltaDecorations monaco API decorations: DecorationEntry = {linkedCode: []}; prevDecorations: any[] = []; - colours: string[] = []; + colourScheme?: string = undefined; + srcColours?: Record = undefined; astCode: AstCodeEntry[] = []; linkedFadeTimeoutId?: NodeJS.Timeout = undefined; @@ -91,11 +93,9 @@ export class Ast extends MonacoPane'}]); } @@ -230,27 +231,35 @@ export class Ast extends MonacoPane, scheme: string) { - if (id === this.compilerInfo.compilerId) { - const astColours = {}; - for (const [index, code] of this.astCode.entries()) { - if ( - code.source && - code.source.from?.line && - code.source.to?.line && - code.source.from.line <= code.source.to.line && - code.source.to.line < code.source.from.line + 100 - ) { - for (let i = code.source.from.line; i <= code.source.to.line; ++i) { - if (i - 1 in colours) { - astColours[index] = colours[i - 1]; - break; - } + tryApplyAstColours(): void { + if (!this.srcColours || !this.colourScheme || this.astCode.length === 0) return; + const astColours = {}; + for (const [index, code] of this.astCode.entries()) { + if ( + code.source && + code.source.from?.line && + code.source.to?.line && + code.source.from.line <= code.source.to.line && + code.source.to.line < code.source.from.line + 100 + ) { + for (let i = code.source.from.line; i <= code.source.to.line; ++i) { + if (i - 1 in this.srcColours) { + astColours[index] = this.srcColours[i - 1]; + break; } } } - colour.applyColours(astColours, scheme, this.editorDecorations); } + colour.applyColours(astColours, this.colourScheme, this.editorDecorations); + } + + onColours(id: number, srcColours: Record, colourScheme: string): void { + if (id !== this.compilerInfo.compilerId) return; + + this.srcColours = srcColours; + this.colourScheme = colourScheme; + + this.tryApplyAstColours(); } updateDecorations() { diff --git a/static/panes/ir-view.ts b/static/panes/ir-view.ts index fadd1a9fb..b48ffabef 100644 --- a/static/panes/ir-view.ts +++ b/static/panes/ir-view.ts @@ -48,9 +48,13 @@ import {CompilerInfo} from '../compiler.interfaces.js'; export class Ir extends MonacoPane { linkedFadeTimeoutId: NodeJS.Timeout | null = null; irCode: any[] = []; - colours: any[] = []; + srcColours?: Record = undefined; + colourScheme?: string = undefined; + + // TODO: eliminate deprecated deltaDecorations monaco API decorations: any = {}; previousDecorations: string[] = []; + options: Toggles; filters: Toggles; lastOptions: LLVMIrBackendOptions = { @@ -168,15 +172,11 @@ export class Ir extends MonacoPane override registerCallbacks(): void { const onMouseMove = _.throttle(this.onMouseMove.bind(this), 50); const onDidChangeCursorSelection = _.throttle(this.onDidChangeCursorSelection.bind(this), 500); - const onColoursOnCompile = this.eventHub.mediateDependentCalls( - this.onColours.bind(this), - this.onCompileResult.bind(this), - ); this.paneRenaming.on('renamePane', this.updateState.bind(this)); - this.eventHub.on('compileResult', onColoursOnCompile.dependencyProxy, this); - this.eventHub.on('colours', onColoursOnCompile.dependentProxy, this); + this.eventHub.on('compileResult', this.onCompileResult.bind(this)); + this.eventHub.on('colours', this.onColours.bind(this)); this.eventHub.on('panesLinkLine', this.onPanesLinkLine.bind(this)); this.editor.onMouseMove(event => onMouseMove(event)); @@ -213,6 +213,7 @@ export class Ir extends MonacoPane if (this.compilerInfo.compilerId !== compilerId) return; if (result.hasIrOutput) { this.showIrResults(unwrap(result.irOutput).asm); + this.tryApplyIrColours(); } else if (compiler.supportsIrView) { this.showIrResults([{text: ''}]); } @@ -248,20 +249,29 @@ export class Ir extends MonacoPane } } - onColours(compilerId: number, colours: any, scheme: any): void { - if (compilerId !== this.compilerInfo.compilerId) return; + tryApplyIrColours(): void { + if (!this.srcColours || !this.colourScheme || this.irCode.length === 0) return; + const irColours: Record = {}; for (const [index, code] of this.irCode.entries()) { if ( code.source && code.source.file === null && code.source.line > 0 && - colours[code.source.line - 1] !== undefined + this.srcColours[code.source.line - 1] !== undefined ) { - irColours[index] = colours[code.source.line - 1]; + irColours[index] = this.srcColours[code.source.line - 1]!; } } - applyColours(irColours, scheme, this.editorDecorations); + applyColours(irColours, this.colourScheme, this.editorDecorations); + } + + onColours(compilerId: number, srcColours: Record, scheme: string): void { + if (compilerId !== this.compilerInfo.compilerId) return; + this.colourScheme = scheme; + this.srcColours = srcColours; + + this.tryApplyIrColours(); } onMouseMove(e: monaco.editor.IEditorMouseEvent): void {