Home

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

export const JS_LANGUAGES = [
  'javascript',
  'javascriptreact',
  'reason',
  'rescript',
  'typescript',
  'typescriptreact',
]

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

  return [...JS_LANGUAGES, ...userJsLanguages].indexOf(doc.languageId) !== -1
}

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

  let str = doc.getText({
    start: { line: 0, character: 0 },
    end: position,
  })

  if (isHtmlDoc(state, doc) && isInsideTag(str, ['script'])) {
    return true
  }

  if (isVueDoc(doc) || isSvelteDoc(doc)) {
    return isInsideTag(str, ['script'])
  }

  return false
}