@@ -146,7 +146,11 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
146146 const workspacePath = path . resolve ( storagePath + '/jdt_ws' ) ;
147147 const syntaxServerWorkspacePath = path . resolve ( storagePath + '/ss_ws' ) ;
148148
149- const serverMode = getJavaServerMode ( ) ;
149+ let serverMode = getJavaServerMode ( ) ;
150+ const isWorkspaceTrusted = ( workspace as any ) . isTrusted ; // TODO: use workspace.isTrusted directly when other clients catch up to adopt 1.56.0
151+ if ( isWorkspaceTrusted !== undefined && ! isWorkspaceTrusted ) { // keep compatibility for old engines < 1.56.0
152+ serverMode = ServerMode . LIGHTWEIGHT ;
153+ }
150154 commands . executeCommand ( 'setContext' , 'java:serverMode' , serverMode ) ;
151155 const isDebugModeByClientPort = ! ! process . env [ 'SYNTAXLS_CLIENT_PORT' ] || ! ! process . env [ 'JDTLS_CLIENT_PORT' ] ;
152156 const requireSyntaxServer = ( serverMode !== ServerMode . STANDARD ) && ( ! isDebugModeByClientPort || ! ! process . env [ 'SYNTAXLS_CLIENT_PORT' ] ) ;
@@ -211,7 +215,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
211215 outputChannelName : extensionName
212216 } ;
213217
214- apiManager . initialize ( requirements ) ;
218+ apiManager . initialize ( requirements , serverMode ) ;
215219
216220 if ( requireSyntaxServer ) {
217221 if ( process . env [ 'SYNTAXLS_CLIENT_PORT' ] ) {
@@ -274,6 +278,16 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
274278 * @param force force to switch server mode without asking
275279 */
276280 commands . registerCommand ( Commands . SWITCH_SERVER_MODE , async ( switchTo : ServerMode , force : boolean = false ) => {
281+ const isWorkspaceTrusted = ( workspace as any ) . isTrusted ;
282+ if ( isWorkspaceTrusted !== undefined && ! isWorkspaceTrusted ) { // keep compatibility for old engines < 1.56.0
283+ const button = "Manage Workspace Trust" ;
284+ const choice = await window . showInformationMessage ( "For security concern, Java language server cannot be switched to Standard mode in untrusted workspaces." , button ) ;
285+ if ( choice === button ) {
286+ commands . executeCommand ( "workbench.action.manageTrust" ) ;
287+ }
288+ return ;
289+ }
290+
277291 const clientStatus : ClientStatus = standardClient . getClientStatus ( ) ;
278292 if ( clientStatus === ClientStatus . Starting || clientStatus === ClientStatus . Started ) {
279293 return ;
@@ -333,6 +347,15 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
333347 if ( requireStandardServer ) {
334348 startStandardServer ( context , requirements , clientOptions , workspacePath , resolve ) ;
335349 }
350+
351+ const onDidGrantWorkspaceTrust = ( workspace as any ) . onDidGrantWorkspaceTrust ;
352+ if ( onDidGrantWorkspaceTrust !== undefined ) { // keep compatibility for old engines < 1.56.0
353+ context . subscriptions . push ( onDidGrantWorkspaceTrust ( ( ) => {
354+ if ( getJavaServerMode ( ) !== ServerMode . LIGHTWEIGHT ) {
355+ commands . executeCommand ( Commands . SWITCH_SERVER_MODE , ServerMode . STANDARD , true ) ;
356+ }
357+ } ) ) ;
358+ }
336359 } ) ;
337360 } ) ;
338361}
0 commit comments