Skip to content

Commit 12fd0e9

Browse files
author
Brad Cornes
committed
add screen directive completions
1 parent ba8a6ff commit 12fd0e9

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

packages/tailwindcss-language-server/src/providers/completionProvider.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,52 @@ function provideCssHelperCompletions(
286286
}
287287
}
288288

289+
function provideScreenDirectiveCompletions(
290+
state: State,
291+
{ position, textDocument }: CompletionParams
292+
): CompletionList {
293+
let doc = state.editor.documents.get(textDocument.uri)
294+
295+
if (!isCssContext(doc, position)) {
296+
return null
297+
}
298+
299+
let text = doc.getText({
300+
start: { line: position.line, character: 0 },
301+
end: position,
302+
})
303+
304+
const match = text.match(/^\s*@screen\s+(?<partial>[^\s]*)$/i)
305+
306+
if (match === null) return null
307+
308+
const screens = dlv(
309+
state.config,
310+
['screens'],
311+
dlv(state.config, ['theme', 'screens'], {})
312+
)
313+
314+
if (!isObject(screens)) return null
315+
316+
return {
317+
isIncomplete: false,
318+
items: Object.keys(screens).map((screen) => ({
319+
label: screen,
320+
kind: CompletionItemKind.Constant,
321+
textEdit: {
322+
newText: screen,
323+
range: {
324+
start: {
325+
line: position.line,
326+
character: position.character - match.groups.partial.length,
327+
},
328+
end: position,
329+
},
330+
},
331+
})),
332+
}
333+
}
334+
289335
function provideCssDirectiveCompletions(
290336
state: State,
291337
{ position, textDocument }: CompletionParams
@@ -377,7 +423,8 @@ export function provideCompletions(
377423
return (
378424
provideClassNameCompletions(state, params) ||
379425
provideCssHelperCompletions(state, params) ||
380-
provideCssDirectiveCompletions(state, params)
426+
provideCssDirectiveCompletions(state, params) ||
427+
provideScreenDirectiveCompletions(state, params)
381428
)
382429
}
383430

0 commit comments

Comments
 (0)