@@ -59,7 +59,7 @@ public Task Html()
59
59
{
60
60
Diagnostics =
61
61
[
62
- new Diagnostic
62
+ new LspDiagnostic
63
63
{
64
64
Code = "HTM1337" ,
65
65
Range = SourceText . From ( input . Text ) . GetRange ( input . NamedSpans . First ( ) . Value . First ( ) )
@@ -95,12 +95,12 @@ public Task FilterEscapedAtFromCss()
95
95
{
96
96
Diagnostics =
97
97
[
98
- new Diagnostic
98
+ new LspDiagnostic
99
99
{
100
100
Code = CSSErrorCodes . UnrecognizedBlockType ,
101
101
Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( "@@" ) + 1 , 1 ) )
102
102
} ,
103
- new Diagnostic
103
+ new LspDiagnostic
104
104
{
105
105
Code = CSSErrorCodes . UnrecognizedBlockType ,
106
106
Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( "f" ) , 1 ) )
@@ -109,6 +109,44 @@ public Task FilterEscapedAtFromCss()
109
109
} ] ) ;
110
110
}
111
111
112
+ [ Fact ]
113
+ public Task FilterCSharpFromCss ( )
114
+ {
115
+ TestCode input = """
116
+ <div>
117
+
118
+ <style>
119
+ @{ insertSomeBigBlobOfCSharp(); }
120
+
121
+ {|CSS031:~|}~~~~
122
+ </style>
123
+
124
+ </div>
125
+
126
+ @code {
127
+ string insertSomeBigBlobOfCSharp() => "body { font-weight: bold; }";
128
+ }
129
+ """ ;
130
+
131
+ return VerifyDiagnosticsAsync ( input ,
132
+ htmlResponse : [ new VSInternalDiagnosticReport
133
+ {
134
+ Diagnostics =
135
+ [
136
+ new LspDiagnostic
137
+ {
138
+ Code = CSSErrorCodes . MissingSelectorBeforeCombinatorCode ,
139
+ Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( "@{" ) , 1 ) )
140
+ } ,
141
+ new LspDiagnostic
142
+ {
143
+ Code = CSSErrorCodes . MissingSelectorBeforeCombinatorCode ,
144
+ Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( "~~" ) , 1 ) )
145
+ }
146
+ ]
147
+ } ] ) ;
148
+ }
149
+
112
150
[ Fact ]
113
151
public Task FilterRazorCommentsFromCss ( )
114
152
{
@@ -117,6 +155,8 @@ public Task FilterRazorCommentsFromCss()
117
155
118
156
<style>
119
157
@* This is a Razor comment *@
158
+
159
+ {|CSS031:~|}~~~~
120
160
</style>
121
161
122
162
</div>
@@ -127,10 +167,15 @@ public Task FilterRazorCommentsFromCss()
127
167
{
128
168
Diagnostics =
129
169
[
130
- new Diagnostic
170
+ new LspDiagnostic
131
171
{
132
172
Code = CSSErrorCodes . MissingSelectorBeforeCombinatorCode ,
133
173
Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( "@*" ) , 1 ) )
174
+ } ,
175
+ new LspDiagnostic
176
+ {
177
+ Code = CSSErrorCodes . MissingSelectorBeforeCombinatorCode ,
178
+ Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( "~~" ) , 1 ) )
134
179
}
135
180
]
136
181
} ] ) ;
@@ -144,6 +189,8 @@ public Task FilterRazorCommentsFromCss_Inside()
144
189
145
190
<style>
146
191
@* This is a Razor comment *@
192
+
193
+ {|CSS031:~|}~~~~
147
194
</style>
148
195
149
196
</div>
@@ -154,15 +201,149 @@ public Task FilterRazorCommentsFromCss_Inside()
154
201
{
155
202
Diagnostics =
156
203
[
157
- new Diagnostic
204
+ new LspDiagnostic
158
205
{
159
206
Code = CSSErrorCodes . MissingSelectorBeforeCombinatorCode ,
160
207
Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( "Ra" ) , 1 ) )
208
+ } ,
209
+ new LspDiagnostic
210
+ {
211
+ Code = CSSErrorCodes . MissingSelectorBeforeCombinatorCode ,
212
+ Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( "~~" ) , 1 ) )
161
213
}
162
214
]
163
215
} ] ) ;
164
216
}
165
217
218
+ [ Fact ]
219
+ public Task FilterMissingClassNameInCss ( )
220
+ {
221
+ TestCode input = """
222
+ <div>
223
+
224
+ <style>
225
+ .@(className)
226
+ background-color: lightblue;
227
+ }
228
+
229
+ .{|CSS008:{|}
230
+ bar: baz;
231
+ }
232
+ </style>
233
+
234
+ </div>
235
+
236
+ @code
237
+ {
238
+ private string className = "foo";
239
+ }
240
+ """ ;
241
+
242
+ return VerifyDiagnosticsAsync ( input ,
243
+ htmlResponse : [ new VSInternalDiagnosticReport
244
+ {
245
+ Diagnostics =
246
+ [
247
+ new LspDiagnostic
248
+ {
249
+ Code = CSSErrorCodes . MissingClassNameAfterDot ,
250
+ Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( ".@" ) + 1 , 1 ) )
251
+ } ,
252
+ new LspDiagnostic
253
+ {
254
+ Code = CSSErrorCodes . MissingClassNameAfterDot ,
255
+ Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( ".{" ) + 1 , 1 ) )
256
+ } ,
257
+ ]
258
+ } ] ) ;
259
+ }
260
+
261
+ [ Fact ]
262
+ public Task FilterMissingClassNameInCss_WithSpace ( )
263
+ {
264
+ TestCode input = """
265
+ <div>
266
+
267
+ <style>
268
+ . @(className)
269
+ background-color: lightblue;
270
+ }
271
+
272
+ .{|CSS008: |}{
273
+ bar: baz;
274
+ }
275
+ </style>
276
+
277
+ </div>
278
+
279
+ @code
280
+ {
281
+ private string className = "foo";
282
+ }
283
+ """ ;
284
+
285
+ return VerifyDiagnosticsAsync ( input ,
286
+ htmlResponse : [ new VSInternalDiagnosticReport
287
+ {
288
+ Diagnostics =
289
+ [
290
+ new LspDiagnostic
291
+ {
292
+ Code = CSSErrorCodes . MissingClassNameAfterDot ,
293
+ Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( ". @" ) + 1 , 1 ) )
294
+ } ,
295
+ new LspDiagnostic
296
+ {
297
+ Code = CSSErrorCodes . MissingClassNameAfterDot ,
298
+ Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( ". {" ) + 1 , 1 ) )
299
+ } ,
300
+ ]
301
+ } ] ) ;
302
+ }
303
+
304
+ [ Fact ]
305
+ public Task FilterPropertyValueInCss ( )
306
+ {
307
+ TestCode input = """
308
+ <div>
309
+
310
+ <style>
311
+ .goo {
312
+ background-color: @(color);
313
+ }
314
+
315
+ .foo {
316
+ background-color:{|CSS025: |}/* no value here */;
317
+ }
318
+ </style>
319
+
320
+ </div>
321
+
322
+ @code
323
+ {
324
+ private string color = "red";
325
+ }
326
+ """ ;
327
+
328
+ return VerifyDiagnosticsAsync ( input ,
329
+ htmlResponse : [ new VSInternalDiagnosticReport
330
+ {
331
+ Diagnostics =
332
+ [
333
+ new LspDiagnostic
334
+ {
335
+ Code = CSSErrorCodes . MissingPropertyValue ,
336
+ Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( ": @" ) + 1 , 1 ) )
337
+ } ,
338
+ new LspDiagnostic
339
+ {
340
+ Code = CSSErrorCodes . MissingPropertyValue ,
341
+ Range = SourceText . From ( input . Text ) . GetRange ( new TextSpan ( input . Text . IndexOf ( ": /" ) + 1 , 1 ) )
342
+ } ,
343
+ ]
344
+ } ] ) ;
345
+ }
346
+
166
347
[ Fact ]
167
348
public Task CombinedAndNestedDiagnostics ( )
168
349
=> VerifyDiagnosticsAsync ( """
0 commit comments