-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added server status information to the status bar. (#61)
* Added server status information to the status bar. * Improve and modularize status display --------- Co-authored-by: Jens Haase <[email protected]>
- Loading branch information
Showing
4 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
Submodule LanguageServer.quark
updated
18 files
+8 −4 | LSP.sc | |
+45 −15 | LSPDatabase.sc | |
+10 −0 | LSPFeature.sc | |
+53 −0 | Notifications/ServerStatusNotification.sc | |
+32 −32 | Providers/CodeLensProvider.sc | |
+204 −25 | Providers/EvaluateProvider.sc | |
+9 −2 | Providers/FindReferencesProvider.sc | |
+8 −3 | Providers/GotoDeclarationProvider.sc | |
+13 −3 | Providers/GotoImplementationProvider.sc | |
+60 −4 | Providers/InitializeProvider.sc | |
+20 −6 | Providers/ShutdownProvider.sc | |
+1 −1 | Providers/SignatureHelpProvider.sc | |
+2 −0 | Requests/WorkspaceConfigurationRequest.sc | |
+73 −0 | SystemOverwrites/extMain.sc | |
+22 −0 | SystemOverwrites/extServer.sc | |
+28 −9 | extString.sc | |
+2 −3 | scide_vscode/Document.sc | |
+4 −33 | scide_vscode/LSPDocument.sc |
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,121 @@ | ||
import * as vscode from "vscode"; | ||
|
||
export type ServerStatusBarData = { | ||
name?: string; | ||
running: boolean; | ||
unresponsive: boolean; | ||
avgCPU: number; | ||
peakCPU: number; | ||
numUGens: number; | ||
numSynths: number; | ||
numGroups: number; | ||
numSynthDefs: number; | ||
}; | ||
|
||
export class ServerStatusBar { | ||
private statusBarItem: vscode.StatusBarItem; | ||
|
||
constructor() { | ||
this.statusBarItem = vscode.window.createStatusBarItem( | ||
vscode.StatusBarAlignment.Right, | ||
100 | ||
); | ||
this.statusBarItem.name = "SuperCollider server status"; | ||
this.statusBarItem.color = new vscode.ThemeColor("disabledForeground"); | ||
this.statusBarItem.show(); | ||
} | ||
|
||
getStatusBarItem() { | ||
return this.statusBarItem; | ||
} | ||
|
||
formatString(string: string, name, icon, avgCPUFormatted, peakCPUFormatted, numUGens, numSynths, numGroups, numSynthDefs): string { | ||
string = string.replace("${name}", name) | ||
string = string.replace("${icon}", icon) | ||
string = string.replace("${avgCPU}", avgCPUFormatted); | ||
string = string.replace("${peakCPU}", peakCPUFormatted); | ||
string = string.replace("${numUGens}", numUGens.toString()); | ||
string = string.replace("${numSynths}", numSynths.toString()); | ||
string = string.replace("${numGroups}", numGroups.toString()); | ||
string = string.replace("${numSynthDefs}", numSynthDefs.toString()); | ||
|
||
return string | ||
} | ||
|
||
updateStatusBar(data: ServerStatusBarData) { | ||
let { | ||
name, | ||
running, | ||
unresponsive, | ||
avgCPU, | ||
peakCPU, | ||
numUGens, | ||
numSynths, | ||
numGroups, | ||
numSynthDefs, | ||
} = data; | ||
|
||
if (!running) { | ||
unresponsive = false; | ||
avgCPU = 0; | ||
peakCPU = 0; | ||
numUGens = 0; | ||
numSynths = 0; | ||
numGroups = 0; | ||
numSynthDefs = 0; | ||
} | ||
const percentFormatter = Intl.NumberFormat(undefined, { | ||
maximumFractionDigits: 2, | ||
minimumFractionDigits: 2 | ||
}); | ||
|
||
const icon = unresponsive | ||
? `$(warning)` | ||
: running | ||
? `$(play)` | ||
: `$(primitive-square)`; | ||
|
||
this.statusBarItem.color = unresponsive | ||
? new vscode.ThemeColor("activityWarningBadge.foreground") | ||
: running | ||
? new vscode.ThemeColor("terminal.ansiGreen") | ||
: new vscode.ThemeColor("disabledForeground"); | ||
|
||
this.statusBarItem.command = unresponsive | ||
? "supercollider.internal.rebootServer" | ||
: running | ||
? null | ||
: "supercollider.internal.bootServer"; | ||
|
||
this.statusBarItem.tooltip = unresponsive | ||
? "Server is unresponsive. Click to restart." | ||
: running | ||
? "Server is running." | ||
: "Server is not running. Click to start."; | ||
|
||
const avgCPUFormatted = percentFormatter.format(avgCPU); | ||
const peakCPUFormatted = percentFormatter.format(peakCPU); | ||
|
||
const configuration = vscode.workspace.getConfiguration() | ||
|
||
const statusString = this.formatString( | ||
configuration.get<string>('supercollider.serverStatusString'), | ||
name, icon, avgCPUFormatted, peakCPUFormatted, numUGens, numSynths, numGroups, numSynthDefs); | ||
|
||
const tooltipString = this.formatString( | ||
"**Status**: " + (running ? "`running`" : "`stopped`") + " \n" + | ||
"---\n" + | ||
"**Average CPU**: `${avgCPU}%` \n" + | ||
"**Peak CPU**: `${peakCPU}%` \n" + | ||
"---\n" + | ||
"**Synths**: `${numSynths}` \n" + | ||
"**Groups**: `${numGroups}` \n" + | ||
"**UGens**: `${numUGens}` \n" + | ||
"---\n" + | ||
"**SynthDefs**: `${numSynthDefs}` \n", | ||
name, icon, avgCPUFormatted, peakCPUFormatted, numUGens, numSynths, numGroups, numSynthDefs); | ||
|
||
this.statusBarItem.text = statusString; | ||
this.statusBarItem.tooltip = new vscode.MarkdownString(tooltipString); | ||
} | ||
} |
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