Skip to content

Commit 8e3370d

Browse files
committed
wip
1 parent 336ff76 commit 8e3370d

File tree

4 files changed

+110
-3
lines changed

4 files changed

+110
-3
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { register } from 'node:module'
2+
import { pathToFileURL } from 'node:url'
3+
import { MessageChannel } from 'node:worker_threads'
4+
5+
export function register() {
6+
const { port1, port2 } = new MessageChannel()
7+
8+
// Port 1 is the "local" port
9+
port1.on('message', (msg) => console.log(msg))
10+
port1.unref()
11+
12+
return {}
13+
}
14+
15+
// // This example showcases how a message channel can be used to
16+
// // communicate with the hooks, by sending `port2` to the hooks.
17+
// const { port1, port2 } = new MessageChannel()
18+
19+
// port1.on('message', (msg) => {
20+
// console.log(msg)
21+
// })
22+
// port1.unref()
23+
24+
// register('./my-hooks.mjs', {
25+
// parentURL: pathToFileURL(__filename),
26+
// data: { number: 1, port: port2 },
27+
// transferList: [port2],
28+
// })

packages/tailwindcss-language-server/src/testing/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { afterAll, onTestFinished, test, TestOptions } from 'vitest'
22
import * as fs from 'node:fs/promises'
3+
import * as os from 'node:os'
34
import * as path from 'node:path'
45
import * as proc from 'node:child_process'
56
import dedent from 'dedent'

packages/tailwindcss-language-server/tests/common.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'node:path'
22
import { beforeAll, describe } from 'vitest'
3-
import { connect } from './connection'
3+
import { connect, launch } from './connection'
44
import {
55
CompletionRequest,
66
ConfigurationRequest,
@@ -43,14 +43,25 @@ interface FixtureContext
4343
}
4444
}
4545

46+
export interface InitOptions {
47+
/**
48+
* How to connect to the LSP:
49+
* - `in-band` uses the same process
50+
* - `launch-binary` launches the binary as a separate process and connects
51+
* to stdin/stdout
52+
*/
53+
mode?: 'in-band' | 'spawn'
54+
}
55+
4656
export async function init(
4757
fixture: string | string[],
4858
options: Record<string, any> = {},
59+
initOpts: InitOptions = {},
4960
): Promise<FixtureContext> {
5061
let settings = {}
5162
let docSettings = new Map<string, Settings>()
5263

53-
const { client } = await connect()
64+
const { client } = initOpts?.mode === 'spawn' ? await launch() : await connect()
5465

5566
const capabilities: ClientCapabilities = {
5667
textDocument: {

packages/tailwindcss-language-server/tests/env/v4.test.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'vitest'
22
import { init } from '../common'
33
import { HoverRequest } from 'vscode-languageserver'
4-
import { defineTest, json } from '../../src/testing'
4+
import { css, defineTest, js, json } from '../../src/testing'
55
import dedent from 'dedent'
66
import { CompletionRequest } from 'vscode-languageserver-protocol'
77

@@ -60,6 +60,73 @@ defineTest({
6060
},
6161
})
6262

63+
defineTest({
64+
name: 'v4, no npm, with plugins',
65+
fs: {
66+
'app.css': css`
67+
@import 'tailwindcss';
68+
@plugin "./plugin.js";
69+
`,
70+
'plugin.js': js`
71+
import plugin from 'tailwindcss/plugin'
72+
73+
export default plugin(function ({ addUtilities }) {
74+
addUtilities({
75+
'.example': {
76+
color: 'red',
77+
},
78+
})
79+
})
80+
`,
81+
},
82+
83+
prepare: async ({ root }) => ({
84+
c: await init(
85+
root,
86+
{},
87+
{
88+
mode: 'spawn',
89+
},
90+
),
91+
}),
92+
handle: async ({ c }) => {
93+
let textDocument = await c.openDocument({
94+
lang: 'html',
95+
text: '<div class="example">',
96+
})
97+
98+
expect(c.project).toMatchObject({
99+
tailwind: {
100+
version: '4.0.0',
101+
isDefaultVersion: true,
102+
},
103+
})
104+
105+
let hover = await c.sendRequest(HoverRequest.type, {
106+
textDocument,
107+
108+
// <div class="example">
109+
// ^
110+
position: { line: 0, character: 13 },
111+
})
112+
113+
expect(hover).toEqual({
114+
contents: {
115+
language: 'css',
116+
value: dedent`
117+
.example {
118+
color: red;
119+
}
120+
`,
121+
},
122+
range: {
123+
start: { line: 0, character: 12 },
124+
end: { line: 0, character: 19 },
125+
},
126+
})
127+
},
128+
})
129+
63130
defineTest({
64131
name: 'v4, with npm, uses local',
65132
fs: {

0 commit comments

Comments
 (0)