11'use strict' ;
22
33import * 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" ;
55import { Commands } from "./commands" ;
66import { Disposable } from "vscode-languageclient" ;
77import * as path from "path" ;
88import { apiManager } from "./apiManager" ;
9- import * as semver from "semver" ;
109import { ACTIVE_BUILD_TOOL_STATE } from "./settings" ;
11- import { BuildFileStatusItemFactory , RuntimeStatusItemFactory , StatusCommands , supportsLanguageStatus } from "./languageStatusItemFactory" ;
10+ import { BuildFileStatusItemFactory , RuntimeStatusItemFactory } from "./languageStatusItemFactory" ;
1211import { getAllJavaProjects , getJavaConfiguration , hasBuildToolConflicts } from "./utils" ;
1312import { LombokVersionItemFactory , getLombokVersion , isLombokImported } from "./lombokSupport" ;
1413
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 ;
2018 private javaProjects : Map < string , IProjectInfo > ;
2119 private fileProjectMapping : Map < string , string > ;
2220 private storagePath : string | undefined ;
2321 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 ;
2722
2823 constructor ( ) {
2924 this . javaProjects = new Map < string , IProjectInfo > ( ) ;
3025 this . fileProjectMapping = new Map < string , string > ( ) ;
3126 this . disposables = [ ] ;
32- this . isAdvancedStatusBarItem = semver . gte ( version , "1.57.0" ) ;
3327 }
3428
3529 public async initialize ( context : ExtensionContext ) : Promise < void > {
@@ -39,15 +33,6 @@ class RuntimeStatusBarProvider implements Disposable {
3933 this . storagePath = Uri . file ( path . join ( storagePath , ".." , ".." ) ) . fsPath ;
4034 }
4135
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-
5136 let projectUriStrings : string [ ] ;
5237 try {
5338 projectUriStrings = await getAllJavaProjects ( false ) ;
@@ -59,10 +44,6 @@ class RuntimeStatusBarProvider implements Disposable {
5944 this . javaProjects . set ( Uri . parse ( uri ) . fsPath , undefined ) ;
6045 }
6146
62- if ( ! supportsLanguageStatus ( ) ) {
63- this . statusBarItem . command = StatusCommands . configureJavaRuntimeCommand ;
64- }
65-
6647 this . disposables . push ( window . onDidChangeActiveTextEditor ( ( textEditor ) => {
6748 this . updateItem ( context , textEditor ) ;
6849 } ) ) ;
@@ -111,7 +92,6 @@ class RuntimeStatusBarProvider implements Disposable {
11192 }
11293
11394 public dispose ( ) : void {
114- this . statusBarItem ?. dispose ( ) ;
11595 this . runtimeStatusItem ?. dispose ( ) ;
11696 this . buildFileStatusItem ?. dispose ( ) ;
11797 this . lombokVersionItem ?. dispose ( ) ;
@@ -176,63 +156,47 @@ class RuntimeStatusBarProvider implements Disposable {
176156 }
177157
178158 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" ) {
181160 return ;
182161 }
183162
184163 const uri : Uri = textEditor . document . uri ;
185164 const projectPath : string = this . findOwnerProject ( uri ) ;
186165 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 ( ) ;
194169 return ;
195170 }
196171
197172 const projectInfo : IProjectInfo = await this . getProjectInfo ( projectPath ) ;
198173 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 ( ) ;
206177 return ;
207178 }
208179
209180 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 ) ;
222191 }
192+ }
193+
194+ if ( isLombokImported ( ) ) {
223195 if ( ! this . lombokVersionItem ) {
224- if ( isLombokImported ( ) ) {
225- this . lombokVersionItem = LombokVersionItemFactory . create ( getLombokVersion ( ) ) ;
226- }
196+ this . lombokVersionItem = LombokVersionItemFactory . create ( getLombokVersion ( ) ) ;
227197 } else {
228- if ( isLombokImported ( ) ) {
229- LombokVersionItemFactory . update ( this . lombokVersionItem , getLombokVersion ( ) ) ;
230- }
198+ LombokVersionItemFactory . update ( this . lombokVersionItem , getLombokVersion ( ) ) ;
231199 }
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 ( ) ;
236200 }
237201 }
238202
@@ -302,4 +266,4 @@ interface IProjectInfo {
302266const SOURCE_LEVEL_KEY = "org.eclipse.jdt.core.compiler.source" ;
303267const VM_INSTALL_PATH = "org.eclipse.jdt.ls.core.vm.location" ;
304268
305- export const runtimeStatusBarProvider : RuntimeStatusBarProvider = new RuntimeStatusBarProvider ( ) ;
269+ export const languageStatusBarProvider : LanguageStatusBarProvider = new LanguageStatusBarProvider ( ) ;
0 commit comments