Skip to content

Commit

Permalink
Fix initialization when path has parentheses (#1009)
Browse files Browse the repository at this point in the history
* Fix initialization when path has parentheses

* Add test

* Add fixtures

* Update changelog
  • Loading branch information
thecrypticace authored Jul 2, 2024
1 parent f4b0e54 commit a094787
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/tailwindcss-language-server/src/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ export class TW {
console.debug('[GLOBAL] Checking selectors', documentSelector)

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

if (pattern.startsWith('!')) {
if (picomatch(pattern.slice(1), { dot: true })(fsPath)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { test } from 'vitest'
import * as path from 'node:path'
import { withFixture, withWorkspace } from '../common'
import { DidChangeWorkspaceFoldersNotification, HoverRequest } from 'vscode-languageserver'

withFixture('document-selection/basic', (c) => {
test('basic: should provide hovers', async ({ expect }) => {
let textDocument = await c.openDocument({
text: '<div class="bg-[#000]">',
})

let res = await c.sendRequest(HoverRequest.type, {
textDocument,
position: { line: 0, character: 13 },
})

expect(res).toEqual({
contents: {
language: 'css',
value:
'.bg-\\[\\#000\\] {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity)) /* #000000 */;\n}',
},
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 21 } },
})
})
})

withFixture('document-selection/(parens)', (c) => {
test('parens: should provide hovers', async ({ expect }) => {
let textDocument = await c.openDocument({
text: '<div class="bg-[#000]">',
})

let res = await c.sendRequest(HoverRequest.type, {
textDocument,
position: { line: 0, character: 13 },
})

expect(res).toEqual({
contents: {
language: 'css',
value:
'.bg-\\[\\#000\\] {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity)) /* #000000 */;\n}',
},
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 21 } },
})
})
})

withFixture('document-selection/[brackets]', (c) => {
test('brackets: should provide hovers', async ({ expect }) => {
let textDocument = await c.openDocument({
text: '<div class="bg-[#000]">',
})

let res = await c.sendRequest(HoverRequest.type, {
textDocument,
position: { line: 0, character: 13 },
})

expect(res).toEqual({
contents: {
language: 'css',
value:
'.bg-\\[\\#000\\] {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity)) /* #000000 */;\n}',
},
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 21 } },
})
})
})

withFixture('document-selection/{curlies}', (c) => {
test('curlies: should provide hovers', async ({ expect }) => {
let textDocument = await c.openDocument({
text: '<div class="bg-[#000]">',
})

let res = await c.sendRequest(HoverRequest.type, {
textDocument,
position: { line: 0, character: 13 },
})

expect(res).toEqual({
contents: {
language: 'css',
value:
'.bg-\\[\\#000\\] {\n --tw-bg-opacity: 1;\n background-color: rgb(0 0 0 / var(--tw-bg-opacity)) /* #000000 */;\n}',
},
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 21 } },
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="bg-[#f00]">test</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
//
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="bg-[#0f0]">test</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
//
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="bg-[#000]">test</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
//
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="bg-[#00f]">test</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
//
}
1 change: 1 addition & 0 deletions packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

## 0.12.3

Expand Down

0 comments on commit a094787

Please sign in to comment.