@@ -22,8 +22,8 @@ import semver from 'semver'
22
22
import { getLanguageBoundaries } from '../util/getLanguageBoundaries'
23
23
import { absoluteRange } from '../util/absoluteRange'
24
24
import { isObject } from '../../class-names/isObject'
25
- import levenshtein from 'js-levenshtein'
26
25
import { stringToPath } from '../util/stringToPath'
26
+ import { closest } from '../util/closest'
27
27
28
28
function getUnsupportedApplyDiagnostics (
29
29
state : State ,
@@ -170,6 +170,12 @@ function getUnknownScreenDiagnostics(
170
170
return null
171
171
}
172
172
173
+ let message = `The screen '${ match . groups . screen } ' does not exist in your theme config.`
174
+ let suggestion = closest ( match . groups . screen , screens )
175
+ if ( suggestion ) {
176
+ message += ` Did you mean '${ suggestion } '?`
177
+ }
178
+
173
179
diagnostics . push ( {
174
180
range : absoluteRange (
175
181
{
@@ -185,7 +191,7 @@ function getUnknownScreenDiagnostics(
185
191
severity === 'error'
186
192
? DiagnosticSeverity . Error
187
193
: DiagnosticSeverity . Warning ,
188
- message : 'Unknown screen' ,
194
+ message,
189
195
} )
190
196
} )
191
197
} )
@@ -227,6 +233,12 @@ function getUnknownVariantDiagnostics(
227
233
continue
228
234
}
229
235
236
+ let message = `The variant '${ variant } ' does not exist.`
237
+ let suggestion = closest ( variant , state . variants )
238
+ if ( suggestion ) {
239
+ message += ` Did you mean '${ suggestion } '?`
240
+ }
241
+
230
242
let variantStartIndex =
231
243
listStartIndex + variants . slice ( 0 , i ) . join ( '' ) . length
232
244
@@ -242,7 +254,7 @@ function getUnknownVariantDiagnostics(
242
254
severity === 'error'
243
255
? DiagnosticSeverity . Error
244
256
: DiagnosticSeverity . Warning ,
245
- message : `Unknown variant: ${ variant } ` ,
257
+ message,
246
258
} )
247
259
}
248
260
} )
@@ -329,17 +341,14 @@ function getInvalidHelperKeyDiagnostics(
329
341
...keys . slice ( 0 , keys . length - 1 ) ,
330
342
] )
331
343
if ( isObject ( parentValue ) ) {
332
- let validKeys = Object . keys ( parentValue )
333
- . filter ( ( key ) => isValid ( parentValue [ key ] ) )
334
- . sort (
335
- ( a , b ) =>
336
- levenshtein ( keys [ keys . length - 1 ] , a ) -
337
- levenshtein ( keys [ keys . length - 1 ] , b )
338
- )
339
- if ( validKeys . length ) {
344
+ let closestValidKey = closest (
345
+ keys [ keys . length - 1 ] ,
346
+ Object . keys ( parentValue ) . filter ( ( key ) => isValid ( parentValue [ key ] ) )
347
+ )
348
+ if ( closestValidKey ) {
340
349
message += ` Did you mean '${ stitch ( [
341
350
...keys . slice ( 0 , keys . length - 1 ) ,
342
- validKeys [ 0 ] ,
351
+ closestValidKey ,
343
352
] ) } '?`
344
353
}
345
354
}
@@ -422,6 +431,16 @@ function getUnsupportedTailwindDirectiveDiagnostics(
422
431
return null
423
432
}
424
433
434
+ let message = `'${ match . groups . value } ' is not a valid group.`
435
+ if ( match . groups . value === 'preflight' ) {
436
+ message += ` Did you mean 'base'?`
437
+ } else {
438
+ let suggestion = closest ( match . groups . value , valid )
439
+ if ( suggestion ) {
440
+ message += ` Did you mean '${ suggestion } '?`
441
+ }
442
+ }
443
+
425
444
diagnostics . push ( {
426
445
range : absoluteRange (
427
446
{
@@ -437,9 +456,7 @@ function getUnsupportedTailwindDirectiveDiagnostics(
437
456
severity === 'error'
438
457
? DiagnosticSeverity . Error
439
458
: DiagnosticSeverity . Warning ,
440
- message : `Unsupported value: ${ match . groups . value } ${
441
- match . groups . value === 'preflight' ? '. Use base instead.' : ''
442
- } `,
459
+ message,
443
460
} )
444
461
} )
445
462
} )
0 commit comments