Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt new createStatusBarItem API #2083

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 59 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@
"@types/lodash.findindex": "^4.6.6",
"@types/mocha": "^5.2.5",
"@types/node": "^8.10.51",
"@types/semver": "^7.3.8",
"@types/vscode": "^1.53.0",
"@types/winreg": "^1.2.30",
"@types/winston": "^2.4.4",
Expand All @@ -1125,6 +1126,7 @@
"fs-extra": "^8.1.0",
"glob": "^7.1.3",
"vscode-languageclient": "7.1.0-next.5",
"semver": "^7.3.5",
"winreg-utf8": "^0.1.1",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^3.10.0"
Expand Down
15 changes: 13 additions & 2 deletions src/runtimeStatusBarProvider.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
'use strict';

import { StatusBarItem, window, StatusBarAlignment, TextEditor, Uri, commands, Event, workspace } from "vscode";
import { StatusBarItem, window, StatusBarAlignment, TextEditor, Uri, commands, workspace, version } from "vscode";
import { Commands } from "./commands";
import { Disposable } from "vscode-languageclient";
import * as path from "path";
import { apiManager } from "./apiManager";
import * as semver from "semver";

class RuntimeStatusBarProvider implements Disposable {
private statusBarItem: StatusBarItem;
private javaProjects: Map<string, IProjectInfo>;
private fileProjectMapping: Map<string, string>;
private storagePath: string | undefined;
private disposables: Disposable[];
// Adopt new API for status bar item, meanwhile keep the compatibility with Theia.
// See: https://github.com/redhat-developer/vscode-java/issues/1982
private isAdvancedStatusBarItem: boolean;

constructor() {
this.javaProjects = new Map<string, IProjectInfo>();
this.fileProjectMapping = new Map<string, string>();
this.disposables = [];
this.isAdvancedStatusBarItem = semver.gte(version, "1.57.0");
}

public async initialize(storagePath?: string): Promise<void> {
Expand All @@ -25,7 +30,13 @@ class RuntimeStatusBarProvider implements Disposable {
this.storagePath = Uri.file(path.join(storagePath, "..", "..")).fsPath;
}

this.statusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, 0);
if (this.isAdvancedStatusBarItem) {
this.statusBarItem = (window.createStatusBarItem as any)("java.runtimeStatus", StatusBarAlignment.Right, 0);
(this.statusBarItem as any).name = "Java Runtime Configuration";
} else {
this.statusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, 0);
}

let projectUriStrings: string[];
try {
projectUriStrings = await commands.executeCommand<string[]>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.GET_ALL_JAVA_PROJECTS);
Expand Down
19 changes: 17 additions & 2 deletions src/serverStatusBarProvider.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
'use strict';

import { StatusBarItem, window, StatusBarAlignment } from "vscode";
import { StatusBarItem, window, StatusBarAlignment, version } from "vscode";
import { Commands } from "./commands";
import { Disposable } from "vscode-languageclient";
import { ServerMode } from "./settings";
import * as semver from "semver";

class ServerStatusBarProvider implements Disposable {
private statusBarItem: StatusBarItem;
// Adopt new API for status bar item, meanwhile keep the compatibility with Theia.
// See: https://github.com/redhat-developer/vscode-java/issues/1982
private isAdvancedStatusBarItem: boolean;

constructor() {
this.statusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, Number.MIN_VALUE);
this.isAdvancedStatusBarItem = semver.gte(version, "1.57.0");
if (this.isAdvancedStatusBarItem) {
this.statusBarItem = (window.createStatusBarItem as any)("java.serverStatus", StatusBarAlignment.Right, Number.MIN_VALUE);
} else {
this.statusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, Number.MIN_VALUE);
}
}

public showLightWeightStatus(): void {
if (this.isAdvancedStatusBarItem) {
(this.statusBarItem as any).name = "Java Server Mode";
}
this.statusBarItem.text = StatusIcon.LightWeight;
this.statusBarItem.command = {
title: "Switch to Standard mode",
Expand All @@ -24,6 +36,9 @@ class ServerStatusBarProvider implements Disposable {
}

public showStandardStatus(): void {
if (this.isAdvancedStatusBarItem) {
(this.statusBarItem as any).name = "Java Server Status";
}
this.statusBarItem.text = StatusIcon.Busy;
this.statusBarItem.command = Commands.SHOW_SERVER_TASK_STATUS;
this.statusBarItem.tooltip = "";
Expand Down