@@ -4,7 +4,7 @@ import * as net from 'net';
44import * as path from 'path' ;
55import { CancellationToken , CodeActionKind , commands , ConfigurationTarget , DocumentSelector , EventEmitter , ExtensionContext , extensions , languages , Location , ProgressLocation , TextEditor , Uri , ViewColumn , window , workspace , WorkspaceConfiguration } from "vscode" ;
66import { ConfigurationParams , ConfigurationRequest , LanguageClientOptions , Location as LSLocation , MessageType , Position as LSPosition , TextDocumentPositionParams , WorkspaceEdit , StaticFeature , ClientCapabilities , FeatureState , TelemetryEventNotification } from "vscode-languageclient" ;
7- import { LanguageClient , StreamInfo } from "vscode-languageclient/node" ;
7+ import { LanguageClient , ServerOptions , StreamInfo } from "vscode-languageclient/node" ;
88import { apiManager } from "./apiManager" ;
99import * as buildPath from './buildpath' ;
1010import { javaRefactorKinds , RefactorDocumentProvider } from "./codeActionProvider" ;
@@ -42,6 +42,7 @@ import { listJdks, sortJdksBySource, sortJdksByVersion } from './jdkUtils';
4242import { ClientCodeActionProvider } from './clientCodeActionProvider' ;
4343import { BuildFileSelector } from './buildFilesSelector' ;
4444import { extendedOutlineQuickPick } from "./outline/extendedOutlineQuickPick" ;
45+ import { startWithStdioFallback } from './standardLanguageClientStart' ;
4546
4647const extensionName = 'Language Support for Java' ;
4748const GRADLE_CHECKSUM = "gradle/checksum/prompt" ;
@@ -50,6 +51,7 @@ const USE_JAVA = "Use Java ";
5051const AS_GRADLE_JVM = " as Gradle JVM" ;
5152const UPGRADE_GRADLE = "Upgrade Gradle to " ;
5253const GRADLE_IMPORT_JVM = "java.import.gradle.java.home" ;
54+ const PIPE_START_TIMEOUT_MS = 10000 ;
5355export const JAVA_SELECTOR : DocumentSelector = [
5456 { scheme : "file" , language : "java" , pattern : "**/*.java" } ,
5557 { scheme : "jdt" , language : "java" , pattern : "**/*.class" } ,
@@ -59,6 +61,8 @@ export const JAVA_SELECTOR: DocumentSelector = [
5961export class StandardLanguageClient {
6062
6163 private languageClient : LanguageClient ;
64+ private serverOptions : ServerOptions ;
65+ private clientOptions : LanguageClientOptions ;
6266 private status : ClientStatus = ClientStatus . uninitialized ;
6367
6468 public async initialize ( context : ExtensionContext , requirements : RequirementsData , clientOptions : LanguageClientOptions , workspacePath : string , jdtEventEmitter : EventEmitter < Uri > ) : Promise < void > {
@@ -85,7 +89,7 @@ export class StandardLanguageClient {
8589 }
8690 } ) ;
8791
88- let serverOptions ;
92+ let serverOptions : ServerOptions ;
8993 const port = process . env [ 'JDTLS_SERVER_PORT' ] ;
9094 if ( ! port ) {
9195 const lsPort = process . env [ 'JDTLS_CLIENT_PORT' ] ;
@@ -105,19 +109,26 @@ export class StandardLanguageClient {
105109 // used during development
106110 serverOptions = awaitServerConnection . bind ( null , port ) ;
107111 }
112+ this . serverOptions = serverOptions ;
113+ this . clientOptions = clientOptions ;
108114
109115 // Create the language client and start the client.
110- this . languageClient = new TracingLanguageClient ( 'java' , extensionName , serverOptions , clientOptions , DEBUG ) ;
111- this . languageClient . registerFeature ( new DisableWillRenameFeature ( ) ) ;
116+ this . languageClient = this . createLanguageClient ( serverOptions , clientOptions ) ;
112117
113118 this . registerCommandsForStandardServer ( context , jdtEventEmitter ) ;
114- fileEventHandler . registerFileEventHandlers ( this . languageClient , context ) ;
119+ fileEventHandler . registerFileEventHandlers ( ( ) => this . languageClient , context ) ;
115120
116121 collectBuildFilePattern ( extensions . all ) ;
117122
118123 this . status = ClientStatus . initialized ;
119124 }
120125
126+ private createLanguageClient ( serverOptions : ServerOptions , clientOptions : LanguageClientOptions ) : LanguageClient {
127+ const languageClient = new TracingLanguageClient ( 'java' , extensionName , serverOptions , clientOptions , DEBUG ) ;
128+ languageClient . registerFeature ( new DisableWillRenameFeature ( ) ) ;
129+ return languageClient ;
130+ }
131+
121132 public registerLanguageClientActions ( context : ExtensionContext , hasImported : boolean , jdtEventEmitter : EventEmitter < Uri > ) {
122133 activationProgressNotification . showProgress ( ) ;
123134 this . languageClient . onNotification ( StatusNotification . type , ( report ) => {
@@ -770,7 +781,17 @@ export class StandardLanguageClient {
770781 public start ( ) : Promise < void > {
771782 if ( this . languageClient && this . status === ClientStatus . initialized ) {
772783 this . status = ClientStatus . starting ;
773- return this . languageClient . start ( ) ;
784+ return startWithStdioFallback ( {
785+ languageClient : this . languageClient ,
786+ serverOptions : this . serverOptions ,
787+ createLanguageClient : ( serverOptions ) => this . createLanguageClient ( serverOptions , this . clientOptions ) ,
788+ pipeStartTimeout : PIPE_START_TIMEOUT_MS ,
789+ onFallback : ( error ) => logger . warn ( `Falling back to 'stdio' (from 'pipe') because starting the pipe transport failed: ${ error } ` ) ,
790+ onStopError : ( error ) => logger . warn ( `Failed to stop the pipe transport client before falling back to 'stdio': ${ error } ` ) ,
791+ } ) . then ( result => {
792+ this . languageClient = result . client ;
793+ this . serverOptions = result . serverOptions ;
794+ } ) ;
774795 }
775796 }
776797
0 commit comments