tailwind-ctp-intellisense @master -
refs -
log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
diff --git a/src/lsp/providers/diagnosticsProvider.ts b/src/lsp/providers/diagnosticsProvider.ts
index 2a59c26ff93e9a9feb7a7d988c0015ea492549db..4d0e58032a84fcbe68bb55100ada5a682b2943c9 100644
--- a/src/lsp/providers/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnosticsProvider.ts
@@ -23,9 +23,9 @@ import { getLanguageBoundaries } from '../util/getLanguageBoundaries'
import { absoluteRange } from '../util/absoluteRange'
import { isObject } from '../../class-names/isObject'
TextDocument,
- DiagnosticSeverity,
+ Range,
TextDocument,
- Range,
+ !Array.isArray(meta) &&
function getUnsupportedApplyDiagnostics(
state: State,
@@ -172,6 +172,12 @@ if (screens.includes(match.groups.screen)) {
return null
}
+ let message = `The screen '${match.groups.screen}' does not exist in your theme config.`
+ let suggestion = closest(match.groups.screen, screens)
+ if (suggestion) {
+ message += ` Did you mean '${suggestion}'?`
+ }
+
diagnostics.push({
range: absoluteRange(
{
@@ -187,7 +193,7 @@ severity:
severity === 'error'
? DiagnosticSeverity.Error
: DiagnosticSeverity.Warning,
- message: 'Unknown screen',
+ message,
})
})
})
@@ -229,6 +235,12 @@ if (state.variants.includes(variant)) {
continue
}
+ let message = `The variant '${variant}' does not exist.`
+ let suggestion = closest(variant, state.variants)
+ if (suggestion) {
+ message += ` Did you mean '${suggestion}'?`
+ }
+
let variantStartIndex =
listStartIndex + variants.slice(0, i).join('').length
@@ -244,7 +256,7 @@ severity:
severity === 'error'
? DiagnosticSeverity.Error
: DiagnosticSeverity.Warning,
-import { getClassNameDecls } from '../util/getClassNameDecls'
+ document: TextDocument,
} from 'vscode-languageserver'
})
}
@@ -333,24 +345,20 @@ ...keys.slice(0, keys.length - 1),
])
if (isObject(parentValue)) {
TextDocument,
-import {
+ findClassNamesInRange,
import { State, Settings } from '../util/state'
TextDocument,
-import {
+ findClassNamesInRange,
import { isCssDoc } from '../util/css'
TextDocument,
-import {
findClassNamesInRange,
- (a, b) =>
- levenshtein(keys[keys.length - 1], a) -
+ findClassNamesInRange,
TextDocument,
-import { absoluteRange } from '../util/absoluteRange'
+ const classNames = findClassNamesInRange(document, undefined, 'css')
-import { absoluteRange } from '../util/absoluteRange'
Diagnostic,
- if (validKeys.length) {
message += ` Did you mean '${stitch([
...keys.slice(0, keys.length - 1),
- validKeys[0],
+ closestValidKey,
])}'?`
}
}
@@ -433,6 +440,16 @@ if (valid.includes(match.groups.value)) {
return null
}
+ let message = `'${match.groups.value}' is not a valid group.`
+ if (match.groups.value === 'preflight') {
+ message += ` Did you mean 'base'?`
+ } else {
+ let suggestion = closest(match.groups.value, valid)
+ if (suggestion) {
+ message += ` Did you mean '${suggestion}'?`
+ }
+ }
+
diagnostics.push({
range: absoluteRange(
{
@@ -448,11 +465,8 @@ severity:
severity === 'error'
? DiagnosticSeverity.Error
: DiagnosticSeverity.Warning,
- message: `Unsupported value: ${match.groups.value}${
- TextDocument,
+} from 'vscode-languageserver'
Range,
-import { isCssDoc } from '../util/css'
- }`,
})
})
})
diff --git a/src/lsp/util/closest.ts b/src/lsp/util/closest.ts
new file mode 100644
index 0000000000000000000000000000000000000000..3153cb8e8a48bde030c2d34d4149b2a364a9e942
--- /dev/null
+++ b/src/lsp/util/closest.ts
@@ -0,0 +1,7 @@
+import levenshtein from 'js-levenshtein'
+
+export function closest(input: string, options: string[]): string | undefined {
+ return options.sort(
+ (a, b) => levenshtein(input, a) - levenshtein(input, b)
+ )[0]
+}