Skip to content

Commit 0cbf86c

Browse files
committed
Refactor
1 parent 5004278 commit 0cbf86c

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,36 +168,40 @@ async function provideSourceGlobHover(
168168

169169
let text = getTextWithoutComments(document, 'css', range)
170170

171-
let pattern = /@source(?:\s+not)?\s*(?<path>'[^']+'|"[^"]+")/dg
171+
let patterns = [
172+
/@source(?:\s+not)?\s*(?<glob>'[^']+'|"[^"]+")/dg,
173+
]
172174

173-
for (let match of findAll(pattern, text)) {
174-
let path = match.groups.path.slice(1, -1)
175+
let matches = patterns.flatMap((pattern) => findAll(pattern, text))
175176

176-
// Ignore paths that don't need brace expansion
177-
if (!path.includes('{') || !path.includes('}')) continue
177+
for (let match of matches) {
178+
let glob = match.groups.glob.slice(1, -1)
179+
180+
// Ignore globs that don't need brace expansion
181+
if (!glob.includes('{') || !glob.includes('}')) continue
178182

179-
// Ignore paths that don't contain the current position
183+
// Ignore glob that don't contain the current position
180184
let slice: Range = absoluteRange(
181185
{
182-
start: indexToPosition(text, match.indices.groups.path[0]),
183-
end: indexToPosition(text, match.indices.groups.path[1]),
186+
start: indexToPosition(text, match.indices.groups.glob[0]),
187+
end: indexToPosition(text, match.indices.groups.glob[1]),
184188
},
185189
range,
186190
)
187191

188192
if (!isWithinRange(position, slice)) continue
189193

190194
// Perform brace expansion
191-
let paths = new Set(braces.expand(path))
192-
if (paths.size < 2) continue
195+
let expanded = new Set(braces.expand(glob))
196+
if (expanded.size < 2) continue
193197

194198
return {
195199
range: slice,
196200
contents: markdown([
197201
//
198202
'**Expansion**',
199203
'```plaintext',
200-
...Array.from(paths, (path) => `- ${path}`),
204+
...Array.from(expanded, (entry) => `- ${entry}`),
201205
'```',
202206
]),
203207
}

0 commit comments

Comments
 (0)