mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 07:04:04 -05:00
Improve syntax highlight switching on AST and Opt
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Type your code here, or load an example.
|
||||
int square(int num) {
|
||||
return num * num;
|
||||
return num * num;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
package main
|
||||
|
||||
func Square(x int) int {
|
||||
return x * x
|
||||
return x * x
|
||||
}
|
||||
|
||||
func main() {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define i32 @square(i32) local_unnamed_addr #0 {
|
||||
%2 = mul nsw i32 %0, %0
|
||||
ret i32 %2
|
||||
%2 = mul nsw i32 %0, %0
|
||||
ret i32 %2
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ implementation
|
||||
|
||||
function Square(const num: Integer): Integer;
|
||||
begin
|
||||
Square := num * num;
|
||||
Square := num * num;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Type your code here, or load an example.
|
||||
pub fn square(num: i32) -> i32 {
|
||||
num * num
|
||||
num * num
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ function Ast(hub, container, state) {
|
||||
this.astEditor = monaco.editor.create(this.domRoot.find(".monaco-placeholder")[0], {
|
||||
value: "",
|
||||
scrollBeyondLastLine: false,
|
||||
language: 'text',
|
||||
language: 'plaintext',
|
||||
readOnly: true,
|
||||
glyphMargin: true,
|
||||
fontFamily: 'Consolas, "Liberation Mono", Courier, monospace',
|
||||
@@ -94,17 +94,23 @@ Ast.prototype.resize = function () {
|
||||
};
|
||||
|
||||
Ast.prototype.onCompileResult = function (id, compiler, result, lang) {
|
||||
if (this._compilerid === id) {
|
||||
if (result.hasAstOutput) {
|
||||
this.showAstResults(result.astOutput);
|
||||
}
|
||||
else {
|
||||
this.showAstResults("<No output>");
|
||||
}
|
||||
if (lang && lang.monaco) {
|
||||
monaco.editor.setModelLanguage(this.astEditor.getModel(), lang.monaco);
|
||||
}
|
||||
if (this._compilerid !== id) return;
|
||||
|
||||
if (result.hasAstOutput) {
|
||||
this.showAstResults(result.astOutput);
|
||||
}
|
||||
else {
|
||||
this.showAstResults("<No output>");
|
||||
}
|
||||
|
||||
if (lang && lang.monaco && this.getCurrentEditorLanguage() !== lang.monaco) {
|
||||
monaco.editor.setModelLanguage(this.astEditor.getModel(), lang.monaco);
|
||||
}
|
||||
};
|
||||
|
||||
// Monaco language id of the current editor
|
||||
Ast.prototype.getCurrentEditorLanguage = function () {
|
||||
return this.astEditor.getModel().getModeId();
|
||||
};
|
||||
|
||||
Ast.prototype.setTitle = function () {
|
||||
|
||||
@@ -194,7 +194,7 @@ GccDump.prototype.onCompileResult = function (id, compiler, result) {
|
||||
if (result.hasGccDumpOutput && result.gccDumpOutput.syntaxHighlight) {
|
||||
monaco.editor.setModelLanguage(this.gccDumpEditor.getModel(), 'gccdump-rtl-gimple');
|
||||
} else {
|
||||
monaco.editor.setModelLanguage(this.gccDumpEditor.getModel(), 'text');
|
||||
monaco.editor.setModelLanguage(this.gccDumpEditor.getModel(), 'plaintext');
|
||||
}
|
||||
|
||||
if (result.hasGccDumpOutput) {
|
||||
|
||||
@@ -43,7 +43,7 @@ function Opt(hub, container, state) {
|
||||
this.optEditor = monaco.editor.create(this.domRoot.find(".monaco-placeholder")[0], {
|
||||
value: this.code,
|
||||
scrollBeyondLastLine: false,
|
||||
language: 'text',
|
||||
language: 'plaintext',
|
||||
readOnly: true,
|
||||
glyphMargin: true,
|
||||
quickSuggestions: false,
|
||||
@@ -101,12 +101,18 @@ Opt.prototype.initCallbacks = function () {
|
||||
};
|
||||
|
||||
Opt.prototype.onCompileResult = function (id, compiler, result, lang) {
|
||||
if (result.hasOptOutput && this._compilerid === id) {
|
||||
if (this._compilerid !== id) return;
|
||||
if (result.hasOptOutput) {
|
||||
this.showOptResults(result.optOutput);
|
||||
if (lang && lang.monaco) {
|
||||
monaco.editor.setModelLanguage(this.optEditor.getModel(), lang.monaco);
|
||||
}
|
||||
}
|
||||
if (lang && lang.monaco && this.getCurrentEditorLanguage() !== lang.monaco) {
|
||||
monaco.editor.setModelLanguage(this.optEditor.getModel(), lang.monaco);
|
||||
}
|
||||
};
|
||||
|
||||
// Monaco language id of the current editor
|
||||
Opt.prototype.getCurrentEditorLanguage = function () {
|
||||
return this.optEditor.getModel().getModeId();
|
||||
};
|
||||
|
||||
Opt.prototype.setTitle = function () {
|
||||
|
||||
Reference in New Issue
Block a user