Skip to content

Commit b356886

Browse files
committed
Add document links and completions for @plugin
plugin
1 parent 5017e99 commit b356886

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

packages/tailwindcss-language-server/tests/document-links/document-links.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,30 @@ withFixture('v4/basic', (c) => {
7878
},
7979
],
8080
})
81+
82+
testDocumentLinks('plugin: file exists', {
83+
text: '@plugin "plugin.js";',
84+
lang: 'css',
85+
expected: [
86+
{
87+
target: `file://${path
88+
.resolve('./tests/fixtures/v4/basic/plugin.js')
89+
.replace(/@/g, '%40')}`,
90+
range: { start: { line: 0, character: 8 }, end: { line: 0, character: 19 } },
91+
},
92+
],
93+
})
94+
95+
testDocumentLinks('plugin: file does not exist', {
96+
text: '@plugin "does-not-exist.js";',
97+
lang: 'css',
98+
expected: [
99+
{
100+
target: `file://${path
101+
.resolve('./tests/fixtures/v4/basic/does-not-exist.js')
102+
.replace(/@/g, '%40')}`,
103+
range: { start: { line: 0, character: 8 }, end: { line: 0, character: 27 } },
104+
},
105+
],
106+
})
81107
})

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,9 @@ async function provideFileDirectiveCompletions(
15361536
return null
15371537
}
15381538

1539-
let pattern = /@config\s*(?<partial>'[^']*|"[^"]*)$/
1539+
let pattern = state.v4
1540+
? /@(config|plugin)\s*(?<partial>'[^']*|"[^"]*)$/
1541+
: /@config\s*(?<partial>'[^']*|"[^"]*)$/
15401542

15411543
let text = document.getText({ start: { line: position.line, character: 0 }, end: position })
15421544
let match = text.match(pattern)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export function getDocumentLinks(
1717
/@config\s*(?<path>'[^']+'|"[^"]+")/g,
1818
]
1919

20+
if (state.v4) {
21+
patterns.push(
22+
/@plugin\s*(?<path>'[^']+'|"[^"]+")/g,
23+
)
24+
}
25+
2026
return getDirectiveLinks(state, document, patterns, resolveTarget)
2127
}
2228

0 commit comments

Comments
 (0)