Skip to content

Commit

Permalink
! Made syntax highlight compatible with VS 15.7
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed May 9, 2018
1 parent 337b581 commit 1a2853d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 54 deletions.
99 changes: 47 additions & 52 deletions Codist/Classifiers/CSharpClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,61 +77,56 @@ public IList<ClassificationSpan> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion Codist/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 1 addition & 1 deletion Codist/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="Codist.WMJ.c7b93d20-621f-4b21-9d28-d51157ef0b94" Version="2.8.0.1000" Language="en-US" Publisher="WMJ" />
<Identity Id="Codist.WMJ.c7b93d20-621f-4b21-9d28-d51157ef0b94" Version="2.8.0.1006" Language="en-US" Publisher="WMJ" />
<DisplayName>Codist</DisplayName>
<Description xml:space="preserve">A plugin which enhances coding experience with advanced syntax highlighting, scrollbar marking and Super Quick Info for C# programmers.</Description>
<MoreInfo>https://github.com/wmjordan/Codist</MoreInfo>
Expand Down

0 comments on commit 1a2853d

Please sign in to comment.