MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / StackUsage

Class StackUsage

static/panes/stack-usage-view.ts:48–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46};
47
48export class StackUsage extends MonacoPane<monaco.editor.IStandaloneCodeEditor, StackUsageState> {
49 // Note: bool | undef here instead of just bool because of an issue with field initialization order
50 isCompilerSupported?: boolean;
51
52 constructor(hub: Hub, container: Container, state: StackUsageState & MonacoPaneState) {
53 super(hub, container, state);
54 if (state.suOutput) {
55 this.showStackUsageResults(state.suOutput, state.source);
56 }
57 this.eventHub.emit('stackUsageViewOpened', this.compilerInfo.compilerId);
58 }
59
60 override getInitialHTML(): string {
61 return $('#stackusage').html();
62 }
63
64 override createEditor(editorRoot: HTMLElement): void {
65 this.editor = monaco.editor.create(
66 editorRoot,
67 extendConfig({
68 language: 'plaintext',
69 readOnly: true,
70 glyphMargin: true,
71 }),
72 );
73 }
74
75 override registerCallbacks() {
76 this.eventHub.emit('requestSettings');
77 this.eventHub.emit('findCompilers');
78
79 this.container.on('shown', this.resize, this);
80
81 const cursorSelectionThrottledFunction = _.throttle(this.onDidChangeCursorSelection.bind(this), 500);
82 this.editor.onDidChangeCursorSelection(e => {
83 cursorSelectionThrottledFunction(e);
84 });
85 }
86
87 override onCompileResult(id: number, compiler: CompilerInfo, result: CompilationResult) {
88 if (this.compilerInfo.compilerId !== id || !this.isCompilerSupported) return;
89 const source = unwrap(result.source);
90 this.editor.setValue(source);
91 if (result.stackUsageOutput) {
92 this.showStackUsageResults(result.stackUsageOutput, source);
93 }
94
95 // TODO: This is inelegant again. Previously took advantage of fourth argument for the compileResult event.
96 const lang = compiler.lang === 'c++' ? 'cpp' : compiler.lang;
97 const model = this.editor.getModel();
98 if (model != null && this.getCurrentEditorLanguage() !== lang) {
99 monaco.editor.setModelLanguage(model, lang);
100 }
101
102 if (!this.isAwaitingInitialResults) {
103 if (this.selection) {
104 this.editor.setSelection(this.selection);
105 this.editor.revealLinesInCenter(this.selection.startLineNumber, this.selection.endLineNumber);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected