mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Add tab "completion" for the server-side C# console (#2176)
This commit is contained in:
@@ -28,7 +28,7 @@ namespace Robust.Shared.Scripting
|
||||
private static readonly Func<Script, bool> _hasReturnValue;
|
||||
private static readonly Func<Diagnostic, IReadOnlyList<object?>?> _getDiagnosticArguments;
|
||||
|
||||
private static readonly string[] _defaultImports =
|
||||
public static readonly string[] DefaultImports =
|
||||
{
|
||||
"System",
|
||||
"System.Linq",
|
||||
@@ -101,6 +101,24 @@ namespace Robust.Shared.Scripting
|
||||
return _getDiagnosticArguments(diag);
|
||||
}
|
||||
|
||||
public static readonly Dictionary<string, Color> ColorScheme = new()
|
||||
{
|
||||
{ClassificationTypeNames.ClassName, Color.FromHex("#4EC9B0")},
|
||||
{ClassificationTypeNames.Comment, Color.FromHex("#57A64A")},
|
||||
{ClassificationTypeNames.EnumName, Color.FromHex("#B8D7A3")},
|
||||
{ClassificationTypeNames.FieldName, Color.FromHex("#C86E11")},
|
||||
{ClassificationTypeNames.InterfaceName, Color.FromHex("#B8D7A3")},
|
||||
{ClassificationTypeNames.Keyword, Color.FromHex("#569CD6")},
|
||||
{ClassificationTypeNames.MethodName, Color.FromHex("#11A3C8")},
|
||||
{ClassificationTypeNames.NamespaceName, Color.FromHex("#C8A611")},
|
||||
{ClassificationTypeNames.NumericLiteral, Color.FromHex("#b5cea8")},
|
||||
{ClassificationTypeNames.PropertyName, Color.FromHex("#11C89D")},
|
||||
{ClassificationTypeNames.StaticSymbol, Color.FromHex("#4EC9B0")},
|
||||
{ClassificationTypeNames.StringLiteral, Color.FromHex("#D69D85")},
|
||||
{ClassificationTypeNames.StructName, Color.FromHex("#4EC9B0")},
|
||||
{"default", Color.FromHex("#D4D4D4")},
|
||||
};
|
||||
|
||||
public static void AddWithSyntaxHighlighting(Script script, FormattedMessage msg, string code,
|
||||
Workspace workspace)
|
||||
{
|
||||
@@ -126,19 +144,8 @@ namespace Robust.Shared.Scripting
|
||||
// TODO: there are probably issues with multiple classifications overlapping the same text here.
|
||||
// Too lazy to fix.
|
||||
var src = code[span.TextSpan.Start..span.TextSpan.End];
|
||||
var color = span.ClassificationType switch
|
||||
{
|
||||
ClassificationTypeNames.Comment => Color.FromHex("#57A64A"),
|
||||
ClassificationTypeNames.NumericLiteral => Color.FromHex("#b5cea8"),
|
||||
ClassificationTypeNames.StringLiteral => Color.FromHex("#D69D85"),
|
||||
ClassificationTypeNames.Keyword => Color.FromHex("#569CD6"),
|
||||
ClassificationTypeNames.StaticSymbol => Color.FromHex("#4EC9B0"),
|
||||
ClassificationTypeNames.ClassName => Color.FromHex("#4EC9B0"),
|
||||
ClassificationTypeNames.StructName => Color.FromHex("#4EC9B0"),
|
||||
ClassificationTypeNames.InterfaceName => Color.FromHex("#B8D7A3"),
|
||||
ClassificationTypeNames.EnumName => Color.FromHex("#B8D7A3"),
|
||||
_ => Color.FromHex("#D4D4D4")
|
||||
};
|
||||
if (!ColorScheme.TryGetValue(span.ClassificationType, out var color))
|
||||
color = ColorScheme["default"];
|
||||
|
||||
msg.PushColor(color);
|
||||
msg.AddText(src);
|
||||
@@ -218,7 +225,7 @@ namespace Robust.Shared.Scripting
|
||||
public static ScriptOptions GetScriptOptions(IReflectionManager reflectionManager)
|
||||
{
|
||||
return ScriptOptions.Default
|
||||
.AddImports(_defaultImports)
|
||||
.AddImports(DefaultImports)
|
||||
.AddReferences(GetDefaultReferences(reflectionManager));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user