Skip to content

wip: Improve value parsing #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
thecrypticace committed Apr 14, 2025
commit b4451e47bf9c3a333131794be7b8de44ea36449d
86 changes: 85 additions & 1 deletion packages/tailwindcss-language-service/src/util/find.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from 'vitest'
import { findClassListsInHtmlRange } from './find'
import { findClassListsInHtmlRange, findClassNameAtPosition } from './find'
import { js, html, pug, createDocument } from './test-utils'

test('class regex works in astro', async ({ expect }) => {
Expand Down Expand Up @@ -791,3 +791,87 @@ test('classAttributes find class lists inside Vue bindings', async ({ expect })
},
])
})

test('Can find class name inside JS/TS functions in <script> tags (HTML)', async ({ expect }) => {
let file = createDocument({
name: 'file.html',
lang: 'html',
settings: {
tailwindCSS: {
classFunctions: ['clsx'],
},
},
content: html`
<script>
let classes = clsx('flex relative')
</script>
`,
})

let className = await findClassNameAtPosition(file.state, file.doc, {
line: 1,
character: 23,
})

expect(className).toEqual({
className: 'flex',
range: {
start: { line: 1, character: 22 },
end: { line: 1, character: 26 },
},
relativeRange: {
start: { line: 0, character: 0 },
end: { line: 0, character: 4 },
},
classList: {
classList: 'flex relative',
important: undefined,
range: {
start: { character: 22, line: 1 },
end: { character: 35, line: 1 },
},
},
})
})

test('Can find class name inside JS/TS functions in <script> tags (Svelte)', async ({ expect }) => {
let file = createDocument({
name: 'file.svelte',
lang: 'svelte',
settings: {
tailwindCSS: {
classFunctions: ['clsx'],
},
},
content: html`
<script>
let classes = clsx('flex relative')
</script>
`,
})

let className = await findClassNameAtPosition(file.state, file.doc, {
line: 1,
character: 23,
})

expect(className).toEqual({
className: 'flex',
range: {
start: { line: 1, character: 22 },
end: { line: 1, character: 26 },
},
relativeRange: {
start: { line: 0, character: 0 },
end: { line: 0, character: 4 },
},
classList: {
classList: 'flex relative',
important: undefined,
range: {
start: { character: 22, line: 1 },
end: { character: 35, line: 1 },
},
},
})
})
1 change: 1 addition & 0 deletions packages/tailwindcss-language-service/src/util/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export function createState(
return {
enabled: true,
features: [],
blocklist: [],
...partial,
editor: {
get connection(): Connection {
Expand Down