From a094787c6c8b849b7fedf701be8d559959a6401a Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 2 Jul 2024 15:15:00 -0400 Subject: [PATCH] Fix initialization when path has parentheses (#1009) * Fix initialization when path has parentheses * Add test * Add fixtures * Update changelog --- .../tailwindcss-language-server/src/tw.ts | 2 +- .../tests/env/document-selection.test.js | 92 +++++++++++++++++++ .../document-selection/(parens)/file.html | 1 + .../(parens)/tailwind.config.js | 3 + .../document-selection/[brackets]/file.html | 1 + .../[brackets]/tailwind.config.js | 3 + .../document-selection/basic/file.html | 1 + .../basic/tailwind.config.js | 3 + .../document-selection/{curlies}/file.html | 1 + .../{curlies}/tailwind.config.js | 3 + packages/vscode-tailwindcss/CHANGELOG.md | 1 + 11 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 packages/tailwindcss-language-server/tests/env/document-selection.test.js create mode 100644 packages/tailwindcss-language-server/tests/fixtures/document-selection/(parens)/file.html create mode 100644 packages/tailwindcss-language-server/tests/fixtures/document-selection/(parens)/tailwind.config.js create mode 100644 packages/tailwindcss-language-server/tests/fixtures/document-selection/[brackets]/file.html create mode 100644 packages/tailwindcss-language-server/tests/fixtures/document-selection/[brackets]/tailwind.config.js create mode 100644 packages/tailwindcss-language-server/tests/fixtures/document-selection/basic/file.html create mode 100644 packages/tailwindcss-language-server/tests/fixtures/document-selection/basic/tailwind.config.js create mode 100644 packages/tailwindcss-language-server/tests/fixtures/document-selection/{curlies}/file.html create mode 100644 packages/tailwindcss-language-server/tests/fixtures/document-selection/{curlies}/tailwind.config.js diff --git a/packages/tailwindcss-language-server/src/tw.ts b/packages/tailwindcss-language-server/src/tw.ts index ecfbee0a..4cffc77b 100644 --- a/packages/tailwindcss-language-server/src/tw.ts +++ b/packages/tailwindcss-language-server/src/tw.ts @@ -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)) { diff --git a/packages/tailwindcss-language-server/tests/env/document-selection.test.js b/packages/tailwindcss-language-server/tests/env/document-selection.test.js new file mode 100644 index 00000000..0789760a --- /dev/null +++ b/packages/tailwindcss-language-server/tests/env/document-selection.test.js @@ -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: '
', + }) + + 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: '
', + }) + + 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: '
', + }) + + 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: '
', + }) + + 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 } }, + }) + }) +}) diff --git a/packages/tailwindcss-language-server/tests/fixtures/document-selection/(parens)/file.html b/packages/tailwindcss-language-server/tests/fixtures/document-selection/(parens)/file.html new file mode 100644 index 00000000..434d0847 --- /dev/null +++ b/packages/tailwindcss-language-server/tests/fixtures/document-selection/(parens)/file.html @@ -0,0 +1 @@ +
test
diff --git a/packages/tailwindcss-language-server/tests/fixtures/document-selection/(parens)/tailwind.config.js b/packages/tailwindcss-language-server/tests/fixtures/document-selection/(parens)/tailwind.config.js new file mode 100644 index 00000000..40b8bc3f --- /dev/null +++ b/packages/tailwindcss-language-server/tests/fixtures/document-selection/(parens)/tailwind.config.js @@ -0,0 +1,3 @@ +export default { + // +} diff --git a/packages/tailwindcss-language-server/tests/fixtures/document-selection/[brackets]/file.html b/packages/tailwindcss-language-server/tests/fixtures/document-selection/[brackets]/file.html new file mode 100644 index 00000000..5ae2a5d8 --- /dev/null +++ b/packages/tailwindcss-language-server/tests/fixtures/document-selection/[brackets]/file.html @@ -0,0 +1 @@ +
test
diff --git a/packages/tailwindcss-language-server/tests/fixtures/document-selection/[brackets]/tailwind.config.js b/packages/tailwindcss-language-server/tests/fixtures/document-selection/[brackets]/tailwind.config.js new file mode 100644 index 00000000..40b8bc3f --- /dev/null +++ b/packages/tailwindcss-language-server/tests/fixtures/document-selection/[brackets]/tailwind.config.js @@ -0,0 +1,3 @@ +export default { + // +} diff --git a/packages/tailwindcss-language-server/tests/fixtures/document-selection/basic/file.html b/packages/tailwindcss-language-server/tests/fixtures/document-selection/basic/file.html new file mode 100644 index 00000000..91f93485 --- /dev/null +++ b/packages/tailwindcss-language-server/tests/fixtures/document-selection/basic/file.html @@ -0,0 +1 @@ +
test
diff --git a/packages/tailwindcss-language-server/tests/fixtures/document-selection/basic/tailwind.config.js b/packages/tailwindcss-language-server/tests/fixtures/document-selection/basic/tailwind.config.js new file mode 100644 index 00000000..40b8bc3f --- /dev/null +++ b/packages/tailwindcss-language-server/tests/fixtures/document-selection/basic/tailwind.config.js @@ -0,0 +1,3 @@ +export default { + // +} diff --git a/packages/tailwindcss-language-server/tests/fixtures/document-selection/{curlies}/file.html b/packages/tailwindcss-language-server/tests/fixtures/document-selection/{curlies}/file.html new file mode 100644 index 00000000..b536d149 --- /dev/null +++ b/packages/tailwindcss-language-server/tests/fixtures/document-selection/{curlies}/file.html @@ -0,0 +1 @@ +
test
diff --git a/packages/tailwindcss-language-server/tests/fixtures/document-selection/{curlies}/tailwind.config.js b/packages/tailwindcss-language-server/tests/fixtures/document-selection/{curlies}/tailwind.config.js new file mode 100644 index 00000000..40b8bc3f --- /dev/null +++ b/packages/tailwindcss-language-server/tests/fixtures/document-selection/{curlies}/tailwind.config.js @@ -0,0 +1,3 @@ +export default { + // +} diff --git a/packages/vscode-tailwindcss/CHANGELOG.md b/packages/vscode-tailwindcss/CHANGELOG.md index caff8e99..71cc3f94 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -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