Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/tailwindcss-language-service/src/util/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,41 @@ test('Helper functions can start with --', async ({ expect }) => {
])
})

test('Helper functions can span multiple lines', async ({ expect }) => {
let file = createDocument({
name: 'file.css',
lang: 'css',
content: `
.a {
color: theme(
'colors.red.500'
);
}
.b {
color: theme(
'colors.red.500',
red
);
}
`,
})

let fns = findHelperFunctionsInDocument(file.state, file.doc)

expect(fns).toEqual([
{
helper: 'theme',
path: 'colors.red.500',
ranges: { full: range(2, 21, 4, 8), path: range(3, 11, 3, 25) },
},
{
helper: 'theme',
path: 'colors.red.500',
ranges: { full: range(7, 21, 10, 8), path: range(8, 11, 8, 25) },
},
])
})

test('Can find helper functions in SCSS', async ({ expect }) => {
let file = createDocument({
name: 'file.scss',
Expand Down
16 changes: 8 additions & 8 deletions packages/tailwindcss-language-service/src/util/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,12 @@ export function findHelperFunctionsInRange(
let path = text.slice(pathStart, pathEnd)

// Skip leading/trailing whitespace
pathStart += path.match(/^\s+/)?.length ?? 0
pathEnd -= path.match(/\s+$/)?.length ?? 0
pathStart += path.match(/^\s+/)?.[0].length ?? 0
pathEnd -= path.match(/\s+$/)?.[0].length ?? 0

// Skip leading/trailing quotes
let quoteStart = path.match(/^['"]+/)?.length ?? 0
let quoteEnd = path.match(/['"]+$/)?.length ?? 0
let quoteStart = path.match(/^['"]+/)?.[0].length ?? 0
let quoteEnd = path.match(/['"]+$/)?.[0].length ?? 0

if (quoteStart && quoteEnd) {
pathStart += quoteStart
Expand Down Expand Up @@ -542,15 +542,15 @@ export function findHelperFunctionsInRange(
// Skip leading/trailing whitespace
//
// This can happen if we've clipped the path down to before the `/`
pathStart += path.match(/^\s+/)?.length ?? 0
pathEnd -= path.match(/\s+$/)?.length ?? 0
pathStart += path.match(/^\s+/)?.[0].length ?? 0
pathEnd -= path.match(/\s+$/)?.[0].length ?? 0

// Re-slice
path = text.slice(pathStart, pathEnd)

// Skip leading/trailing quotes
quoteStart = path.match(/^['"]+/)?.length ?? 0
quoteEnd = path.match(/['"]+$/)?.length ?? 0
quoteStart = path.match(/^['"]+/)?.[0].length ?? 0
quoteEnd = path.match(/['"]+$/)?.[0].length ?? 0

pathStart += quoteStart
pathEnd -= quoteEnd
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prerelease

- Nothing yet!
- Fix incorrect `invalidConfigPath` warnings when a `theme(…)` or `config(…)` call spans multiple lines ([#1606](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1606))

## 0.16.0

Expand Down