1
1
'use strict' ;
2
2
3
3
import * as fse from "fs-extra" ;
4
- import { StatusBarItem , window , StatusBarAlignment , TextEditor , Uri , commands , workspace , version , languages , Command , ExtensionContext } from "vscode" ;
4
+ import { window , TextEditor , Uri , commands , workspace , ExtensionContext , LanguageStatusItem } from "vscode" ;
5
5
import { Commands } from "./commands" ;
6
6
import { Disposable } from "vscode-languageclient" ;
7
7
import * as path from "path" ;
8
8
import { apiManager } from "./apiManager" ;
9
- import * as semver from "semver" ;
10
9
import { ACTIVE_BUILD_TOOL_STATE } from "./settings" ;
11
- import { BuildFileStatusItemFactory , RuntimeStatusItemFactory , StatusCommands , supportsLanguageStatus } from "./languageStatusItemFactory" ;
10
+ import { BuildFileStatusItemFactory , RuntimeStatusItemFactory } from "./languageStatusItemFactory" ;
12
11
import { getAllJavaProjects , getJavaConfiguration , hasBuildToolConflicts } from "./utils" ;
13
12
import { LombokVersionItemFactory , getLombokVersion , isLombokImported } from "./lombokSupport" ;
14
13
15
- class RuntimeStatusBarProvider implements Disposable {
16
- private statusBarItem : StatusBarItem ;
17
- private runtimeStatusItem : any ;
18
- private buildFileStatusItem : any ;
19
- private lombokVersionItem : any ;
14
+ class LanguageStatusBarProvider implements Disposable {
15
+ private runtimeStatusItem : LanguageStatusItem ;
16
+ private buildFileStatusItem : LanguageStatusItem ;
17
+ private lombokVersionItem : LanguageStatusItem ;
20
18
private javaProjects : Map < string , IProjectInfo > ;
21
19
private fileProjectMapping : Map < string , string > ;
22
20
private storagePath : string | undefined ;
23
21
private disposables : Disposable [ ] ;
24
- // Adopt new API for status bar item, meanwhile keep the compatibility with Theia.
25
- // See: https://github.com/redhat-developer/vscode-java/issues/1982
26
- private isAdvancedStatusBarItem : boolean ;
27
22
28
23
constructor ( ) {
29
24
this . javaProjects = new Map < string , IProjectInfo > ( ) ;
30
25
this . fileProjectMapping = new Map < string , string > ( ) ;
31
26
this . disposables = [ ] ;
32
- this . isAdvancedStatusBarItem = semver . gte ( version , "1.57.0" ) ;
33
27
}
34
28
35
29
public async initialize ( context : ExtensionContext ) : Promise < void > {
@@ -39,15 +33,6 @@ class RuntimeStatusBarProvider implements Disposable {
39
33
this . storagePath = Uri . file ( path . join ( storagePath , ".." , ".." ) ) . fsPath ;
40
34
}
41
35
42
- if ( ! supportsLanguageStatus ( ) ) {
43
- if ( this . isAdvancedStatusBarItem ) {
44
- this . statusBarItem = ( window . createStatusBarItem as any ) ( "java.runtimeStatus" , StatusBarAlignment . Right , 0 ) ;
45
- ( this . statusBarItem as any ) . name = "Java Runtime Configuration" ;
46
- } else {
47
- this . statusBarItem = window . createStatusBarItem ( StatusBarAlignment . Right , 0 ) ;
48
- }
49
- }
50
-
51
36
let projectUriStrings : string [ ] ;
52
37
try {
53
38
projectUriStrings = await getAllJavaProjects ( false ) ;
@@ -59,10 +44,6 @@ class RuntimeStatusBarProvider implements Disposable {
59
44
this . javaProjects . set ( Uri . parse ( uri ) . fsPath , undefined ) ;
60
45
}
61
46
62
- if ( ! supportsLanguageStatus ( ) ) {
63
- this . statusBarItem . command = StatusCommands . configureJavaRuntimeCommand ;
64
- }
65
-
66
47
this . disposables . push ( window . onDidChangeActiveTextEditor ( ( textEditor ) => {
67
48
this . updateItem ( context , textEditor ) ;
68
49
} ) ) ;
@@ -111,7 +92,6 @@ class RuntimeStatusBarProvider implements Disposable {
111
92
}
112
93
113
94
public dispose ( ) : void {
114
- this . statusBarItem ?. dispose ( ) ;
115
95
this . runtimeStatusItem ?. dispose ( ) ;
116
96
this . buildFileStatusItem ?. dispose ( ) ;
117
97
this . lombokVersionItem ?. dispose ( ) ;
@@ -176,63 +156,47 @@ class RuntimeStatusBarProvider implements Disposable {
176
156
}
177
157
178
158
private async updateItem ( context : ExtensionContext , textEditor : TextEditor ) : Promise < void > {
179
- if ( ! textEditor || path . extname ( textEditor . document . fileName ) !== ".java" && ! supportsLanguageStatus ( ) ) {
180
- this . statusBarItem ?. hide ( ) ;
159
+ if ( ! textEditor || path . extname ( textEditor . document . fileName ) !== ".java" ) {
181
160
return ;
182
161
}
183
162
184
163
const uri : Uri = textEditor . document . uri ;
185
164
const projectPath : string = this . findOwnerProject ( uri ) ;
186
165
if ( ! projectPath ) {
187
- if ( supportsLanguageStatus ( ) ) {
188
- this . hideRuntimeStatusItem ( ) ;
189
- this . hideBuildFileStatusItem ( ) ;
190
- this . hideLombokVersionItem ( ) ;
191
- } else {
192
- this . statusBarItem ?. hide ( ) ;
193
- }
166
+ this . hideRuntimeStatusItem ( ) ;
167
+ this . hideBuildFileStatusItem ( ) ;
168
+ this . hideLombokVersionItem ( ) ;
194
169
return ;
195
170
}
196
171
197
172
const projectInfo : IProjectInfo = await this . getProjectInfo ( projectPath ) ;
198
173
if ( ! projectInfo ) {
199
- if ( supportsLanguageStatus ( ) ) {
200
- this . hideRuntimeStatusItem ( ) ;
201
- this . hideBuildFileStatusItem ( ) ;
202
- this . hideLombokVersionItem ( ) ;
203
- } else {
204
- this . statusBarItem ?. hide ( ) ;
205
- }
174
+ this . hideRuntimeStatusItem ( ) ;
175
+ this . hideBuildFileStatusItem ( ) ;
176
+ this . hideLombokVersionItem ( ) ;
206
177
return ;
207
178
}
208
179
209
180
const text = this . getJavaRuntimeFromVersion ( projectInfo . sourceLevel ) ;
210
- if ( supportsLanguageStatus ( ) ) {
211
- const buildFilePath = await this . getBuildFilePath ( context , projectPath ) ;
212
- if ( ! this . runtimeStatusItem ) {
213
- this . runtimeStatusItem = RuntimeStatusItemFactory . create ( text , projectInfo . vmInstallPath ) ;
214
- if ( buildFilePath ) {
215
- this . buildFileStatusItem = BuildFileStatusItemFactory . create ( buildFilePath ) ;
216
- }
217
- } else {
218
- RuntimeStatusItemFactory . update ( this . runtimeStatusItem , text , projectInfo . vmInstallPath ) ;
219
- if ( buildFilePath ) {
220
- BuildFileStatusItemFactory . update ( this . buildFileStatusItem , buildFilePath ) ;
221
- }
181
+ const buildFilePath = await this . getBuildFilePath ( context , projectPath ) ;
182
+ if ( ! this . runtimeStatusItem ) {
183
+ this . runtimeStatusItem = RuntimeStatusItemFactory . create ( text , projectInfo . vmInstallPath ) ;
184
+ if ( buildFilePath ) {
185
+ this . buildFileStatusItem = BuildFileStatusItemFactory . create ( buildFilePath ) ;
186
+ }
187
+ } else {
188
+ RuntimeStatusItemFactory . update ( this . runtimeStatusItem , text , projectInfo . vmInstallPath ) ;
189
+ if ( buildFilePath ) {
190
+ BuildFileStatusItemFactory . update ( this . buildFileStatusItem , buildFilePath ) ;
222
191
}
192
+ }
193
+
194
+ if ( isLombokImported ( ) ) {
223
195
if ( ! this . lombokVersionItem ) {
224
- if ( isLombokImported ( ) ) {
225
- this . lombokVersionItem = LombokVersionItemFactory . create ( getLombokVersion ( ) ) ;
226
- }
196
+ this . lombokVersionItem = LombokVersionItemFactory . create ( getLombokVersion ( ) ) ;
227
197
} else {
228
- if ( isLombokImported ( ) ) {
229
- LombokVersionItemFactory . update ( this . lombokVersionItem , getLombokVersion ( ) ) ;
230
- }
198
+ LombokVersionItemFactory . update ( this . lombokVersionItem , getLombokVersion ( ) ) ;
231
199
}
232
- } else {
233
- this . statusBarItem . text = text ;
234
- this . statusBarItem . tooltip = projectInfo . vmInstallPath ? `Language Level: ${ this . statusBarItem . text } <${ projectInfo . vmInstallPath } >` : "Configure Java Runtime" ;
235
- this . statusBarItem . show ( ) ;
236
200
}
237
201
}
238
202
@@ -302,4 +266,4 @@ interface IProjectInfo {
302
266
const SOURCE_LEVEL_KEY = "org.eclipse.jdt.core.compiler.source" ;
303
267
const VM_INSTALL_PATH = "org.eclipse.jdt.ls.core.vm.location" ;
304
268
305
- export const runtimeStatusBarProvider : RuntimeStatusBarProvider = new RuntimeStatusBarProvider ( ) ;
269
+ export const languageStatusBarProvider : LanguageStatusBarProvider = new LanguageStatusBarProvider ( ) ;
0 commit comments