diff --git a/packages/tailwindcss-language-service/src/util/find.test.ts b/packages/tailwindcss-language-service/src/util/find.test.ts index 839fb6d0..170217c0 100644 --- a/packages/tailwindcss-language-service/src/util/find.test.ts +++ b/packages/tailwindcss-language-service/src/util/find.test.ts @@ -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 }) => { @@ -791,3 +791,87 @@ test('classAttributes find class lists inside Vue bindings', async ({ expect }) }, ]) }) + +test('Can find class name inside JS/TS functions in + `, + }) + + 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 + `, + }) + + 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 }, + }, + }, + }) +}) diff --git a/packages/tailwindcss-language-service/src/util/find.ts b/packages/tailwindcss-language-service/src/util/find.ts index 9118403d..53ad7195 100644 --- a/packages/tailwindcss-language-service/src/util/find.ts +++ b/packages/tailwindcss-language-service/src/util/find.ts @@ -5,7 +5,7 @@ import lineColumn from 'line-column' import { isCssContext, isCssDoc } from './css' import { isHtmlContext, isVueDoc } from './html' import { isWithinRange } from './isWithinRange' -import { isJsxContext } from './js' +import { isJsContext } from './js' import { dedupeByRange, flatten } from './array' import { getClassAttributeLexer, getComputedClassAttributeLexer } from './lexers' import { getLanguageBoundaries } from './getLanguageBoundaries' @@ -526,7 +526,7 @@ export async function findClassNameAtPosition( classNames = await findClassNamesInRange(state, doc, searchRange, 'css') } else if (isHtmlContext(state, doc, position)) { classNames = await findClassNamesInRange(state, doc, searchRange, 'html') - } else if (isJsxContext(state, doc, position)) { + } else if (isJsContext(state, doc, position)) { classNames = await findClassNamesInRange(state, doc, searchRange, 'jsx') } else { classNames = await findClassNamesInRange(state, doc, searchRange) diff --git a/packages/tailwindcss-language-service/src/util/state.ts b/packages/tailwindcss-language-service/src/util/state.ts index 754f2a49..26cc2ed0 100644 --- a/packages/tailwindcss-language-service/src/util/state.ts +++ b/packages/tailwindcss-language-service/src/util/state.ts @@ -228,6 +228,7 @@ export function createState( return { enabled: true, features: [], + blocklist: [], ...partial, editor: { get connection(): Connection { diff --git a/packages/vscode-tailwindcss/CHANGELOG.md b/packages/vscode-tailwindcss/CHANGELOG.md index 4c9240f6..4162495c 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -3,6 +3,7 @@ ## Prerelease - Warn when using a blocklisted class in v4 ([#1310](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1310)) +- Support class function hovers in Svelte and HTML `