Home

tailwind-ctp-intellisense @5f6b8e3f4e3e5b05772156d73abdab8613b69c21 - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / src / lsp / 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
import { TextDocument, Position } from 'vscode-languageserver'
import { isHtmlDoc, isInsideTag, isVueDoc, isSvelteDoc } from './html'
import { State } from './state'

export const JS_LANGUAGES = [
  'javascript',
  'javascriptreact',
  'reason',
  '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
}