Home

tailwind-ctp-intellisense @03e16a4ac0640fb8d5403dd15130d80c1940b3bc - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / src / lsp / providers / diagnostics / getInvalidApplyDiagnostics.ts
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { findClassNamesInRange } from '../../util/find'
import { InvalidApplyDiagnostic, DiagnosticKind } from './types'
import { Settings, State } from '../../util/state'
import { TextDocument, DiagnosticSeverity } from 'vscode-languageserver'
import { getClassNameMeta } from '../../util/getClassNameMeta'

export function getInvalidApplyDiagnostics(
  state: State,
  document: TextDocument,
  settings: Settings
): InvalidApplyDiagnostic[] {
  let severity = settings.lint.invalidApply
  if (severity === 'ignore') return []

  const classNames = findClassNamesInRange(document, undefined, 'css')

  let diagnostics: InvalidApplyDiagnostic[] = classNames.map((className) => {
    const meta = getClassNameMeta(state, className.className)
    if (!meta) return null

    let message: string

    if (Array.isArray(meta)) {
      message = `'@apply' cannot be used with '${className.className}' because it is included in multiple rulesets.`
    } else if (meta.source !== 'utilities') {
      message = `'@apply' cannot be used with '${className.className}' because it is not a utility.`
    } else if (meta.context && meta.context.length > 0) {
      if (meta.context.length === 1) {
        message = `'@apply' cannot be used with '${className.className}' because it is nested inside of an at-rule ('${meta.context[0]}').`
      } else {
        message = `'@apply' cannot be used with '${
          className.className
        }' because it is nested inside of at-rules (${meta.context
          .map((c) => `'${c}'`)
          .join(', ')}).`
      }
    } else if (meta.pseudo && meta.pseudo.length > 0) {
      if (meta.pseudo.length === 1) {
        message = `'@apply' cannot be used with '${className.className}' because its definition includes a pseudo-selector ('${meta.pseudo[0]}')`
      } else {
        message = `'@apply' cannot be used with '${
          className.className
        }' because its definition includes pseudo-selectors (${meta.pseudo
          .map((p) => `'${p}'`)
          .join(', ')}).`
      }
    }

    if (!message) return null

    return {
      code: DiagnosticKind.InvalidApply,
      severity:
        severity === 'error'
          ? DiagnosticSeverity.Error
          : DiagnosticSeverity.Warning,
      range: className.range,
      message,
      className,
    }
  })

  return diagnostics.filter(Boolean)
}