diff --git a/src/lsp/providers/codeActionProvider/index.ts b/src/lsp/providers/codeActionProvider/index.ts index 6ae4bf984ee3310f28f8a627347c6b54b8ad140c..5bced1dd72db162e0e77354f2d931bcdf89927a5 100644 --- a/src/lsp/providers/codeActionProvider/index.ts +++ b/src/lsp/providers/codeActionProvider/index.ts @@ -24,10 +24,6 @@ AugmentedDiagnostic, InvalidApplyDiagnostic, isUtilityConflictsDiagnostic, UtilityConflictsDiagnostic, - isInvalidConfigPathDiagnostic, - isInvalidTailwindDirectiveDiagnostic, - isInvalidScreenDiagnostic, - isInvalidVariantDiagnostic, } from '../diagnostics/types' import { flatten, dedupeBy } from '../../../util/array' import { joinWithAnd } from '../../util/joinWithAnd' @@ -76,14 +72,18 @@ if (isUtilityConflictsDiagnostic(diagnostic)) { return provideUtilityConflictsCodeActions(state, params, diagnostic) } - if ( - isInvalidConfigPathDiagnostic(diagnostic) || - isInvalidTailwindDirectiveDiagnostic(diagnostic) || - isInvalidScreenDiagnostic(diagnostic) || - isInvalidVariantDiagnostic(diagnostic) - ) { - return diagnostic.suggestions.map((suggestion) => ({ - title: `Replace with '${suggestion}'`, + let match = findLast( + / Did you mean (?:something like )?'(?[^']+)'\?$/g, + diagnostic.message + ) + + if (!match) { + return [] + } + + return [ + { + title: `Replace with '${match.groups.replacement}'`, kind: CodeActionKind.QuickFix, diagnostics: [diagnostic], edit: { @@ -91,15 +91,13 @@ changes: { [params.textDocument.uri]: [ { range: diagnostic.range, - newText: suggestion, + newText: match.groups.replacement, }, ], }, }, - })) - } - - return [] + }, + ] }) return Promise.all(actions) diff --git a/src/lsp/providers/diagnostics/diagnosticsProvider.ts b/src/lsp/providers/diagnostics/diagnosticsProvider.ts index 91ca0e3eedd6db523fbaf2a96198b659330771ab..1c98a391dfe30bdfd994e1c474d0c5251b6fdc42 100644 --- a/src/lsp/providers/diagnostics/diagnosticsProvider.ts +++ b/src/lsp/providers/diagnostics/diagnosticsProvider.ts @@ -197,11 +197,8 @@ return null } let message = `The screen '${match.groups.screen}' does not exist in your theme config.` - let suggestions: string[] = [] let suggestion = closest(match.groups.screen, screens) - if (suggestion) { - suggestions.push(suggestion) message += ` Did you mean '${suggestion}'?` } @@ -222,7 +219,6 @@ severity === 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning, message, - suggestions, }) }) }) @@ -265,11 +261,8 @@ continue } let message = `The variant '${variant}' does not exist.` - let suggestions: string[] = [] let suggestion = closest(variant, state.variants) - if (suggestion) { - suggestions.push(suggestion) message += ` Did you mean '${suggestion}'?` } @@ -290,7 +283,6 @@ severity === 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning, message, - suggestions, }) } }) @@ -345,7 +337,6 @@ return `${acc}.${cur}` }, '') let message: string - let suggestions: string[] = [] if (isValid(value)) { // The value resolves successfully, but we need to check that there @@ -383,24 +374,24 @@ keys[keys.length - 1], Object.keys(parentValue).filter((key) => isValid(parentValue[key])) ) if (closestValidKey) { - suggestions.push( - stitch([...keys.slice(0, keys.length - 1), closestValidKey]) - ) - message += ` Did you mean '${suggestions[0]}'?` + message += ` Did you mean '${stitch([ + ...keys.slice(0, keys.length - 1), + closestValidKey, + ])}'?` } } } else { message = `'${match.groups.key}' was found but does not resolve to a string.` if (isObject(value)) { - let validKeys = Object.keys(value).filter((key) => + let firstValidKey = Object.keys(value).find((key) => isValid(value[key]) ) - if (validKeys.length) { - suggestions.push( - ...validKeys.map((validKey) => stitch([...keys, validKey])) - ) - message += ` Did you mean something like '${suggestions[0]}'?` + if (firstValidKey) { + message += ` Did you mean something like '${stitch([ + ...keys, + firstValidKey, + ])}'?` } } } @@ -430,7 +421,6 @@ severity === 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning, message, - suggestions, }) }) }) @@ -474,15 +464,11 @@ return null } let message = `'${match.groups.value}' is not a valid group.` - let suggestions: string[] = [] - if (match.groups.value === 'preflight') { - suggestions.push('base') message += ` Did you mean 'base'?` } else { let suggestion = closest(match.groups.value, valid) if (suggestion) { - suggestions.push(suggestion) message += ` Did you mean '${suggestion}'?` } } @@ -504,7 +490,6 @@ severity === 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning, message, - suggestions, }) }) }) diff --git a/src/lsp/providers/diagnostics/types.ts b/src/lsp/providers/diagnostics/types.ts index 385aac55033657c115363d37bf2c00414d581a60..00fc979386386abbad601bf15ba40c8be6cd12c0 100644 --- a/src/lsp/providers/diagnostics/types.ts +++ b/src/lsp/providers/diagnostics/types.ts @@ -35,7 +35,6 @@ } export type InvalidScreenDiagnostic = Diagnostic & { code: DiagnosticKind.InvalidScreen - suggestions: string[] } export function isInvalidScreenDiagnostic( @@ -46,7 +45,6 @@ } export type InvalidVariantDiagnostic = Diagnostic & { code: DiagnosticKind.InvalidVariant - suggestions: string[] } export function isInvalidVariantDiagnostic( @@ -57,7 +55,6 @@ } export type InvalidConfigPathDiagnostic = Diagnostic & { code: DiagnosticKind.InvalidConfigPath - suggestions: string[] } export function isInvalidConfigPathDiagnostic( @@ -68,7 +65,6 @@ } export type InvalidTailwindDirectiveDiagnostic = Diagnostic & { code: DiagnosticKind.InvalidTailwindDirective - suggestions: string[] } export function isInvalidTailwindDirectiveDiagnostic(