Home

tailwind-ctp-intellisense @b6d257c8434ac9cd2f48caf47124b342e2957c83 - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-language-service / src / documentLinksProvider.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
import type { TextDocument } from 'vscode-languageserver-textdocument'
import { State } from './util/state'
import type { DocumentLink, Range } from 'vscode-languageserver'
import { isCssDoc } from './util/css'
import { getLanguageBoundaries } from './util/getLanguageBoundaries'
import { findAll, indexToPosition } from './util/find'
import { getTextWithoutComments } from './util/doc'
import { absoluteRange } from './util/absoluteRange'
import * as semver from './util/semver'

export function getDocumentLinks(
  state: State,
  document: TextDocument,
  resolveTarget: (linkPath: string) => string
): DocumentLink[] {
  return getConfigDirectiveLinks(state, document, resolveTarget)
}

function getConfigDirectiveLinks(
  state: State,
  document: TextDocument,
  resolveTarget: (linkPath: string) => string
): DocumentLink[] {
  if (!semver.gte(state.version, '3.2.0')) {
    return []
  }

  let links: DocumentLink[] = []
  let ranges: Range[] = []

  if (isCssDoc(state, document)) {
    ranges.push(undefined)
  } else {
    let boundaries = getLanguageBoundaries(state, document)
    if (!boundaries) return []
    ranges.push(...boundaries.filter((b) => b.type === 'css').map(({ range }) => range))
  }

  for (let range of ranges) {
    let text = getTextWithoutComments(document, 'css', range)
    let matches = findAll(/@config\s*(?<path>'[^']+'|"[^"]+")/g, text)

    for (let match of matches) {
      links.push({
        target: resolveTarget(match.groups.path.slice(1, -1)),
        range: absoluteRange(
          {
            start: indexToPosition(text, match.index + match[0].length - match.groups.path.length),
            end: indexToPosition(text, match.index + match[0].length),
          },
          range
        ),
      })
    }
  }

  return links
}