Home

tailwind-ctp-intellisense @a9a0983d8b670d743867e6818b5ade5de4791282 - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-language-server / src / providers / hoverProvider.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
import { State } from '../util/state'
import { Hover, TextDocumentPositionParams } from 'vscode-languageserver'
import {
  getClassNameAtPosition,
  getClassNameParts,
} from '../util/getClassNameAtPosition'
import { stringifyCss } from '../util/stringify'
const dlv = require('dlv')
import escapeClassName from 'css.escape'
import { isHtmlContext } from '../util/html'

export function provideHover(
  state: State,
  params: TextDocumentPositionParams
): Hover {
  let doc = state.editor.documents.get(params.textDocument.uri)

  if (isHtmlContext(doc, params.position)) {
    return provideClassNameHover(state, params)
  }

  return null
}

function provideClassNameHover(
  state: State,
  { textDocument, position }: TextDocumentPositionParams
): Hover {
  let doc = state.editor.documents.get(textDocument.uri)
  let hovered = getClassNameAtPosition(doc, position)
  if (!hovered) return null

  const parts = getClassNameParts(state, hovered.className)
  if (parts === null) return null

  return {
    contents: {
      language: 'css',
      value: stringifyCss(dlv(state.classNames.classNames, parts), {
        selector: augmentClassName(parts, state),
      }),
    },
    range: hovered.range,
  }
}

// TODO
function augmentClassName(className: string | string[], state: State): string {
  const parts = Array.isArray(className)
    ? className
    : getClassNameParts(state, className)
  const obj = dlv(state.classNames.classNames, parts)
  const pseudo = obj.__pseudo ? obj.__pseudo.join('') : ''
  const scope = obj.__scope ? `${obj.__scope} ` : ''
  return `${scope}.${escapeClassName(parts.join(state.separator))}${pseudo}`
}