Skip to content

Commit a094787

Browse files
Fix initialization when path has parentheses (#1009)
* Fix initialization when path has parentheses * Add test * Add fixtures * Update changelog
1 parent f4b0e54 commit a094787

File tree

11 files changed

+110
-1
lines changed

11 files changed

+110
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ export class TW {
820820
console.debug('[GLOBAL] Checking selectors', documentSelector)
821821

822822
for (let selector of documentSelector) {
823-
let pattern = selector.pattern.replace(/[\[\]{}]/g, (m) => `\\${m}`)
823+
let pattern = selector.pattern.replace(/[\[\]{}()]/g, (m) => `\\${m}`)
824824

825825
if (pattern.startsWith('!')) {
826826
if (picomatch(pattern.slice(1), { dot: true })(fsPath)) {
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { test } from 'vitest'
2+
import * as path from 'node:path'
3+
import { withFixture, withWorkspace } from '../common'
4+
import { DidChangeWorkspaceFoldersNotification, HoverRequest } from 'vscode-languageserver'
5+
6+
withFixture('document-selection/basic', (c) => {
7+
test('basic: should provide hovers', async ({ expect }) => {
8+
let textDocument = await c.openDocument({
9+
text: '<div class="bg-[#000]">',
10+
})
11+
12+
let res = await c.sendRequest(HoverRequest.type, {
13+
textDocument,
14+
position: { line: 0, character: 13 },
15+
})
16+
17+
expect(res).toEqual({
18+
contents: {
19+
language: 'css',
20+
value:
21+
'.bg-\\[\\#000\\] {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity)) /* #000000 */;\n}',
22+
},
23+
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 21 } },
24+
})
25+
})
26+
})
27+
28+
withFixture('document-selection/(parens)', (c) => {
29+
test('parens: should provide hovers', async ({ expect }) => {
30+
let textDocument = await c.openDocument({
31+
text: '<div class="bg-[#000]">',
32+
})
33+
34+
let res = await c.sendRequest(HoverRequest.type, {
35+
textDocument,
36+
position: { line: 0, character: 13 },
37+
})
38+
39+
expect(res).toEqual({
40+
contents: {
41+
language: 'css',
42+
value:
43+
'.bg-\\[\\#000\\] {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity)) /* #000000 */;\n}',
44+
},
45+
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 21 } },
46+
})
47+
})
48+
})
49+
50+
withFixture('document-selection/[brackets]', (c) => {
51+
test('brackets: should provide hovers', async ({ expect }) => {
52+
let textDocument = await c.openDocument({
53+
text: '<div class="bg-[#000]">',
54+
})
55+
56+
let res = await c.sendRequest(HoverRequest.type, {
57+
textDocument,
58+
position: { line: 0, character: 13 },
59+
})
60+
61+
expect(res).toEqual({
62+
contents: {
63+
language: 'css',
64+
value:
65+
'.bg-\\[\\#000\\] {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity)) /* #000000 */;\n}',
66+
},
67+
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 21 } },
68+
})
69+
})
70+
})
71+
72+
withFixture('document-selection/{curlies}', (c) => {
73+
test('curlies: should provide hovers', async ({ expect }) => {
74+
let textDocument = await c.openDocument({
75+
text: '<div class="bg-[#000]">',
76+
})
77+
78+
let res = await c.sendRequest(HoverRequest.type, {
79+
textDocument,
80+
position: { line: 0, character: 13 },
81+
})
82+
83+
expect(res).toEqual({
84+
contents: {
85+
language: 'css',
86+
value:
87+
'.bg-\\[\\#000\\] {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity)) /* #000000 */;\n}',
88+
},
89+
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 21 } },
90+
})
91+
})
92+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="bg-[#f00]">test</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
//
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="bg-[#0f0]">test</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
//
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="bg-[#000]">test</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
//
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="bg-[#00f]">test</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
//
3+
}

packages/vscode-tailwindcss/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fix detection of v3 insiders builds ([#1007](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1007))
66
- Make sure language-specific settings are passed to our language server ([#1006](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1006))
7+
- Fix initialization when path contains parentheses ([#1009](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1009))
78

89
## 0.12.3
910

0 commit comments

Comments
 (0)