11import { AddressInfo , Server , Socket , createServer } from 'net' ;
22import { setTimeout } from 'timers/promises' ;
3- import { commands } from 'vscode' ;
3+ import { commands , workspace } from 'vscode' ;
44import { BazelLanguageServerTerminal } from './bazelLangaugeServerTerminal' ;
55import { Commands } from './commands' ;
66
@@ -11,6 +11,21 @@ const RETRY_INTERVAL = 5000; // ms
1111let server : Server | undefined ;
1212
1313function 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 (
21+ vmargs
22+ . split ( / \s + / )
23+ . filter ( ( x ) => x . includes ( 'java.bazel.staticProcessStreamSocket' ) ) [ 0 ]
24+ . split ( '=' ) [ 1 ]
25+ ) ;
26+ }
27+ }
28+
1429 return new Promise ( ( resolve ) => {
1530 if ( ! server ) {
1631 server = createServer ( ( sock : Socket ) => {
@@ -27,7 +42,7 @@ function startTCPServer(attempts = 0): Promise<number> {
2742 } ) ;
2843 } ) ;
2944 }
30- server . listen ( 0 , 'localhost' , ( ) => {
45+ server . listen ( port , 'localhost' , ( ) => {
3146 if ( server ) {
3247 const address = server . address ( ) ;
3348 if ( address ) {
0 commit comments