5
5
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
6
*/
7
7
8
- import { readFileSync } from 'node:fs' ;
8
+ // import { readFileSync } from 'node:fs';
9
9
import { Command } from 'commander' ;
10
- import lsp from 'vscode-languageserver' ;
10
+ import lsp from 'vscode-languageserver/node.js' ;
11
+ import { WebSocketMessageReader , WebSocketMessageWriter , toSocket } from 'vscode-ws-jsonrpc' ;
11
12
import { createLspConnection } from './lsp-connection.js' ;
13
+ import * as ws from 'ws' ;
12
14
13
15
const DEFAULT_LOG_LEVEL = lsp . MessageType . Info ;
14
- const { version } = JSON . parse ( readFileSync ( new URL ( '../package.json' , import . meta. url ) , { encoding : 'utf8' } ) ) ;
16
+ // const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), { encoding: 'utf8' }));
15
17
16
18
const program = new Command ( 'typescript-language-server' )
17
- . version ( version )
18
- . requiredOption ( '--stdio' , 'use stdio' )
19
+ // .version(version)
20
+ // .requiredOption('--stdio', 'use stdio')
19
21
. option ( '--log-level <logLevel>' , 'A number indicating the log level (4 = log, 3 = info, 2 = warn, 1 = error). Defaults to `2`.' )
20
22
. parse ( process . argv ) ;
21
23
@@ -30,6 +32,21 @@ if (options.logLevel) {
30
32
}
31
33
}
32
34
33
- createLspConnection ( {
34
- showMessageLevel : logLevel as lsp . MessageType ,
35
- } ) . listen ( ) ;
35
+ const port = 9090 ;
36
+ const wss = new ws . WebSocketServer ( { port } ) ;
37
+
38
+ let connection : lsp . Connection | undefined = undefined ;
39
+
40
+ wss . on ( 'connection' , ( socket ) => {
41
+ if ( connection ) {
42
+ connection . dispose ( ) ;
43
+ }
44
+ const sock = toSocket ( socket ) ;
45
+ const reader = new WebSocketMessageReader ( sock ) ;
46
+ const writer = new WebSocketMessageWriter ( sock ) ;
47
+ connection = lsp . createConnection ( lsp . ProposedFeatures . all , reader , writer ) ;
48
+
49
+ createLspConnection ( {
50
+ showMessageLevel : logLevel as lsp . MessageType ,
51
+ } , connection ) . listen ( ) ;
52
+ } ) ;
0 commit comments