From 8a8aae6754a75a2c6cc3124f716569876a89086d Mon Sep 17 00:00:00 2001 From: LEGION13900KF Date: Wed, 27 Aug 2025 18:32:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85control=20flow=20keywords?= =?UTF-8?q?=E7=9A=84=E9=A2=9C=E8=89=B2=E8=AE=BE=E7=BD=AE=EF=BC=8C=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E4=B8=BA=E6=A9=98=E7=BA=A2=E3=80=82=E5=85=B7=E4=BD=93?= =?UTF-8?q?=E5=8C=85=E6=8B=AC=20if=20else=20while=20do=20for=20freach=20sw?= =?UTF-8?q?itch=20break=20continue=20return=20goto=20throw=20yield?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ClassificationTypes.cs | 54 ++++++++++- FormatDefinitions.cs | 197 ++++++++++++++++++++++++++++++++++++++++- Tagger.cs | 17 +++- 3 files changed, 264 insertions(+), 4 deletions(-) diff --git a/ClassificationTypes.cs b/ClassificationTypes.cs index b20eb71..f7bccc8 100644 --- a/ClassificationTypes.cs +++ b/ClassificationTypes.cs @@ -43,5 +43,57 @@ internal static class ClassificationTypes [Export(typeof(ClassificationTypeDefinition))] [Name("modifier - static")] internal static ClassificationTypeDefinition StaticModifierType = null; - + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - if")] + internal static ClassificationTypeDefinition ControlFlowIfType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - else")] + internal static ClassificationTypeDefinition ControlFlowElseType = null; + + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - while")] + internal static ClassificationTypeDefinition ControlFlowWhileType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - do")] + internal static ClassificationTypeDefinition ControlFlowDoType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - switch")] + internal static ClassificationTypeDefinition ControlFlowSwitchType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - break")] + internal static ClassificationTypeDefinition ControlFlowBreakType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - continue")] + internal static ClassificationTypeDefinition ControlFlowContinueType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - for")] + internal static ClassificationTypeDefinition ControlFlowForType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - foreach")] + internal static ClassificationTypeDefinition ControlFlowForeachType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - return")] + internal static ClassificationTypeDefinition ControlFlowReturnType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - goto")] + internal static ClassificationTypeDefinition ControlFlowGotoType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - throw")] + internal static ClassificationTypeDefinition ControlFlowThrowType = null; + + [Export(typeof(ClassificationTypeDefinition))] + [Name("control flow - yield")] + internal static ClassificationTypeDefinition ControlFlowYieldType = null; } \ No newline at end of file diff --git a/FormatDefinitions.cs b/FormatDefinitions.cs index 0059ec4..13bf5a5 100644 --- a/FormatDefinitions.cs +++ b/FormatDefinitions.cs @@ -138,4 +138,199 @@ public StaticModifierFormat() DisplayName = "C# Modifier - Static"; ForegroundColor = Colors.Gray; } -} \ No newline at end of file +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - if")] +[Name("Control Flow If Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowIfFormat : ClassificationFormatDefinition +{ + public ControlFlowIfFormat() + { + DisplayName = "C# Control Flow - if"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - else")] +[Name("Control Flow Else Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowElseFormat : ClassificationFormatDefinition +{ + public ControlFlowElseFormat() + { + DisplayName = "C# Control Flow - else"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - while")] +[Name("Control Flow While Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowWhileFormat : ClassificationFormatDefinition +{ + public ControlFlowWhileFormat() + { + DisplayName = "C# Control Flow - while"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - do")] +[Name("Control Flow Do Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowDoFormat : ClassificationFormatDefinition +{ + public ControlFlowDoFormat() + { + DisplayName = "C# Control Flow - do"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - for")] +[Name("Control Flow For Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowForFormat : ClassificationFormatDefinition +{ + public ControlFlowForFormat() + { + DisplayName = "C# Control Flow - for"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - foreach")] +[Name("Control Flow Foreach Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowForeachFormat : ClassificationFormatDefinition +{ + public ControlFlowForeachFormat() + { + DisplayName = "C# Control Flow - foreach"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - switch")] +[Name("Control Flow Switch Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowSwitchFormat : ClassificationFormatDefinition +{ + public ControlFlowSwitchFormat() + { + DisplayName = "C# Control Flow - switch"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - break")] +[Name("Control Flow Break Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowBreakFormat : ClassificationFormatDefinition +{ + public ControlFlowBreakFormat() + { + DisplayName = "C# Control Flow - break"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - continue")] +[Name("Control Flow Continue Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowContinueFormat : ClassificationFormatDefinition +{ + public ControlFlowContinueFormat() + { + DisplayName = "C# Control Flow - continue"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - return")] +[Name("Control Flow Return Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowReturnFormat : ClassificationFormatDefinition +{ + public ControlFlowReturnFormat() + { + DisplayName = "C# Control Flow - return"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - goto")] +[Name("Control Flow Goto Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowGotoFormat : ClassificationFormatDefinition +{ + public ControlFlowGotoFormat() + { + DisplayName = "C# Control Flow - goto"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - throw")] +[Name("Control Flow Throw Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowThrowFormat : ClassificationFormatDefinition +{ + public ControlFlowThrowFormat() + { + DisplayName = "C# Control Flow - throw"; + ForegroundColor = Colors.OrangeRed; + } +} + +[Export(typeof(EditorFormatDefinition))] +[ClassificationType(ClassificationTypeNames = "control flow - yield")] +[Name("Control Flow Yield Format")] +[UserVisible(true)] +[Priority(9999)] +[Order(After = Priority.High)] +internal sealed class ControlFlowYieldFormat : ClassificationFormatDefinition +{ + public ControlFlowYieldFormat() + { + DisplayName = "C# Control Flow - yield"; + ForegroundColor = Colors.OrangeRed; + } +} diff --git a/Tagger.cs b/Tagger.cs index daf86d2..365c528 100644 --- a/Tagger.cs +++ b/Tagger.cs @@ -27,10 +27,23 @@ public Tagger(ITextBuffer buffer, IClassificationTypeRegistryService registry, I ["abstract"] = registry.GetClassificationType("modifier - abstract"), ["sealed"] = registry.GetClassificationType("modifier - sealed"), ["override"] = registry.GetClassificationType("modifier - override"), - ["static"] = registry.GetClassificationType("modifier - static") + ["static"] = registry.GetClassificationType("modifier - static"), + ["if"] = registry.GetClassificationType("control flow - if"), + ["else"] = registry.GetClassificationType("control flow - else"), + ["while"] = registry.GetClassificationType("control flow - while"), + ["do"] = registry.GetClassificationType("control flow - do"), + ["for"] = registry.GetClassificationType("control flow - for"), + ["foreach"] = registry.GetClassificationType("control flow - foreach"), + ["switch"] = registry.GetClassificationType("control flow - switch"), + ["break"] = registry.GetClassificationType("control flow - break"), + ["continue"] = registry.GetClassificationType("control flow - continue"), + ["return"] = registry.GetClassificationType("control flow - return"), + ["goto"] = registry.GetClassificationType("control flow - goto"), + ["throw"] = registry.GetClassificationType("control flow - throw"), + ["yield"] = registry.GetClassificationType("control flow - yield"), }; _lineStartRegex = new Regex($@"^\s*({string.Join("|", _modifierMap.Keys)}|\[)", RegexOptions.IgnoreCase | RegexOptions.Compiled); - } + } public IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans) {