1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
3
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" ;
6
7
import { Context } from "./constants" ;
7
8
import { contextManager } from "./contextManager" ;
8
9
import { LibraryController } from "./controllers/libraryController" ;
@@ -17,6 +18,38 @@ export async function activate(context: ExtensionContext): Promise<any> {
17
18
}
18
19
19
20
async 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
+
20
53
Settings . initialize ( context ) ;
21
54
contextManager . initialize ( context ) ;
22
55
setMavenExtensionState ( ) ;
@@ -28,6 +61,13 @@ async function activateExtension(_operationId: string, context: ExtensionContext
28
61
contextManager . setContextValue ( Context . EXTENSION_ACTIVATED , true ) ;
29
62
30
63
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
+ } ) ) ;
31
71
}
32
72
33
73
// determine if the add dependency shortcut will show or not
@@ -47,3 +87,22 @@ function setMavenExtensionState() {
47
87
export async function deactivate ( ) {
48
88
await disposeTelemetryWrapper ( ) ;
49
89
}
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