1
1
import * as path from 'node:path'
2
2
import { beforeAll , describe } from 'vitest'
3
- import { connect } from './connection'
3
+ import { connect , launch } from './connection'
4
4
import {
5
5
CompletionRequest ,
6
6
ConfigurationRequest ,
@@ -12,6 +12,7 @@ import {
12
12
RegistrationRequest ,
13
13
InitializeParams ,
14
14
DidOpenTextDocumentParams ,
15
+ MessageType ,
15
16
} from 'vscode-languageserver-protocol'
16
17
import type { ClientCapabilities , ProtocolConnection } from 'vscode-languageclient'
17
18
import type { Feature } from '@tailwindcss/language-service/src/features'
@@ -44,6 +45,14 @@ interface FixtureContext
44
45
}
45
46
46
47
export interface InitOptions {
48
+ /**
49
+ * How to connect to the LSP:
50
+ * - `in-band` runs the server in the same process (default)
51
+ * - `spawn` launches the binary as a separate process, connects via stdio,
52
+ * and requires a rebuild of the server after making changes.
53
+ */
54
+ mode ?: 'in-band' | 'spawn'
55
+
47
56
/**
48
57
* Extra initialization options to pass to the LSP
49
58
*/
@@ -57,7 +66,23 @@ export async function init(
57
66
let settings = { }
58
67
let docSettings = new Map < string , Settings > ( )
59
68
60
- const { client } = await connect ( )
69
+ const { client } = opts ?. mode === 'spawn' ? await launch ( ) : await connect ( )
70
+
71
+ if ( opts ?. mode === 'spawn' ) {
72
+ client . onNotification ( 'window/logMessage' , ( { message, type } ) => {
73
+ if ( type === MessageType . Error ) {
74
+ console . error ( message )
75
+ } else if ( type === MessageType . Warning ) {
76
+ console . warn ( message )
77
+ } else if ( type === MessageType . Info ) {
78
+ console . info ( message )
79
+ } else if ( type === MessageType . Log ) {
80
+ console . log ( message )
81
+ } else if ( type === MessageType . Debug ) {
82
+ console . debug ( message )
83
+ }
84
+ } )
85
+ }
61
86
62
87
const capabilities : ClientCapabilities = {
63
88
textDocument : {
0 commit comments