From 1a2853dd38776ccf4bdc56b93a33ef48768d63a9 Mon Sep 17 00:00:00 2001 From: WMJ Date: Wed, 9 May 2018 20:10:13 +0800 Subject: [PATCH] ! Made syntax highlight compatible with VS 15.7 --- Codist/Classifiers/CSharpClassifier.cs | 99 ++++++++++++-------------- Codist/Properties/AssemblyInfo.cs | 2 +- Codist/source.extension.vsixmanifest | 2 +- 3 files changed, 49 insertions(+), 54 deletions(-) diff --git a/Codist/Classifiers/CSharpClassifier.cs b/Codist/Classifiers/CSharpClassifier.cs index f057f819..914f37c1 100644 --- a/Codist/Classifiers/CSharpClassifier.cs +++ b/Codist/Classifiers/CSharpClassifier.cs @@ -77,61 +77,56 @@ public IList GetClassificationSpans(SnapshotSpan span) { var textSpan = new TextSpan(span.Start.Position, span.Length); var unitCompilation = semanticModel.SyntaxTree.GetCompilationUnitRoot(); - var classifiedSpans = Classifier.GetClassifiedSpans(semanticModel, textSpan, workspace) - .Where(item => { - var ct = item.ClassificationType; - if (ct == "keyword") { - // highlights: return, yield return, yield break, throw and continue - var node = unitCompilation.FindNode(item.TextSpan, true, true); - const SyntaxKind ThrowExpression = (SyntaxKind)9052; - switch (node.Kind()) { - case SyntaxKind.BreakStatement: - if (node.Parent is SwitchSectionSyntax == false) { - goto case SyntaxKind.ReturnStatement; - } - return false; - case SyntaxKind.ReturnKeyword: - case SyntaxKind.GotoCaseStatement: - case SyntaxKind.GotoDefaultStatement: - case SyntaxKind.ContinueStatement: - case SyntaxKind.ReturnStatement: - case SyntaxKind.YieldReturnStatement: - case SyntaxKind.YieldBreakStatement: - case SyntaxKind.ThrowStatement: - case ThrowExpression: - result.Add(CreateClassificationSpan(snapshot, item.TextSpan, _Classifications.ControlFlowKeyword)); - return false; - } - return false; - } - if (Config.Instance.SpecialHighlightOptions.MatchFlags(SpecialHighlightOptions.XmlDocCode) - && ct == Constants.XmlDocCData) { - ct = HighlightXmlDocCData(span, item, workspace, result, ct); - return false; - } - if (ct == Constants.CodePunctuation && item.TextSpan.Length == 1) { - HighlightPunctuation(item, snapshot, result, semanticModel, unitCompilation); - return false; - } - - return ct == Constants.CodeIdentifier - || ct == Constants.CodeClassName - || ct == Constants.CodeStructName - || ct == Constants.CodeInterfaceName - || ct == Constants.CodeEnumName - || ct == Constants.CodeTypeParameterName - || ct == Constants.CodeDelegateName; - }); - + var classifiedSpans = Classifier.GetClassifiedSpans(semanticModel, textSpan, workspace); foreach (var item in classifiedSpans) { - var itemSpan = item.TextSpan; - var node = unitCompilation.FindNode(itemSpan, true); - - foreach (var type in GetClassificationType(node, semanticModel)) { - result.Add(CreateClassificationSpan(snapshot, itemSpan, type)); + var ct = item.ClassificationType; + switch (ct) { + case "keyword": { + // highlights: return, yield return, yield break, throw and continue + var node = unitCompilation.FindNode(item.TextSpan, true, true); + const SyntaxKind ThrowExpression = (SyntaxKind)9052; + switch (node.Kind()) { + case SyntaxKind.BreakStatement: + if (node.Parent is SwitchSectionSyntax == false) { + goto case SyntaxKind.ReturnStatement; + } + continue; + case SyntaxKind.ReturnKeyword: + case SyntaxKind.GotoCaseStatement: + case SyntaxKind.GotoDefaultStatement: + case SyntaxKind.ContinueStatement: + case SyntaxKind.ReturnStatement: + case SyntaxKind.YieldReturnStatement: + case SyntaxKind.YieldBreakStatement: + case SyntaxKind.ThrowStatement: + case ThrowExpression: + result.Add(CreateClassificationSpan(snapshot, item.TextSpan, _Classifications.ControlFlowKeyword)); + continue; + } + } + continue; + case Constants.XmlDocCData: + if (Config.Instance.SpecialHighlightOptions.MatchFlags(SpecialHighlightOptions.XmlDocCode)) { + ct = HighlightXmlDocCData(span, item, workspace, result, ct); + } + continue; + case Constants.CodePunctuation: + if (item.TextSpan.Length == 1) { + HighlightPunctuation(item, snapshot, result, semanticModel, unitCompilation); + } + continue; + default: if (ct == Constants.CodeIdentifier + || ct.EndsWith("name", StringComparison.Ordinal)) + { + var itemSpan = item.TextSpan; + var node = unitCompilation.FindNode(itemSpan, true); + foreach (var type in GetClassificationType(node, semanticModel)) { + result.Add(CreateClassificationSpan(snapshot, itemSpan, type)); + } + } + break; } } - return result; } diff --git a/Codist/Properties/AssemblyInfo.cs b/Codist/Properties/AssemblyInfo.cs index b9098247..50a35e7a 100644 --- a/Codist/Properties/AssemblyInfo.cs +++ b/Codist/Properties/AssemblyInfo.cs @@ -30,4 +30,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("2.8.0.0")] -[assembly: AssemblyFileVersion("2.8.0.1003")] +[assembly: AssemblyFileVersion("2.8.0.1011")] diff --git a/Codist/source.extension.vsixmanifest b/Codist/source.extension.vsixmanifest index 70c863e8..70b0ceba 100644 --- a/Codist/source.extension.vsixmanifest +++ b/Codist/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + Codist A plugin which enhances coding experience with advanced syntax highlighting, scrollbar marking and Super Quick Info for C# programmers. https://github.com/wmjordan/Codist