Fixes compiler init order by using initializeStateDependentProperties (#4210)

The options were being properly passed in the state,
but the UI was being initialized before the value was set to the member,
causing it not to be displayed.

Closes #4207
This commit is contained in:
Rubén Rincón Blanco
2022-12-19 19:57:53 -06:00
committed by Matt Godbolt
parent b3a619b6a1
commit baf975e52d
2 changed files with 30 additions and 22 deletions
+5 -4
View File
@@ -22,7 +22,7 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import {Language} from '../types/languages.interfaces';
import {Language, LanguageKey} from '../types/languages.interfaces';
import {CompilerInfo} from '../types/compiler.interfaces';
export type LibraryVersion = {
@@ -51,12 +51,13 @@ export type LibsPerRemote = Record<string, LanguageLibs>;
export type Options = {
libs: Libs;
remoteLibs: LibsPerRemote;
languages: Record<string, Language>;
languages: Record<LanguageKey, Language>;
compilers: CompilerInfo[];
defaultCompiler: Record<string, string>;
defaultLibs: Record<string, string | null>;
defaultCompiler: Record<LanguageKey, string>;
defaultLibs: Record<LanguageKey, string | null>;
defaultFontScale: number;
sentryDsn?: string;
release?: string;
sentryEnvironment?: string;
compileOptions: Record<LanguageKey, string>
};
+25 -18
View File
@@ -195,7 +195,7 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
private compilerService: CompilerService;
private readonly id: number;
private sourceTreeId: number | null;
private readonly sourceEditorId: number | null;
private sourceEditorId: number | null;
private originalCompilerId: string;
private readonly infoByLang: Record<string, {compiler: string; options: string}>;
private deferCompiles: boolean;
@@ -314,23 +314,15 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
// eslint-disable-next-line max-statements
constructor(hub: Hub, container: Container, state: MonacoPaneState & CompilerState) {
super(hub, container, state);
this.compilerService = hub.compilerService;
this.id = state.id || hub.nextCompilerId();
this.sourceTreeId = state.tree ? state.tree : null;
if (this.sourceTreeId) {
this.sourceEditorId = null;
} else {
this.sourceEditorId = state.source || 1;
}
this.id = state.id || hub.nextCompilerId();
this.settings = Settings.getStoredSettings();
this.originalCompilerId = state.compiler;
this.initLangAndCompiler(state);
this.infoByLang = {};
this.deferCompiles = hub.deferred;
this.needsCompile = false;
this.deviceViewOpen = !!state.deviceViewOpen;
this.options = state.options || (options.compileOptions as any)[this.currentLangId ?? ''];
this.initLangAndCompiler(state);
this.source = '';
this.assembly = [];
this.colours = [];
@@ -342,9 +334,9 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.nextRequest = null;
this.nextCMakeRequest = null;
this.optViewOpen = false;
this.flagsViewOpen = state.flagsViewOpen || false;
this.cfgViewOpen = false;
this.wantOptInfo = state.wantOptInfo;
this.decorations = {
labelUsages: [],
};
@@ -354,7 +346,7 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.alertSystem.prefixMessage = 'Compiler #' + this.id;
this.awaitingInitialResults = false;
this.selection = state.selection;
this.linkedFadeTimeoutId = null;
this.toolsMenu = null;
@@ -371,9 +363,7 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.compiler?.id ?? '',
this.onCompilerChange.bind(this)
);
this.initLibraries(state);
// MonacoPane's registerCallbacks is not called late enough either
this.initCallbacks();
// Handle initial settings
@@ -388,6 +378,23 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
}
}
override initializeStateDependentProperties(state: MonacoPaneState & CompilerState) {
this.compilerService = this.hub.compilerService;
this.sourceTreeId = state.tree ? state.tree : null;
if (this.sourceTreeId) {
this.sourceEditorId = null;
} else {
this.sourceEditorId = state.source || 1;
}
this.options = state.options || (options.compileOptions[this.currentLangId ?? ''] ?? '');
this.deviceViewOpen = !!state.deviceViewOpen;
this.flagsViewOpen = state.flagsViewOpen || false;
this.wantOptInfo = state.wantOptInfo;
this.originalCompilerId = state.compiler;
this.selection = state.selection;
}
override getInitialHTML() {
return $('#compiler').html();
}