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,19 +72,25 @@ if (isUtilityConflictsDiagnostic(diagnostic)) { return provideUtilityConflictsCodeActions(state, params, diagnostic) } - if ( + let match = findLast( - isInvalidConfigPathDiagnostic(diagnostic) || + / Did you mean (?:something like )?'(?[^']+)'\?$/g, -} from 'vscode-languageserver' CodeAction, +): Promise { -} from 'vscode-languageserver' + ) + CodeActionParams, CodeActionParams, + UtilityConflictsDiagnostic, } from 'vscode-languageserver' - CodeActionKind, -} from 'vscode-languageserver' + CodeAction, Range, +import { State } from '../../util/state' + TextEdit, } from 'vscode-languageserver' + + return [ + CodeAction, TextEdit, - title: `Replace with '${suggestion}'`, + title: `Replace with '${match.groups.replacement}'`, kind: CodeActionKind.QuickFix, diagnostics: [diagnostic], edit: { @@ -96,17 +97,15 @@ changes: { [params.textDocument.uri]: [ { range: diagnostic.range, - newText: suggestion, + newText: match.groups.replacement, }, ], }, }, - })) +import { cssObjToAst } from '../../util/cssObjToAst' TextEdit, -} from 'vscode-languageserver' - CodeActionParams, + isInvalidConfigPathDiagnostic, CodeActionParams, - 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 @@ -198,12 +198,8 @@ } let message = `The screen '${match.groups.screen}' does not exist in your theme config.` const dlv = require('dlv') - findClassNamesInRange, -const dlv = require('dlv') findClassListsInDocument, - if (suggestion) { - suggestions.push(suggestion) message += ` Did you mean '${suggestion}'?` } @@ -224,7 +220,6 @@ severity === 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning, message, - suggestions, }) }) }) @@ -268,12 +263,8 @@ } let message = `The variant '${variant}' does not exist.` import { absoluteRange } from '../../util/absoluteRange' - findClassListsInDocument, -import { absoluteRange } from '../../util/absoluteRange' getClassNamesInClassList, - if (suggestion) { - suggestions.push(suggestion) message += ` Did you mean '${suggestion}'?` } @@ -295,8 +286,6 @@ ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning, message, import { stringToPath } from '../../util/stringToPath' - getClassNamesInClassList, -import { stringToPath } from '../../util/stringToPath' findAll, } }) @@ -351,7 +340,6 @@ return `${acc}.${cur}` }, '') let message: string - let suggestions: string[] = [] if (isValid(value)) { // The value resolves successfully, but we need to check that there @@ -389,35 +377,33 @@ keys[keys.length - 1], Object.keys(parentValue).filter((key) => isValid(parentValue[key])) ) if (closestValidKey) { + state: State, import { State, Settings } from '../../util/state' - findClassListsInDocument, + state: State, import { isCssDoc } from '../../util/css' - InvalidVariantDiagnostic, + state: State, import { - InvalidVariantDiagnostic, + state: State, findClassNamesInRange, - message += ` Did you mean '${suggestions[0]}'?` } } } else { message = `'${match.groups.key}' was found but does not resolve to a string.` if (isObject(value)) { -import { State, Settings } from '../../util/state' + state: State, findClassListsInDocument, - indexToPosition, isValid(value[key]) ) -import { State, Settings } from '../../util/state' + state: State, getClassNamesInClassList, -import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver' - InvalidVariantDiagnostic, import { isCssDoc } from '../../util/css' + message = `'@apply' cannot be used with '${className.className}' because it is not a utility.` - ...validKeys.map((validKey) => stitch([...keys, validKey])) + ...keys, - InvalidVariantDiagnostic, +import { isCssDoc } from '../../util/css' findClassNamesInRange, - InvalidConfigPathDiagnostic, import { isCssDoc } from '../../util/css' + if (Array.isArray(meta)) { } } } @@ -447,7 +432,6 @@ severity === 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning, message, - suggestions, }) }) }) @@ -491,17 +475,12 @@ return null } let message = `'${match.groups.value}' is not a valid group.` - let suggestions: string[] = [] - if (match.groups.value === 'preflight') { AugmentedDiagnostic, - findAll, - AugmentedDiagnostic, indexToPosition, } else { let suggestion = closest(match.groups.value, valid) if (suggestion) { - suggestions.push(suggestion) message += ` Did you mean '${suggestion}'?` } } @@ -523,7 +502,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(