Skip to content

Commit 73b734d

Browse files
committed
Add completions for —theme(…)
1 parent 62eabe6 commit 73b734d

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

packages/tailwindcss-language-service/src/completionProvider.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ function provideCssHelperCompletions(
974974

975975
const match = text
976976
.substr(0, text.length - 1) // don't include that extra character from earlier
977-
.match(/[\s:;/*(){}](?<helper>config|theme)\(\s*['"]?(?<path>[^)'"]*)$/)
977+
.match(/[\s:;/*(){}](?<helper>config|theme|--theme)\(\s*['"]?(?<path>[^)'"]*)$/)
978978

979979
if (match === null) {
980980
return null
@@ -992,6 +992,39 @@ function provideCssHelperCompletions(
992992
return null
993993
}
994994

995+
let editRange = {
996+
start: {
997+
line: position.line,
998+
character: position.character,
999+
},
1000+
end: position,
1001+
}
1002+
1003+
if (state.v4 && match.groups.helper === '--theme') {
1004+
// List known theme keys
1005+
let validThemeKeys = resolveKnownThemeKeys(state.designSystem)
1006+
1007+
let items: CompletionItem[] = validThemeKeys.map((themeKey, index) => {
1008+
return {
1009+
label: themeKey,
1010+
sortText: naturalExpand(index, validThemeKeys.length),
1011+
kind: 9,
1012+
}
1013+
})
1014+
1015+
return withDefaults(
1016+
{ isIncomplete: false, items },
1017+
{
1018+
range: editRange,
1019+
data: {
1020+
...(state.completionItemData ?? {}),
1021+
_type: 'helper',
1022+
},
1023+
},
1024+
state.editor.capabilities.itemDefaults,
1025+
)
1026+
}
1027+
9951028
let base = match.groups.helper === 'config' ? state.config : dlv(state.config, 'theme', {})
9961029
let parts = path.split(/([\[\].]+)/)
9971030
let keys = parts.filter((_, i) => i % 2 === 0)
@@ -1025,13 +1058,7 @@ function provideCssHelperCompletions(
10251058

10261059
if (!obj) return null
10271060

1028-
let editRange = {
1029-
start: {
1030-
line: position.line,
1031-
character: position.character - offset,
1032-
},
1033-
end: position,
1034-
}
1061+
editRange.start.character = position.character - offset
10351062

10361063
return withDefaults(
10371064
{

0 commit comments

Comments
 (0)