Skip to content

Commit 41cc24a

Browse files
author
Laurynas Grigutis
committed
Fixed findClassListsInHtmlRange state type & removed type casting in find.test.ts
1 parent 100cad7 commit 41cc24a

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

packages/tailwindcss-language-service/src/util/find.test.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
getDefaultTailwindSettings,
3-
type DocumentClassList,
4-
type EditorState,
5-
type State,
6-
} from './state'
1+
import { getDefaultTailwindSettings, type DocumentClassList } from './state'
72
import { test } from 'vitest'
83
import { TextDocument } from 'vscode-languageserver-textdocument'
94
import { findClassListsInHtmlRange } from './find'
@@ -18,15 +13,13 @@ test('test astro', async ({ expect }) => {
1813

1914
let doc = TextDocument.create('file://file.astro', 'astro', 1, content)
2015
let defaultSettings = getDefaultTailwindSettings()
21-
let state: State = {
22-
blocklist: [],
23-
enabled: true,
16+
let state: Parameters<typeof findClassListsInHtmlRange>[0] = {
2417
editor: {
25-
userLanguages: {},
2618
getConfiguration: async () => ({
2719
...defaultSettings,
2820
tailwindCSS: {
2921
...defaultSettings.tailwindCSS,
22+
classAttributes: ['class'],
3023
experimental: {
3124
...defaultSettings.tailwindCSS.experimental,
3225
classRegex: [
@@ -36,7 +29,7 @@ test('test astro', async ({ expect }) => {
3629
},
3730
},
3831
}),
39-
} as EditorState,
32+
},
4033
}
4134

4235
let classLists = await findClassListsInHtmlRange(state, doc, 'html')
@@ -180,7 +173,7 @@ test('test simple classFunctions', async ({ expect }) => {
180173
const cmaDoc = TextDocument.create('file://file.html', 'html', 1, cmaContent)
181174
const cmaClassLists = await findClassListsInHtmlRange(state, cmaDoc, 'html')
182175

183-
expect(cmaClassLists).not.toMatchObject(expectedResult)
176+
expect(cmaClassLists).toMatchObject([])
184177
})
185178

186179
test('test nested classFunctions', async ({ expect }) => {
@@ -283,13 +276,10 @@ test('test nested classFunctions', async ({ expect }) => {
283276
expect(classLists).toMatchObject(expectedResult)
284277
})
285278

286-
function getTailwindSettingsForClassFunctions(): State {
279+
function getTailwindSettingsForClassFunctions(): Parameters<typeof findClassListsInHtmlRange>[0] {
287280
const defaultSettings = getDefaultTailwindSettings()
288281
return {
289-
blocklist: [],
290-
enabled: true,
291282
editor: {
292-
userLanguages: {},
293283
getConfiguration: async () => ({
294284
...defaultSettings,
295285
tailwindCSS: {
@@ -300,6 +290,6 @@ function getTailwindSettingsForClassFunctions(): State {
300290
},
301291
},
302292
}),
303-
} as EditorState,
293+
},
304294
}
305295
}

packages/tailwindcss-language-service/src/util/find.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ export function matchClassFunctions(text: string, fnNames: string[]): RegExpMatc
171171
}
172172

173173
export async function findClassListsInHtmlRange(
174-
state: State,
174+
// PickDeep from 'type-fest' package cannot be used here due to a circular reference issue in the package
175+
// Fixes are underway (see: https://github.com/sindresorhus/type-fest/pull/1079)
176+
state: { editor?: Pick<NonNullable<State['editor']>, 'getConfiguration'> },
175177
doc: TextDocument,
176178
type: 'html' | 'js' | 'jsx',
177179
range?: Range,

0 commit comments

Comments
 (0)