Skip to content

Commit 85ba6a4

Browse files
committed
Update settings
1 parent f262bbb commit 85ba6a4

File tree

3 files changed

+54
-56
lines changed

3 files changed

+54
-56
lines changed

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,20 @@
7171
"default": {},
7272
"markdownDescription": "Enable features in languages that are not supported by default. Add a mapping here between the new language and an already supported language.\n E.g.: `{\"plaintext\": \"html\"}`"
7373
},
74-
"tailwindCSS.colorDecorators.enabled": {
75-
"type": "boolean",
76-
"default": true,
77-
"scope": "language-overridable"
78-
},
79-
"tailwindCSS.colorDecorators.classes": {
80-
"type": "boolean",
81-
"default": true,
82-
"scope": "language-overridable"
83-
},
84-
"tailwindCSS.colorDecorators.cssHelpers": {
85-
"type": "boolean",
86-
"default": true,
74+
"tailwindCSS.colorDecorators": {
75+
"type": "string",
76+
"enum": [
77+
"inherit",
78+
"on",
79+
"off"
80+
],
81+
"markdownEnumDescriptions": [
82+
"Color decorators are rendered if `editor.colorDecorators` is `true`.",
83+
"Color decorators are rendered.",
84+
"Color decorators are not rendered."
85+
],
86+
"default": "inherit",
87+
"markdownDescription": "Controls whether the editor should render inline color decorators for Tailwind CSS classes and helper functions.",
8788
"scope": "language-overridable"
8889
},
8990
"tailwindCSS.validate": {

src/lib/registerColorDecorator.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,22 @@ export function registerColorDecorator(
4747
return
4848
}
4949

50-
let settings = workspace.getConfiguration(
51-
'tailwindCSS.colorDecorators',
52-
editor.document
53-
)
50+
let preference =
51+
workspace.getConfiguration('tailwindCSS', editor.document)
52+
.colorDecorators || 'inherit'
53+
54+
let enabled =
55+
preference === 'inherit'
56+
? workspace.getConfiguration('editor').colorDecorators
57+
: preference === 'on'
5458

55-
if (settings.enabled !== true) {
59+
if (enabled !== true) {
5660
editor.setDecorations(colorDecorationType, [])
5761
return
5862
}
5963

6064
let { colors } = await emitter.emit('getDocumentColors', {
6165
document: editor.document.uri.toString(),
62-
classes: settings.classes,
63-
cssHelpers: settings.cssHelpers,
6466
})
6567

6668
editor.setDecorations(

src/lsp/providers/documentColorProvider.ts

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,50 @@ import {
77
} from '../util/find'
88
import { getClassNameParts } from '../util/getClassNameAtPosition'
99
import { getColor, getColorFromValue } from '../util/color'
10-
import { logFull } from '../util/logFull'
1110
import { stringToPath } from '../util/stringToPath'
1211
const dlv = require('dlv')
1312

1413
export function registerDocumentColorProvider(state: State) {
1514
onMessage(
1615
state.editor.connection,
1716
'getDocumentColors',
18-
async ({ document, classes, cssHelpers }) => {
17+
async ({ document }) => {
1918
let colors = []
2019
let doc = state.editor.documents.get(document)
2120
if (!doc) return { colors }
2221

23-
if (classes) {
24-
let classLists = findClassListsInDocument(state, doc)
25-
classLists.forEach((classList) => {
26-
let classNames = getClassNamesInClassList(classList)
27-
classNames.forEach((className) => {
28-
let parts = getClassNameParts(state, className.className)
29-
if (!parts) return
30-
let color = getColor(state, parts)
31-
if (!color) return
32-
colors.push({ range: className.range, color: color.documentation })
33-
})
22+
let classLists = findClassListsInDocument(state, doc)
23+
classLists.forEach((classList) => {
24+
let classNames = getClassNamesInClassList(classList)
25+
classNames.forEach((className) => {
26+
let parts = getClassNameParts(state, className.className)
27+
if (!parts) return
28+
let color = getColor(state, parts)
29+
if (!color) return
30+
colors.push({ range: className.range, color: color.documentation })
3431
})
35-
}
32+
})
3633

37-
if (cssHelpers) {
38-
let helperFns = findHelperFunctionsInDocument(state, doc)
39-
helperFns.forEach((fn) => {
40-
let keys = stringToPath(fn.value)
41-
let base = fn.helper === 'theme' ? ['theme'] : []
42-
let value = dlv(state.config, [...base, ...keys])
43-
let color = getColorFromValue(value)
44-
if (color) {
45-
// colors.push({
46-
// range: {
47-
// start: {
48-
// line: fn.valueRange.start.line,
49-
// character: fn.valueRange.start.character + 1,
50-
// },
51-
// end: fn.valueRange.end,
52-
// },
53-
// color,
54-
// })
55-
colors.push({ range: fn.valueRange, color })
56-
}
57-
})
58-
}
34+
let helperFns = findHelperFunctionsInDocument(state, doc)
35+
helperFns.forEach((fn) => {
36+
let keys = stringToPath(fn.value)
37+
let base = fn.helper === 'theme' ? ['theme'] : []
38+
let value = dlv(state.config, [...base, ...keys])
39+
let color = getColorFromValue(value)
40+
if (color) {
41+
// colors.push({
42+
// range: {
43+
// start: {
44+
// line: fn.valueRange.start.line,
45+
// character: fn.valueRange.start.character + 1,
46+
// },
47+
// end: fn.valueRange.end,
48+
// },
49+
// color,
50+
// })
51+
colors.push({ range: fn.valueRange, color })
52+
}
53+
})
5954

6055
return { colors }
6156
}

0 commit comments

Comments
 (0)