Skip to content

Commit d3d4b66

Browse files
committed
Add theme() completion item
1 parent cb67219 commit d3d4b66

File tree

1 file changed

+29
-3
lines changed
  • packages/tailwindcss-language-server/src/language

1 file changed

+29
-3
lines changed

packages/tailwindcss-language-server/src/language/cssServer.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
WorkspaceFolder,
1313
Disposable,
1414
ConfigurationRequest,
15+
CompletionItemKind,
1516
} from 'vscode-languageserver/node'
1617
import { TextDocument } from 'vscode-languageserver-textdocument'
1718
import { Utils, URI } from 'vscode-uri'
@@ -143,15 +144,40 @@ async function withDocumentAndSettings<T>(
143144
}
144145

145146
connection.onCompletion(async ({ textDocument, position }, _token) =>
146-
withDocumentAndSettings(textDocument.uri, ({ document, settings }) =>
147-
cssLanguageService.doComplete2(
147+
withDocumentAndSettings(textDocument.uri, async ({ document, settings }) => {
148+
let result = await cssLanguageService.doComplete2(
148149
document,
149150
position,
150151
stylesheets.get(document),
151152
getDocumentContext(document.uri, workspaceFolders),
152153
settings?.completion
153154
)
154-
)
155+
return {
156+
isIncomplete: result.isIncomplete,
157+
items: result.items.flatMap((item) => {
158+
// Add the `theme()` function
159+
if (item.kind === CompletionItemKind.Function && item.label === 'calc()') {
160+
return [
161+
item,
162+
{
163+
...item,
164+
label: 'theme()',
165+
documentation: {
166+
kind: 'markdown',
167+
value:
168+
'Use the `theme()` function to access your Tailwind config values using dot notation.',
169+
},
170+
textEdit: {
171+
...item.textEdit,
172+
newText: item.textEdit.newText.replace(/^calc\(/, 'theme('),
173+
},
174+
},
175+
]
176+
}
177+
return item
178+
}),
179+
}
180+
})
155181
)
156182

157183
connection.onHover(({ textDocument, position }, _token) =>

0 commit comments

Comments
 (0)