|
1 | 1 | using System;
|
2 | 2 | using System.Threading.Tasks;
|
| 3 | +using System.Windows.Input; |
3 | 4 | using Microsoft.CodeAnalysis.Text;
|
4 | 5 | using OmniSharp.Models.SemanticHighlight;
|
5 | 6 | using OmniSharp.Models.V2;
|
@@ -102,6 +103,93 @@ class C1
|
102 | 103 | );
|
103 | 104 | }
|
104 | 105 |
|
| 106 | + [Fact] |
| 107 | + public async Task SemanticHighlightWithAsyncEnumerable() |
| 108 | + { |
| 109 | + var testFile = new TestFile("a.cs", @" |
| 110 | +class C1 |
| 111 | +{ |
| 112 | + public async Task C2() { |
| 113 | + string s1 = ""hello""; |
| 114 | + await foreach (var x in e) { } |
| 115 | + string s2 = ""world""; |
| 116 | + } |
| 117 | +}"); |
| 118 | + |
| 119 | + var highlights = await GetSemanticHighlightsForFileAsync(testFile); |
| 120 | + |
| 121 | + AssertSyntax(highlights, testFile.Content.Code, 0, |
| 122 | + Keyword("class"), |
| 123 | + ClassName("C1"), |
| 124 | + Punctuation("{"), |
| 125 | + Keyword("public"), |
| 126 | + Keyword("async"), |
| 127 | + Identifier("Task"), |
| 128 | + Method("C2"), |
| 129 | + Punctuation("("), |
| 130 | + Punctuation(")"), |
| 131 | + Punctuation("{"), |
| 132 | + Keyword("string"), |
| 133 | + Local("s1"), |
| 134 | + Operator("="), |
| 135 | + String("\"hello\""), |
| 136 | + Punctuation(";"), |
| 137 | + Keyword("await"), |
| 138 | + ControlKeyword("foreach"), |
| 139 | + Punctuation("("), |
| 140 | + Keyword("var"), |
| 141 | + Local("x"), |
| 142 | + ControlKeyword("in"), |
| 143 | + Identifier("e"), |
| 144 | + Punctuation(")"), |
| 145 | + Punctuation("{"), |
| 146 | + Punctuation("}"), |
| 147 | + Keyword("string"), |
| 148 | + Local("s2"), |
| 149 | + Operator("="), |
| 150 | + String("\"world\""), |
| 151 | + Punctuation(";"), |
| 152 | + Punctuation("}"), |
| 153 | + Punctuation("}") |
| 154 | + ); |
| 155 | + } |
| 156 | + |
| 157 | + [Fact] |
| 158 | + public async Task SemanticHighlightWithNullable() |
| 159 | + { |
| 160 | + var testFile = new TestFile("a.cs", @" |
| 161 | +class C1 |
| 162 | +{ |
| 163 | + string s1 = ""hello""; |
| 164 | + int[]? example; |
| 165 | + string s2 = ""world""; |
| 166 | +}"); |
| 167 | + |
| 168 | + var highlights = await GetSemanticHighlightsForFileAsync(testFile); |
| 169 | + |
| 170 | + AssertSyntax(highlights, testFile.Content.Code, 0, |
| 171 | + Keyword("class"), |
| 172 | + ClassName("C1"), |
| 173 | + Punctuation("{"), |
| 174 | + Keyword("string"), |
| 175 | + Field("s1"), |
| 176 | + Operator("="), |
| 177 | + String("\"hello\""), |
| 178 | + Punctuation(";"), |
| 179 | + Keyword("int"), |
| 180 | + Punctuation("["), |
| 181 | + Punctuation("]"), |
| 182 | + Operator("?"), |
| 183 | + Field("example"), |
| 184 | + Punctuation(";"), |
| 185 | + Keyword("string"), |
| 186 | + Field("s2"), |
| 187 | + Operator("="), |
| 188 | + String("\"world\""), |
| 189 | + Punctuation(";"), |
| 190 | + Punctuation("}") |
| 191 | + ); |
| 192 | + } |
105 | 193 |
|
106 | 194 | [Fact]
|
107 | 195 | public async Task SemanticHighlightStaticModifiers()
|
@@ -208,11 +296,14 @@ private static void AssertSyntax(SemanticHighlightSpan[] highlights, string code
|
208 | 296 | Assert.Equal(expectedTokens.Length, highlights.Length);
|
209 | 297 | }
|
210 | 298 |
|
| 299 | + private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Method(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.MethodName, text, modifiers); |
| 300 | + private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Local(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.LocalName, text, modifiers); |
211 | 301 | private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) ClassName(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.ClassName, text, modifiers);
|
212 | 302 | private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Field(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.FieldName, text, modifiers);
|
213 | 303 | private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Identifier(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Identifier, text, modifiers);
|
214 | 304 | private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) NamespaceName(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.NamespaceName, text, modifiers);
|
215 | 305 | private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Keyword(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Keyword, text, modifiers);
|
| 306 | + private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) ControlKeyword(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.ControlKeyword, text, modifiers); |
216 | 307 | private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Number(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.NumericLiteral, text, modifiers);
|
217 | 308 | private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Operator(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Operator, text, modifiers);
|
218 | 309 | private static (SemanticHighlightClassification type, string text, SemanticHighlightModifier[] modifiers) Punctuation(string text, params SemanticHighlightModifier[] modifiers) => (SemanticHighlightClassification.Punctuation, text, modifiers);
|
|
0 commit comments