Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle RecordStructName in semantic highlighting classification #2232

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ private static SemanticHighlightSpan CreateSemanticSpan(IEnumerable<ClassifiedRe

var linePos = lines.GetLinePositionSpan(span.TextSpan);

var type = SemanticHighlightClassification.Text;
_classificationMap.TryGetValue(span.ClassificationType, out type);

return new SemanticHighlightSpan
{
StartLine = linePos.Start.Line,
EndLine = linePos.End.Line,
StartColumn = linePos.Start.Character,
EndColumn = linePos.End.Character,
Type = _classificationMap[span.ClassificationType],
Type = type,
Modifiers = modifiers
};
}
Expand All @@ -100,7 +103,7 @@ class ClassifiedResult
}

private static readonly Dictionary<string, SemanticHighlightClassification> _classificationMap =
new Dictionary<string, SemanticHighlightClassification>
new()
{
[ClassificationTypeNames.Comment] = SemanticHighlightClassification.Comment,
[ClassificationTypeNames.ExcludedCode] = SemanticHighlightClassification.ExcludedCode,
Expand All @@ -126,6 +129,7 @@ class ClassifiedResult
[ClassificationTypeNames.InterfaceName] = SemanticHighlightClassification.InterfaceName,
[ClassificationTypeNames.ModuleName] = SemanticHighlightClassification.ModuleName,
[ClassificationTypeNames.StructName] = SemanticHighlightClassification.StructName,
[ClassificationTypeNames.RecordStructName] = SemanticHighlightClassification.StructName,
[ClassificationTypeNames.TypeParameterName] = SemanticHighlightClassification.TypeParameterName,
[ClassificationTypeNames.FieldName] = SemanticHighlightClassification.FieldName,
[ClassificationTypeNames.EnumMemberName] = SemanticHighlightClassification.EnumMemberName,
Expand Down Expand Up @@ -171,7 +175,7 @@ class ClassifiedResult
};

private static readonly Dictionary<string, SemanticHighlightModifier> _modifierMap =
new Dictionary<string, SemanticHighlightModifier>
new()
{
[ClassificationTypeNames.StaticSymbol] = SemanticHighlightModifier.Static,
};
Expand Down
40 changes: 40 additions & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/SemanticHighlightFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,45 @@ record R1(string S, int I);
);
}

[Fact]
public async Task SemanticHighlightRecordStructName()
{
var testFile = new TestFile("a.cs", @"
R1 r1 = new R1(string.Empty, 1);
record struct R1(string S, int I);
");

var highlights = await GetSemanticHighlightsForFileAsync(testFile);

AssertSyntax(highlights, testFile.Content.Code, 0,
StructName("R1"),
Local("r1"),
Operator("="),
Keyword("new"),
StructName("R1"),
Punctuation("("),
Keyword("string"),
Operator("."),
Field("Empty", SemanticHighlightModifier.Static),
Punctuation(","),
Number("1"),
Punctuation(")"),
Punctuation(";"),

Keyword("record"),
Keyword("struct"),
StructName("R1"),
Punctuation("("),
Keyword("string"),
Parameter("S"),
Punctuation(","),
Keyword("int"),
Parameter("I"),
Punctuation(")"),
Punctuation(";")
);
}

private Task<SemanticHighlightSpan[]> GetSemanticHighlightsForFileAsync(TestFile testFile)
{
return GetSemanticHighlightsAsync(testFile, range: null);
Expand Down Expand Up @@ -352,6 +391,7 @@ private static void AssertSyntax(SemanticHighlightSpan[] highlights, string code
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Method(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.MethodName, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Local(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.LocalName, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) ClassName(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.ClassName, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) StructName(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.StructName, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Field(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.FieldName, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Identifier(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Identifier, text, modifiers);
private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Parameter(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.ParameterName, text, modifiers);
Expand Down