diff --git a/static/components.interfaces.ts b/static/components.interfaces.ts index 9cdb45622..b64383704 100644 --- a/static/components.interfaces.ts +++ b/static/components.interfaces.ts @@ -32,7 +32,8 @@ import {ClangirState} from './panes/clangir-view.interfaces.js'; import {GccDumpViewState} from './panes/gccdump-view.interfaces.js'; import {IrState} from './panes/ir-view.interfaces.js'; import {OptPipelineViewState} from './panes/opt-pipeline.interfaces.js'; -import {MonacoPaneState} from './panes/pane.interfaces.js'; +import {MonacoPane, Pane} from './panes/pane'; +import {MonacoPaneState, PaneState} from './panes/pane.interfaces.js'; /** * Component name constants with 'as const' assertions. @@ -468,3 +469,9 @@ export interface SerializedLayoutState { * Type for drag source factory functions */ export type DragSourceFactory = () => ComponentConfig; + +export type InferComponentState = T extends MonacoPane + ? S & MonacoPaneState + : T extends Pane + ? S & PaneState + : never; diff --git a/static/hub.ts b/static/hub.ts index cfd022770..73ba13ac7 100644 --- a/static/hub.ts +++ b/static/hub.ts @@ -23,8 +23,6 @@ // POSSIBILITY OF SUCH DAMAGE. import GoldenLayout, {ContentItem} from 'golden-layout'; -type GLC = GoldenLayout.Container; - import _ from 'underscore'; import {LanguageKey} from '../types/languages.interfaces.js'; import {CompilerService} from './compiler-service.js'; @@ -46,6 +44,7 @@ import { HASKELL_CORE_VIEW_COMPONENT_NAME, HASKELL_STG_VIEW_COMPONENT_NAME, IR_VIEW_COMPONENT_NAME, + InferComponentState, LLVM_OPT_PIPELINE_VIEW_COMPONENT_NAME, OPT_PIPELINE_VIEW_COMPONENT_NAME, OPT_VIEW_COMPONENT_NAME, @@ -89,7 +88,9 @@ import {RustMir as RustMirView} from './panes/rustmir-view.js'; import {StackUsage as StackUsageView} from './panes/stack-usage-view.js'; import {ToolInputView} from './panes/tool-input-view.js'; import {Tool} from './panes/tool.js'; -import {Tree} from './panes/tree.js'; +import {Tree, TreeState} from './panes/tree.js'; + +type GLC = GoldenLayout.Container; type EventDescriptorMap = { [E in keyof EventMap]: [E, ...Parameters]; @@ -429,7 +430,7 @@ export class Hub { // Component Factories - private codeEditorFactory(container: GoldenLayout.Container, state: any): Editor { + private codeEditorFactory(container: GoldenLayout.Container, state: InferComponentState): Editor { // Ensure editors are closable: some older versions had 'isClosable' false. // NB there doesn't seem to be a better way to do this than reach into the config and rely on the fact nothing // has used it yet. @@ -442,157 +443,142 @@ export class Hub { return editor; } - private treeFactory(container: GoldenLayout.Container, state: ConstructorParameters[2]): Tree { + private treeFactory(container: GoldenLayout.Container, state: TreeState): Tree { const tree = new Tree(this, container, state); this.trees.push(tree); return tree; } - public compilerFactory(container: GoldenLayout.Container, state: any): any /* typeof Compiler */ { + public compilerFactory(container: GoldenLayout.Container, state: InferComponentState): Compiler { return new Compiler(this, container, state); } - public executorFactory(container: GoldenLayout.Container, state: any): any /*typeof Executor */ { + public executorFactory(container: GoldenLayout.Container, state: InferComponentState): Executor { return new Executor(this, container, state); } - public outputFactory(container: GoldenLayout.Container, state: ConstructorParameters[2]): Output { + public outputFactory(container: GoldenLayout.Container, state: InferComponentState): Output { return new Output(this, container, state); } - public toolFactory(container: GoldenLayout.Container, state: any): any /* typeof Tool */ { + public toolFactory(container: GoldenLayout.Container, state: InferComponentState): Tool { return new Tool(this, container, state); } - public diffFactory(container: GoldenLayout.Container, state: any): any /* typeof Diff */ { + public diffFactory(container: GoldenLayout.Container, state: InferComponentState): Diff { return new Diff(this, container, state); } public toolInputViewFactory( container: GoldenLayout.Container, - state: ConstructorParameters[2], + state: InferComponentState, ): ToolInputView { return new ToolInputView(this, container, state); } - public optViewFactory(container: GoldenLayout.Container, state: ConstructorParameters[2]): OptView { + public optViewFactory(container: GoldenLayout.Container, state: InferComponentState): OptView { return new OptView(this, container, state); } public stackUsageViewFactory( container: GoldenLayout.Container, - state: ConstructorParameters[2], + state: InferComponentState, ): StackUsageView { return new StackUsageView(this, container, state); } - public flagsViewFactory( - container: GoldenLayout.Container, - state: ConstructorParameters[2], - ): FlagsView { + public flagsViewFactory(container: GoldenLayout.Container, state: InferComponentState): FlagsView { return new FlagsView(this, container, state); } public ppViewFactory( container: GoldenLayout.Container, - state: ConstructorParameters[2], + state: InferComponentState, ): PreProcessorView { return new PreProcessorView(this, container, state); } - public astViewFactory(container: GoldenLayout.Container, state: ConstructorParameters[2]): AstView { + public astViewFactory(container: GoldenLayout.Container, state: InferComponentState): AstView { return new AstView(this, container, state); } - public irViewFactory(container: GoldenLayout.Container, state: ConstructorParameters[2]): IrView { + public irViewFactory(container: GoldenLayout.Container, state: InferComponentState): IrView { return new IrView(this, container, state); } - public clangirViewFactory( - container: GoldenLayout.Container, - state: ConstructorParameters[2], - ): ClangirView { + public clangirViewFactory(container: GoldenLayout.Container, state: InferComponentState): ClangirView { return new ClangirView(this, container, state); } - public optPipelineFactory( - container: GoldenLayout.Container, - state: ConstructorParameters[2], - ): OptPipeline { + public optPipelineFactory(container: GoldenLayout.Container, state: InferComponentState): OptPipeline { return new OptPipeline(this, container, state); } - public deviceViewFactory( - container: GoldenLayout.Container, - state: ConstructorParameters[2], - ): DeviceView { + public deviceViewFactory(container: GoldenLayout.Container, state: InferComponentState): DeviceView { return new DeviceView(this, container, state); } public gnatDebugTreeViewFactory( container: GoldenLayout.Container, - state: ConstructorParameters[2], + state: InferComponentState, ): GnatDebugTreeView { return new GnatDebugTreeView(this, container, state); } public gnatDebugViewFactory( container: GoldenLayout.Container, - state: ConstructorParameters[2], + state: InferComponentState, ): GnatDebugView { return new GnatDebugView(this, container, state); } - public rustMirViewFactory( - container: GoldenLayout.Container, - state: ConstructorParameters[2], - ): RustMirView { + public rustMirViewFactory(container: GoldenLayout.Container, state: InferComponentState): RustMirView { return new RustMirView(this, container, state); } public rustMacroExpViewFactory( container: GoldenLayout.Container, - state: ConstructorParameters[2], + state: InferComponentState, ): RustMacroExpView { return new RustMacroExpView(this, container, state); } - public rustHirViewFactory( - container: GoldenLayout.Container, - state: ConstructorParameters[2], - ): RustHirView { + public rustHirViewFactory(container: GoldenLayout.Container, state: InferComponentState): RustHirView { return new RustHirView(this, container, state); } public haskellCoreViewFactory( container: GoldenLayout.Container, - state: ConstructorParameters[2], + state: InferComponentState, ): HaskellCoreView { return new HaskellCoreView(this, container, state); } public haskellStgViewFactory( container: GoldenLayout.Container, - state: ConstructorParameters[2], + state: InferComponentState, ): HaskellStgView { return new HaskellStgView(this, container, state); } public haskellCmmViewFactory( container: GoldenLayout.Container, - state: ConstructorParameters[2], + state: InferComponentState, ): HaskellCmmView { return new HaskellCmmView(this, container, state); } - public gccDumpViewFactory(container: GoldenLayout.Container, state: any): any /* typeof GccDumpView */ { + public gccDumpViewFactory(container: GoldenLayout.Container, state: InferComponentState): GCCDumpView { return new GCCDumpView(this, container, state); } - public cfgViewFactory(container: GoldenLayout.Container, state: ConstructorParameters[2]): CfgView { + public cfgViewFactory(container: GoldenLayout.Container, state: InferComponentState): CfgView { return new CfgView(this, container, state); } - public conformanceViewFactory(container: GoldenLayout.Container, state: any): any /* typeof ConformanceView */ { + public conformanceViewFactory( + container: GoldenLayout.Container, + state: InferComponentState, + ): ConformanceView { return new ConformanceView(this, container, state); } }