Skip to content

Commit c591108

Browse files
committed
Refactor
1 parent 0710171 commit c591108

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

packages/tailwindcss-language-service/src/documentLinksProvider.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { findAll, indexToPosition } from './util/find'
77
import { getTextWithoutComments } from './util/doc'
88
import { absoluteRange } from './util/absoluteRange'
99
import * as semver from './util/semver'
10+
import { getCssBlocks } from './util/language-blocks'
1011

1112
export function getDocumentLinks(
1213
state: State,
@@ -38,34 +39,27 @@ function getDirectiveLinks(
3839
}
3940

4041
let links: DocumentLink[] = []
41-
let ranges: Range[] = []
4242

43-
if (isCssDoc(state, document)) {
44-
ranges.push(undefined)
45-
} else {
46-
let boundaries = getLanguageBoundaries(state, document)
47-
if (!boundaries) return []
48-
ranges.push(...boundaries.filter((b) => b.type === 'css').map(({ range }) => range))
49-
}
43+
for (let block of getCssBlocks(state, document)) {
44+
let text = block.text
5045

51-
for (let range of ranges) {
52-
let text = getTextWithoutComments(document, 'css', range)
5346
let matches: RegExpMatchArray[] = []
5447

5548
for (let pattern of patterns) {
5649
matches.push(...findAll(pattern, text))
5750
}
5851

5952
for (let match of matches) {
53+
let path = match.groups.path.slice(1, -1)
54+
55+
let range = {
56+
start: indexToPosition(text, match.index + match[0].length - match.groups.path.length),
57+
end: indexToPosition(text, match.index + match[0].length),
58+
}
59+
6060
links.push({
61-
target: resolveTarget(match.groups.path.slice(1, -1)),
62-
range: absoluteRange(
63-
{
64-
start: indexToPosition(text, match.index + match[0].length - match.groups.path.length),
65-
end: indexToPosition(text, match.index + match[0].length),
66-
},
67-
range,
68-
),
61+
target: resolveTarget(path),
62+
range: absoluteRange(range, block.range),
6963
})
7064
}
7165
}

0 commit comments

Comments
 (0)