11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT license.
33
4- import { Extension , ExtensionContext , extensions } from "vscode" ;
5- import { dispose as disposeTelemetryWrapper , initializeFromJsonFile , instrumentOperation } from "vscode-extension-telemetry-wrapper" ;
4+ import { commands , Event , Extension , ExtensionContext , extensions , Uri } from "vscode" ;
5+ import { dispose as disposeTelemetryWrapper , initializeFromJsonFile , instrumentOperation , instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper" ;
6+ import { Commands } from "./commands" ;
67import { Context } from "./constants" ;
78import { contextManager } from "./contextManager" ;
89import { LibraryController } from "./controllers/libraryController" ;
@@ -17,6 +18,38 @@ export async function activate(context: ExtensionContext): Promise<any> {
1718}
1819
1920async function activateExtension ( _operationId : string , context : ExtensionContext ) : Promise < void > {
21+ const extension : Extension < any > | undefined = extensions . getExtension ( "redhat.java" ) ;
22+ if ( extension && extension . isActive ) {
23+ const extensionApi : any = extension . exports ;
24+ if ( ! extensionApi ) {
25+ return ;
26+ }
27+
28+ serverMode = extensionApi . serverMode ;
29+
30+ if ( extensionApi . onDidClasspathUpdate ) {
31+ const onDidClasspathUpdate : Event < Uri > = extensionApi . onDidClasspathUpdate ;
32+ context . subscriptions . push ( onDidClasspathUpdate ( async ( ) => {
33+ await commands . executeCommand ( Commands . VIEW_PACKAGE_REFRESH , /* debounce = */ true ) ;
34+ } ) ) ;
35+ }
36+
37+ if ( extensionApi . onDidServerModeChange ) {
38+ const onDidServerModeChange : Event < string > = extensionApi . onDidServerModeChange ;
39+ context . subscriptions . push ( onDidServerModeChange ( async ( mode : string ) => {
40+ serverMode = mode ;
41+ commands . executeCommand ( Commands . VIEW_PACKAGE_REFRESH , /* debounce = */ false ) ;
42+ } ) ) ;
43+ }
44+
45+ if ( extensionApi . onDidProjectsImport ) {
46+ const onDidProjectsImport : Event < Uri [ ] > = extensionApi . onDidProjectsImport ;
47+ context . subscriptions . push ( onDidProjectsImport ( async ( ) => {
48+ commands . executeCommand ( Commands . VIEW_PACKAGE_REFRESH , /* debounce = */ true ) ;
49+ } ) ) ;
50+ }
51+ }
52+
2053 Settings . initialize ( context ) ;
2154 contextManager . initialize ( context ) ;
2255 setMavenExtensionState ( ) ;
@@ -28,6 +61,13 @@ async function activateExtension(_operationId: string, context: ExtensionContext
2861 contextManager . setContextValue ( Context . EXTENSION_ACTIVATED , true ) ;
2962
3063 initExpService ( context ) ;
64+
65+ context . subscriptions . push ( instrumentOperationAsVsCodeCommand ( Commands . JAVA_PROJECT_SWITCH_SERVER_MODE , async ( ) => {
66+ if ( isSwitchingServer ( ) ) {
67+ return ;
68+ }
69+ await commands . executeCommand ( Commands . JAVA_SWITCH_SERVER_MODE , "Standard" /*mode*/ ) ;
70+ } ) ) ;
3171}
3272
3373// determine if the add dependency shortcut will show or not
@@ -47,3 +87,22 @@ function setMavenExtensionState() {
4787export async function deactivate ( ) {
4888 await disposeTelemetryWrapper ( ) ;
4989}
90+
91+ export function isStandardServerReady ( ) : boolean {
92+ // undefined serverMode indicates an older version language server
93+ if ( serverMode === undefined ) {
94+ return true ;
95+ }
96+
97+ if ( serverMode !== "Standard" ) {
98+ return false ;
99+ }
100+
101+ return true ;
102+ }
103+
104+ export function isSwitchingServer ( ) : boolean {
105+ return serverMode === "Hybrid" ;
106+ }
107+
108+ let serverMode : string | undefined ;
0 commit comments