1
1
import { AddressInfo , Server , Socket , createServer } from 'net' ;
2
2
import { setTimeout } from 'timers/promises' ;
3
- import { commands } from 'vscode' ;
3
+ import { commands , workspace } from 'vscode' ;
4
4
import { BazelLanguageServerTerminal } from './bazelLangaugeServerTerminal' ;
5
5
import { Commands } from './commands' ;
6
6
@@ -11,6 +11,16 @@ const RETRY_INTERVAL = 5000; // ms
11
11
let server : Server | undefined ;
12
12
13
13
function startTCPServer ( attempts = 0 ) : Promise < number > {
14
+ let port = 0 ;
15
+ if ( workspace . getConfiguration ( 'java' ) . has ( 'jdt.ls.vmargs' ) ) {
16
+ const vmargs = workspace
17
+ . getConfiguration ( 'java' )
18
+ . get < string > ( 'jdt.ls.vmargs' ) ;
19
+ if ( vmargs ?. includes ( 'java.bazel.staticProcessStreamSocket' ) ) {
20
+ port = parseInt ( vmargs . split ( 'java.bazel.staticProcessStreamSocket=' ) [ 1 ] ) ;
21
+ }
22
+ }
23
+
14
24
return new Promise ( ( resolve ) => {
15
25
if ( ! server ) {
16
26
server = createServer ( ( sock : Socket ) => {
@@ -27,7 +37,7 @@ function startTCPServer(attempts = 0): Promise<number> {
27
37
} ) ;
28
38
} ) ;
29
39
}
30
- server . listen ( 0 , 'localhost' , ( ) => {
40
+ server . listen ( port , 'localhost' , ( ) => {
31
41
if ( server ) {
32
42
const address = server . address ( ) ;
33
43
if ( address ) {
0 commit comments