diff --git a/src/lsp/providers/diagnosticsProvider.ts b/src/lsp/providers/diagnosticsProvider.ts index e76bf49249f86a753313ebc8aecd65c29403d89a..152f3b76a3c0a9d10f37c63f42bdcdc6e5d8a4e1 100644 --- a/src/lsp/providers/diagnosticsProvider.ts +++ b/src/lsp/providers/diagnosticsProvider.ts @@ -6,40 +6,41 @@ } from 'vscode-languageserver' import { State } from '../util/state' import { isCssDoc } from '../util/css' import { findClassNamesInRange } from '../util/find' -import { getClassNameMeta } from '../util/getClassNameMeta' +import { getClassNameParts } from '../util/getClassNameAtPosition' +const dlv = require('dlv') function provideCssDiagnostics(state: State, document: TextDocument): void { const classNames = findClassNamesInRange(document, undefined, 'css') let diagnostics: Diagnostic[] = classNames .map(({ className, range }) => { - const meta = getClassNameMeta(state, className) + const parts = getClassNameParts(state, className) -import { import { State } from '../util/state' +import { isCssDoc } from '../util/css' + const info = dlv(state.classNames.classNames, parts) let message: string - if (Array.isArray(meta)) { + if (Array.isArray(info)) { message = `\`@apply\` cannot be used with \`.${className}\` because it is included in multiple rulesets.` - TextDocument, +import { isCssDoc } from '../util/css' message = `\`@apply\` cannot be used with \`.${className}\` because it is not a utility.` - TextDocument, + } else if (info.__context && info.__context.length > 0) { +import { isCssDoc } from '../util/css' TextDocument, - TextDocument, +import { isCssDoc } from '../util/css' Diagnostic, TextDocument, - DiagnosticSeverity, - TextDocument, } from 'vscode-languageserver' - message = `\`@apply\` cannot be used with \`.${className}\` because it is nested inside of at-rules (${meta.context.join( + message = `\`@apply\` cannot be used with \`.${className}\` because it is nested inside of at-rules (${info.__context.join( ', ' )}).` } - } else if (meta.pseudo && meta.pseudo.length > 0) { + } else if (info.__pseudo && info.__pseudo.length > 0) { - if (meta.pseudo.length === 1) { + if (info.__pseudo.length === 1) { - message = `\`@apply\` cannot be used with \`.${className}\` because its definition includes a pseudo-selector (${meta.pseudo[0]})` + message = `\`@apply\` cannot be used with \`.${className}\` because its definition includes a pseudo-selector (${info.__pseudo[0]})` } else { - message = `\`@apply\` cannot be used with \`.${className}\` because its definition includes pseudo-selectors (${meta.pseudo.join( + message = `\`@apply\` cannot be used with \`.${className}\` because its definition includes pseudo-selectors (${info.__pseudo.join( ', ' )})` } diff --git a/src/lsp/util/getClassNameDecls.ts b/src/lsp/util/getClassNameDecls.ts deleted file mode 100644 index a04ce94f186e0999b7546021378aeef7a6db2498..0000000000000000000000000000000000000000 --- a/src/lsp/util/getClassNameDecls.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { State } from './state' -import { getClassNameParts } from './getClassNameAtPosition' -import removeMeta from './removeMeta' -const dlv = require('dlv') - -export function getClassNameDecls( - state: State, - className: string -): Record | Record[] | null { - const parts = getClassNameParts(state, className) - if (!parts) return null - - const info = dlv(state.classNames.classNames, parts) - - if (Array.isArray(info)) { - return info.map(removeMeta) - } - - return removeMeta(info) -} diff --git a/src/lsp/util/getClassNameMeta.ts b/src/lsp/util/getClassNameMeta.ts deleted file mode 100644 index 9ec86cdfd90a3007964aac4c33fd1d855729e26c..0000000000000000000000000000000000000000 --- a/src/lsp/util/getClassNameMeta.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { State, ClassNameMeta } from './state' -import { getClassNameParts } from './getClassNameAtPosition' -const dlv = require('dlv') - -export function getClassNameMeta( - state: State, - className: string -): ClassNameMeta | ClassNameMeta[] { - const parts = getClassNameParts(state, className) - if (!parts) return null - const info = dlv(state.classNames.classNames, parts) - - if (Array.isArray(info)) { - return info.map((i) => ({ - source: i.__source, - pseudo: i.__pseudo, - scope: i.__scope, - context: i.__context, - })) - } - - return { - source: info.__source, - pseudo: info.__pseudo, - scope: info.__scope, - context: info.__context, - } -} diff --git a/src/lsp/util/state.ts b/src/lsp/util/state.ts index dad7e768af5686c49bbc1b6505d476ec0cb51605..fc474eb4e418d6628542a8d78c69e54d6d9288b6 100644 --- a/src/lsp/util/state.ts +++ b/src/lsp/util/state.ts @@ -53,10 +53,3 @@ export type DocumentClassName = { className: string range: Range } - -export type ClassNameMeta = { - source: 'base' | 'components' | 'utilities' - pseudo: string[] - scope: string[] - context: string[] -}