-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support for
source(…)
feature in v4 (#1083)
This PR mades a fair number of changes to improve the developer experience in v4. Most of it is related to `@source` and `source(…)` but there are some additional tweaks: - [x] Make sure `@import "…" source(…)` does not issue syntax warnings - [x] Make sure `@import "…" theme(…)` does not issue syntax warnings - [x] Make sure `@import "…" prefix(…)` does not issue syntax warnings - [x] Make sure `@tailwind utilities source(…)` isn't diagnosed as invalid - [x] Add suggestions for `@theme` options - [x] Add suggestions for `@import "…" theme(…)` options - [x] Directory auto-completion for `source(…)` - [x] Directory auto-completion for `@source "…"` - [x] Don’t suggest TypeScript declaration files for `@config`, `@plugin`, and `@source` - [x] In a new workspace creating/editing a CSS file should check if it's the language server needs to start. - [x] Show brace expansion when hovering `@source` - [x] Highlight `@import "…" source(…)` properly - [x] Highlight `@import "…" theme(…)` properly - [x] Highlight `@import "…" prefix(…)` properly - [x] Highlight `@tailwind utilities source(…)` properly - [x] Highlight uses of `source(none)` explicitly - [x] Link paths in valid uses of `source("…")` - [x] Don't link Windows-style paths in `@source`, `@config`, and `@plugin` - [x] Warn that `@source none` is invalid - [x] Highlight `@source none` as invalid (theme-dependent) - [x] Warn when `source(…)` is not passed anything - [x] Warn when `source(none)` is mispelled - [x] Warn when a v4 project uses `@tailwind base` or `@tailwind components` - [x] Warn when non-POSIX paths are passed to `@source` and `source(…)` - [x] Warn when `@tailwind base` is used in a v4 project - [x] Warn when `@tailwind preflight` is used in a v4 project - [x] Warn when `@tailwind components` is used in a v4 project - [x] Warn when `@tailwind screens` is used in a v4 project - [x] Warn when `@tailwind variants` is used in a v4 project I had some stretch goals but I don't think I'll get to them in this PR unless we think they're important enough to hold up the PR: - [ ] Warn when braces surround a single item in `@source` globs - [ ] Warn when unsupported glob syntax is used in `@source` - [ ] Warn when a v4 project uses `@import "tailwindcss/tailwind"` - [ ] Warn when a v4 project uses `@import "tailwindcss/tailwind.css"` - [ ] Highlight glob parts in `@source "…"` strings - [ ] Auto-complete `source(none)` when typing `source(…)` --------- Co-authored-by: Robin Malfait <[email protected]>
- Loading branch information
1 parent
55050a4
commit 20e1448
Showing
28 changed files
with
1,276 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
packages/tailwindcss-language-server/tests/diagnostics/source-diagnostics.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { expect, test } from 'vitest' | ||
import { withFixture } from '../common' | ||
|
||
withFixture('v4/basic', (c) => { | ||
function runTest(name, { code, expected, language }) { | ||
test(name, async () => { | ||
let promise = new Promise((resolve) => { | ||
c.onNotification('textDocument/publishDiagnostics', ({ diagnostics }) => { | ||
resolve(diagnostics) | ||
}) | ||
}) | ||
|
||
let doc = await c.openDocument({ text: code, lang: language }) | ||
let diagnostics = await promise | ||
|
||
expected = JSON.parse(JSON.stringify(expected).replaceAll('{{URI}}', doc.uri)) | ||
|
||
expect(diagnostics).toMatchObject(expected) | ||
}) | ||
} | ||
|
||
runTest('Source directives require paths', { | ||
language: 'css', | ||
code: ` | ||
@import 'tailwindcss' source(); | ||
@import 'tailwindcss' source(''); | ||
@import 'tailwindcss' source(""); | ||
@tailwind utilities source(); | ||
@tailwind utilities source(''); | ||
@tailwind utilities source(""); | ||
`, | ||
expected: [ | ||
{ | ||
code: 'invalidSourceDirective', | ||
message: 'The source directive requires a path to a directory.', | ||
range: { | ||
start: { line: 1, character: 35 }, | ||
end: { line: 1, character: 35 }, | ||
}, | ||
}, | ||
{ | ||
code: 'invalidSourceDirective', | ||
message: 'The source directive requires a path to a directory.', | ||
range: { | ||
start: { line: 2, character: 35 }, | ||
end: { line: 2, character: 37 }, | ||
}, | ||
}, | ||
{ | ||
code: 'invalidSourceDirective', | ||
message: 'The source directive requires a path to a directory.', | ||
range: { | ||
start: { line: 3, character: 35 }, | ||
end: { line: 3, character: 37 }, | ||
}, | ||
}, | ||
{ | ||
code: 'invalidSourceDirective', | ||
message: 'The source directive requires a path to a directory.', | ||
range: { | ||
start: { line: 4, character: 33 }, | ||
end: { line: 4, character: 33 }, | ||
}, | ||
}, | ||
{ | ||
code: 'invalidSourceDirective', | ||
message: 'The source directive requires a path to a directory.', | ||
range: { | ||
start: { line: 5, character: 33 }, | ||
end: { line: 5, character: 35 }, | ||
}, | ||
}, | ||
{ | ||
code: 'invalidSourceDirective', | ||
message: 'The source directive requires a path to a directory.', | ||
range: { | ||
start: { line: 6, character: 33 }, | ||
end: { line: 6, character: 35 }, | ||
}, | ||
}, | ||
], | ||
}) | ||
|
||
runTest('source(none) must not be misspelled', { | ||
language: 'css', | ||
code: ` | ||
@import 'tailwindcss' source(no); | ||
@tailwind utilities source(no); | ||
`, | ||
expected: [ | ||
{ | ||
code: 'invalidSourceDirective', | ||
message: '`source(no)` is invalid. Did you mean `source(none)`?', | ||
range: { | ||
start: { line: 1, character: 35 }, | ||
end: { line: 1, character: 37 }, | ||
}, | ||
}, | ||
{ | ||
code: 'invalidSourceDirective', | ||
message: '`source(no)` is invalid. Did you mean `source(none)`?', | ||
range: { | ||
start: { line: 2, character: 33 }, | ||
end: { line: 2, character: 35 }, | ||
}, | ||
}, | ||
], | ||
}) | ||
|
||
runTest('source("…") does not produce diagnostics', { | ||
language: 'css', | ||
code: ` | ||
@import 'tailwindcss' source('../app'); | ||
@tailwind utilities source('../app'); | ||
@import 'tailwindcss' source("../app"); | ||
@tailwind utilities source("../app"); | ||
`, | ||
expected: [], | ||
}) | ||
|
||
runTest('paths given to source("…") must error when not POSIX', { | ||
language: 'css', | ||
code: String.raw` | ||
@import 'tailwindcss' source('C:\\absolute\\path'); | ||
@import 'tailwindcss' source('C:relative.txt'); | ||
`, | ||
expected: [ | ||
{ | ||
code: 'invalidSourceDirective', | ||
message: | ||
'POSIX-style paths are required with `source(…)` but `C:\\absolute\\path` is a Windows-style path.', | ||
range: { | ||
start: { line: 1, character: 35 }, | ||
end: { line: 1, character: 55 }, | ||
}, | ||
}, | ||
{ | ||
code: 'invalidSourceDirective', | ||
message: | ||
'POSIX-style paths are required with `source(…)` but `C:relative.txt` is a Windows-style path.', | ||
range: { | ||
start: { line: 2, character: 35 }, | ||
end: { line: 2, character: 51 }, | ||
}, | ||
}, | ||
], | ||
}) | ||
}) |
Oops, something went wrong.