|
1 | | -import type { State } from './util/state' |
2 | | -import { |
3 | | - findClassListsInDocument, |
4 | | - getClassNamesInClassList, |
5 | | - findHelperFunctionsInDocument, |
6 | | -} from './util/find' |
| 1 | +import type { ColorInformation } from 'vscode-languageserver' |
| 2 | +import type { Document } from './documents/document' |
7 | 3 | import { getColor, getColorFromValue, culoriColorToVscodeColor } from './util/color' |
8 | 4 | import { stringToPath } from './util/stringToPath' |
9 | | -import type { ColorInformation } from 'vscode-languageserver' |
10 | | -import type { TextDocument } from 'vscode-languageserver-textdocument' |
11 | 5 | import dlv from 'dlv' |
12 | 6 | import { dedupeByRange } from './util/array' |
13 | 7 |
|
14 | | -export async function getDocumentColors( |
15 | | - state: State, |
16 | | - document: TextDocument, |
17 | | -): Promise<ColorInformation[]> { |
| 8 | +export function getDocumentColors(doc: Document): ColorInformation[] { |
18 | 9 | let colors: ColorInformation[] = [] |
19 | | - if (!state.enabled) return colors |
20 | 10 |
|
21 | | - let settings = await state.editor.getConfiguration(document.uri) |
22 | | - if (settings.tailwindCSS.colorDecorators === false) return colors |
| 11 | + for (let className of doc.classNames()) { |
| 12 | + let color = getColor(doc.state, className.className) |
| 13 | + if (!color) continue |
| 14 | + if (typeof color === 'string') continue |
| 15 | + if ((color.alpha ?? 1) === 0) continue |
23 | 16 |
|
24 | | - let classLists = await findClassListsInDocument(state, document) |
25 | | - classLists.forEach((classList) => { |
26 | | - let classNames = getClassNamesInClassList(classList, state.blocklist) |
27 | | - classNames.forEach((className) => { |
28 | | - let color = getColor(state, className.className) |
29 | | - if (color === null || typeof color === 'string' || (color.alpha ?? 1) === 0) { |
30 | | - return |
31 | | - } |
32 | | - colors.push({ |
33 | | - range: className.range, |
34 | | - color: culoriColorToVscodeColor(color), |
35 | | - }) |
| 17 | + colors.push({ |
| 18 | + range: className.range, |
| 19 | + color: culoriColorToVscodeColor(color), |
36 | 20 | }) |
37 | | - }) |
| 21 | + } |
38 | 22 |
|
39 | | - let helperFns = findHelperFunctionsInDocument(state, document) |
40 | | - helperFns.forEach((fn) => { |
| 23 | + for (let fn of doc.helperFns()) { |
41 | 24 | let keys = stringToPath(fn.path) |
42 | 25 | let base = fn.helper === 'theme' ? ['theme'] : [] |
43 | | - let value = dlv(state.config, [...base, ...keys]) |
| 26 | + let value = dlv(doc.state.config, [...base, ...keys]) |
| 27 | + |
44 | 28 | let color = getColorFromValue(value) |
45 | | - if (color && typeof color !== 'string' && (color.alpha ?? 1) !== 0) { |
46 | | - colors.push({ range: fn.ranges.path, color: culoriColorToVscodeColor(color) }) |
47 | | - } |
48 | | - }) |
| 29 | + if (!color) continue |
| 30 | + if (typeof color === 'string') continue |
| 31 | + if ((color.alpha ?? 1) === 0) continue |
| 32 | + |
| 33 | + colors.push({ |
| 34 | + range: fn.ranges.path, |
| 35 | + color: culoriColorToVscodeColor(color), |
| 36 | + }) |
| 37 | + } |
49 | 38 |
|
50 | 39 | return dedupeByRange(colors) |
51 | 40 | } |
0 commit comments