Skip to content

Commit 06a0660

Browse files
committed
wip
1 parent 643a77a commit 06a0660

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

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

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,16 +1641,40 @@ async function provideFileDirectiveCompletions(
16411641
return type.isDirectory || isAllowedFile(name)
16421642
})
16431643

1644-
return withDefaults(
1644+
let items: CompletionItem[] = entries.map(([name, type]) => ({
1645+
label: type.isDirectory ? name + '/' : name,
1646+
kind: type.isDirectory ? 19 : 17,
1647+
command: type.isDirectory
1648+
? { command: 'editor.action.triggerSuggest', title: '' }
1649+
: undefined,
1650+
}))
1651+
1652+
let sourceStart = suggest === 'directory'
1653+
? text.lastIndexOf('source(') + 7
1654+
: -1
1655+
1656+
if (sourceStart !== -1) {
1657+
items.push({
1658+
filterText: '/',
1659+
label: '(none)',
1660+
kind: 15, // Snippet
1661+
textEdit: {
1662+
range: {
1663+
start: {
1664+
line: position.line,
1665+
character: sourceStart,
1666+
},
1667+
end: position,
1668+
},
1669+
newText: 'none',
1670+
},
1671+
})
1672+
}
1673+
1674+
let wip = withDefaults(
16451675
{
16461676
isIncomplete: false,
1647-
items: entries.map(([name, type]) => ({
1648-
label: type.isDirectory ? name + '/' : name,
1649-
kind: type.isDirectory ? 19 : 17,
1650-
command: type.isDirectory
1651-
? { command: 'editor.action.triggerSuggest', title: '' }
1652-
: undefined,
1653-
})),
1677+
items,
16541678
},
16551679
{
16561680
data: {
@@ -1667,6 +1691,10 @@ async function provideFileDirectiveCompletions(
16671691
},
16681692
state.editor.capabilities.itemDefaults,
16691693
)
1694+
1695+
console.log(JSON.stringify(wip))
1696+
1697+
return wip
16701698
}
16711699

16721700
async function provideEmmetCompletions(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect, test } from 'vitest'
2+
import { findFileDirective } from './file-paths'
3+
4+
let findV3 = (text: string) => findFileDirective({ enabled: true, v4: false }, text)
5+
let findV4 = (text: string) => findFileDirective({ enabled: true, v4: true }, text)
6+
7+
test('…', async () => {
8+
await expect(findV4('@import "tailwindcss" source("./')).resolves.toEqual({
9+
directive: 'import',
10+
partial: './',
11+
suggest: 'directory',
12+
})
13+
})

packages/tailwindcss-language-service/src/completions/file-paths.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const PATTERN_CUSTOM_V3 = /@(?<directive>config)\s*(?<partial>'[^']*|"[^"]*)$/
77
// @import … source('…')
88
// @tailwind utilities source('…')
99
const PATTERN_IMPORT_SOURCE = /@(?<directive>import)\s*(?<path>'[^']*'|"[^"]*")\s*source\((?<partial>'[^']*|"[^"]*)$/
10-
const PATTERN_UTIL_SOURCE = /@(?<directive>tailwind)\s+utilities\s+source\((?<partial>'[^']*|"[^"]*)$/
10+
const PATTERN_UTIL_SOURCE = /@(?<directive>tailwind)\s+utilities\s+source\((?<partial>'[^']*|"[^"]*)?$/
1111

1212
export type FileDirective = {
1313
directive: string
@@ -24,7 +24,7 @@ export async function findFileDirective(state: State, text: string): Promise<Fil
2424
if (!match) return null
2525

2626
let directive = match.groups.directive
27-
let partial = match.groups.partial.slice(1) // remove leading quote
27+
let partial = match.groups.partial?.slice(1) ?? "" // remove leading quote
2828

2929
// Most suggestions are for JS files so we'll default to that
3030
let suggest: FileDirective['suggest'] = 'script'

0 commit comments

Comments
 (0)