Home

tailwind-ctp-intellisense @66945537e9d035b9af70e88938003a465ef83ce8 - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-language-service / src / util / css.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
import type { TextDocument, Position } from 'vscode-languageserver'
import { isVueDoc, isSvelteDoc, isHtmlDoc } from './html'
import { isJsDoc } from './js'
import { State } from './state'
import { cssLanguages } from './languages'
import { getLanguageBoundaries } from './getLanguageBoundaries'

export function isCssDoc(state: State, doc: TextDocument): boolean {
  const userCssLanguages = Object.keys(state.editor.userLanguages).filter((lang) =>
    cssLanguages.includes(state.editor.userLanguages[lang])
  )

  return [...cssLanguages, ...userCssLanguages].indexOf(doc.languageId) !== -1
}

export function isCssContext(state: State, doc: TextDocument, position: Position): boolean {
  if (isCssDoc(state, doc)) {
    return true
  }

  if (isHtmlDoc(state, doc) || isVueDoc(doc) || isSvelteDoc(doc) || isJsDoc(state, doc)) {
    let str = doc.getText({
      start: { line: 0, character: 0 },
      end: position,
    })

    let boundaries = getLanguageBoundaries(state, doc, str)

    return boundaries ? boundaries[boundaries.length - 1].type === 'css' : false
  }

  return false
}