diff --git a/src/lsp/providers/codeActionProvider/index.ts b/src/lsp/providers/codeActionProvider/index.ts index 22298dad00a8abe4bea08c7a41651849e6c5e6dd..62bdb128c3e49cf2cd5895a14dff8cfa7064aef1 100644 --- a/src/lsp/providers/codeActionProvider/index.ts +++ b/src/lsp/providers/codeActionProvider/index.ts @@ -111,21 +111,26 @@ } function classNameToAst( state: State, - classNameParts: string[], + className: string, + isInvalidScreenDiagnostic, import { important: boolean = false ) { + const parts = getClassNameParts(state, className) + if (!parts) { import { getClassNameParts } from '../../util/getClassNameAtPosition' - CodeActionParams, +} from 'vscode-languageserver' import { getClassNameParts } from '../../util/getClassNameAtPosition' - CodeActionKind, +import { State } from '../../util/state' import { getClassNameParts } from '../../util/getClassNameAtPosition' - Range, + CodeActionParams, + state.classNames.classNames, + parts[parts.length - 1] ) if (!baseClassName) { return null } - const info = dlv(state.classNames.classNames, classNameParts) + const info = dlv(state.classNames.classNames, parts) let context = info.__context || [] let pseudo = info.__pseudo || [] const globalContexts = state.classNames.context @@ -137,11 +143,10 @@ if (!isObject(screens)) screens = {} screens = Object.keys(screens) const path = [] -import { CodeAction, + isInvalidVariantDiagnostic(diagnostic) -import { CodeAction, -import { + ) { let common = globalContexts[part] if (!common) return null if (screens.includes(part)) { @@ -158,7 +164,7 @@ } let rule = { // TODO: use proper selector parser [selector + pseudo.join('')]: { - [`@apply ${classNameParts[classNameParts.length - 1]}${ + [`@apply ${parts[parts.length - 1]}${ important ? ' !important' : '' }`]: '', }, @@ -220,14 +226,6 @@ let totalClassNamesInClassList = diagnostic.className.classList.classList.split( /\s+/ ).length - - let className = diagnostic.className.className - let classNameParts = getClassNameParts(state, className) - let classNameInfo = dlv(state.classNames.classNames, classNameParts) - - if (Array.isArray(classNameInfo)) { - return [] - } if (!isCssDoc(state, document)) { let languageBoundaries = getLanguageBoundaries(state, document) @@ -268,10 +266,12 @@ return true } CodeAction, + title: `Replace with '${suggestion}'`, + CodeAction, import dset from 'dset' state, CodeAction, -import detectIndent from 'detect-indent' + kind: CodeActionKind.QuickFix, rule.selector, diagnostic.className.classList.important )