This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vscode): add a status bar item for the language server (#3139)
* feat(vscode): add a status bar item for the language server * address PR review
- Loading branch information
Showing
3 changed files
with
176 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
// list of commands available in the VS Code extension | ||
export enum Commands { SyntaxTree = "rome.syntaxTree" } | ||
export enum Commands { | ||
SyntaxTree = "rome.syntaxTree", | ||
ServerStatus = "rome.serverStatus", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { StatusBarAlignment, StatusBarItem, ThemeColor, window } from "vscode"; | ||
import { State } from "vscode-languageclient"; | ||
import { Commands } from "./commands"; | ||
|
||
/** | ||
* Enumeration of all the status the extension can display | ||
* | ||
* The string value of the enum is the ThemeIcon ID to be displayer in the status | ||
* bar item when this status is active | ||
* | ||
* See https://code.visualstudio.com/api/references/icons-in-labels#icon-listing | ||
* for a list of available icons | ||
*/ | ||
enum Status { | ||
Pending = "refresh", | ||
Ready = "check", | ||
Inactive = "eye-closed", | ||
Warning = "warning", | ||
Error = "error", | ||
} | ||
|
||
export class StatusBar { | ||
private statusBarItem: StatusBarItem; | ||
|
||
private serverState: State = State.Starting; | ||
private isActive: boolean = false; | ||
|
||
constructor() { | ||
this.statusBarItem = window.createStatusBarItem( | ||
"rome.status", | ||
StatusBarAlignment.Right, | ||
-1, | ||
); | ||
|
||
this.statusBarItem.name = "Rome"; | ||
this.statusBarItem.command = Commands.ServerStatus; | ||
this.update(); | ||
} | ||
|
||
public setServerState(state: State) { | ||
this.serverState = state; | ||
this.update(); | ||
} | ||
|
||
public setActive(isActive: boolean) { | ||
this.isActive = isActive; | ||
this.update(); | ||
} | ||
|
||
private update() { | ||
let status: Status; | ||
if (this.serverState === State.Running) { | ||
if (this.isActive) { | ||
status = Status.Ready; | ||
} else { | ||
status = Status.Inactive; | ||
} | ||
} else if (this.serverState === State.Starting) { | ||
status = Status.Pending; | ||
} else { | ||
status = Status.Error; | ||
} | ||
|
||
this.statusBarItem.text = `$(${status}) Rome`; | ||
|
||
switch (status) { | ||
case Status.Pending: { | ||
this.statusBarItem.tooltip = "Rome is initializing ..."; | ||
break; | ||
} | ||
case Status.Ready: { | ||
this.statusBarItem.tooltip = "Rome is active"; | ||
break; | ||
} | ||
case Status.Inactive: { | ||
this.statusBarItem.tooltip = | ||
"The current file is not supported or ignored by Rome"; | ||
break; | ||
} | ||
// @ts-expect-error Reserved for future use | ||
case Status.Warning: { | ||
this.statusBarItem.tooltip = undefined; | ||
break; | ||
} | ||
case Status.Error: { | ||
this.statusBarItem.tooltip = "Rome encountered a fatal error"; | ||
break; | ||
} | ||
} | ||
|
||
switch (status) { | ||
case Status.Error: { | ||
this.statusBarItem.color = new ThemeColor( | ||
"statusBarItem.errorForeground", | ||
); | ||
this.statusBarItem.backgroundColor = new ThemeColor( | ||
"statusBarItem.errorBackground", | ||
); | ||
break; | ||
} | ||
// @ts-expect-error Reserved for future use | ||
case Status.Warning: { | ||
this.statusBarItem.color = new ThemeColor( | ||
"statusBarItem.warningForeground", | ||
); | ||
this.statusBarItem.backgroundColor = new ThemeColor( | ||
"statusBarItem.warningBackground", | ||
); | ||
break; | ||
} | ||
default: { | ||
this.statusBarItem.color = undefined; | ||
this.statusBarItem.backgroundColor = undefined; | ||
break; | ||
} | ||
} | ||
|
||
this.statusBarItem.show(); | ||
} | ||
|
||
public hide() { | ||
this.statusBarItem.hide(); | ||
} | ||
} |