Skip to content

Commit c04b54d

Browse files
committed
Enabled dynamic IL coloring in Code Runner.
Refactored the CodeRunner to automatically apply 'il' coloring when a C# compiler that generates IL code is selected.
1 parent 6267151 commit c04b54d

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/CodeSnip/Views/CodeRunnerView/CodeRunnerViewModel.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ public partial class CodeRunnerViewModel : ObservableObject
6666

6767
public CodeRunnerViewModel(string languageExtension, string code, Func<string> getLatestCode)
6868
{
69-
// Set the highlighting name based on the source language extension
70-
AsmHighlightingName = MapLanguageExtensionToAsmHighlighting(languageExtension);
7169
Compilers = _compilersSettings.GetCompilersByExtension(languageExtension);
7270
var defaultCompilerId = _compilersSettings.GetDefaultCompilerIdByExtension(languageExtension);
7371
SelectedCompiler = Compilers.FirstOrDefault(c => c.Id == defaultCompilerId) ?? Compilers.FirstOrDefault();
@@ -79,20 +77,30 @@ public CodeRunnerViewModel(string languageExtension, string code, Func<string> g
7977
}
8078

8179
// This method maps the source language extension to the appropriate assembly highlighting definition name.
82-
private static string MapLanguageExtensionToAsmHighlighting(string languageExtension)
80+
private static string MapLanguageExtensionToAsmHighlighting(string languageExtension, CompilerInfo? compiler)
8381
{
82+
if (languageExtension.Equals("cs", StringComparison.OrdinalIgnoreCase) &&
83+
compiler?.Id?.Contains("ildasm", StringComparison.OrdinalIgnoreCase) == true)
84+
{
85+
return "il";
86+
}
87+
8488
return languageExtension.ToLowerInvariant() switch
8589
{
86-
//"cs" => "il",
90+
8791
"java" => "java-bytecode",
88-
"py" => "python-bytecode",
8992
_ => "asm", // Default for C++, Rust, D, etc.
9093
};
9194
}
9295

93-
partial void OnSelectedCompilerChanged(CompilerInfo? value)
96+
partial void OnSelectedCompilerChanged(CompilerInfo? oldValue, CompilerInfo? newValue)
9497
{
95-
Flags = value?.Flags ?? "";
98+
Flags = newValue?.Flags ?? "";
99+
AsmHighlightingName = MapLanguageExtensionToAsmHighlighting(Extension, newValue);
100+
// clear previous outputs
101+
AsmCode = "";
102+
StdOut = "";
103+
ErrorText = "";
96104
}
97105

98106
private bool CanExecuteCompilerActions()

0 commit comments

Comments
 (0)