Skip to content

Commit

Permalink
add extension status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
shadycuz committed Aug 26, 2021
1 parent 441ae45 commit fa64aeb
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ extension fits your needs and enhances your development experience.
and the [VS Code Groovy extension].
* [Managing extensions in VS Code].
* **Step 2.** To activate the extension, open any directory or workspace
containing Groovy code.
containing Groovy code and look for the thumbs up! 👍
<img src="docs/images/status-bar.png">

You are ready to get Groovy :-) &nbsp;&nbsp; 🎉🎉🎉

## Features

The extension is currently a work-in-progress but does provide basic IntelliSense. We plan to extend this extension to include code navigation and code editing.

- Code completion and Signature help
- Code completion and Signature help
<img src="docs/images/completion-signature-help.gif">
- See GroovyDoc strings on Classes, Fields, Methods and Functions.
- See GroovyDoc strings on Classes, Fields, Methods and Functions.
<img src="docs/images/docstring-help.gif">

## Build from source
Expand Down
Binary file added docs/images/status-bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import findJava from "./utils/findJava";
import * as path from "path";
import * as vscode from "vscode";
import { extensionStatusBar } from "./gui/extensionStatusBarProvider";
import {
LanguageClient,
LanguageClientOptions,
Expand Down Expand Up @@ -49,6 +50,9 @@ function onDidChangeConfiguration(event: vscode.ConfigurationChangeEvent) {
}

function restartLanguageServer() {

extensionStatusBar.restart();

if (!languageClient) {
startLanguageServer();
return;
Expand All @@ -75,7 +79,13 @@ function restartLanguageServer() {

export function activate(context: vscode.ExtensionContext) {
extensionContext = context;

// Enable the status bar and tell it to display.
context.subscriptions.push(extensionStatusBar);
extensionStatusBar.startUp();

javaPath = findJava();

vscode.workspace.onDidChangeConfiguration(onDidChangeConfiguration);

vscode.commands.registerCommand(
Expand All @@ -98,10 +108,12 @@ function startLanguageServer() {
if (!extensionContext) {
//something very bad happened!
resolve();
extensionStatusBar.setError();
vscode.window.showErrorMessage(STARTUP_ERROR);
return;
}
if (!javaPath) {
extensionStatusBar.setError();
resolve();
let settingsJavaHome = vscode.workspace
.getConfiguration("groovy")
Expand Down Expand Up @@ -155,10 +167,12 @@ function startLanguageServer() {
);
languageClient.onReady().then(resolve, (reason: any) => {
resolve();
extensionStatusBar.setError();
vscode.window.showErrorMessage(STARTUP_ERROR);
});
let disposable = languageClient.start();
extensionContext.subscriptions.push(disposable);
extensionStatusBar.running();
});
}
);
Expand Down
79 changes: 79 additions & 0 deletions src/gui/extensionStatusBarProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2021 DontShaveTheYak
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
//
// Author: DontShaveTheYak
// No warranty of merchantability or fitness of any kind.
// Use this software at your own risk.
////////////////////////////////////////////////////////////////////////////////

import { StatusBarItem, window, StatusBarAlignment } from "vscode";
import { Disposable } from "vscode-languageclient";

class ExtensionStatusBarProvider implements Disposable {
private statusBarItem: StatusBarItem;

constructor() {
this.statusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, Number.MIN_VALUE);
}

public startUp(): void {
this.statusBarItem.text = StatusIcon.Launching;
this.statusBarItem.tooltip = 'Groovy-Guru is Starting.';
this.statusBarItem.show();
}

public restart(): void {
this.statusBarItem.text = StatusIcon.Busy;
this.statusBarItem.tooltip = 'Groovy-Guru is Restarting.';
}

public running(): void {
this.statusBarItem.text = StatusIcon.Ready;
this.statusBarItem.tooltip = 'Groovy-Guru is running.';
}

public updateText(text: string): void {
this.statusBarItem.text = text;
}

public setBusy(): void {
this.statusBarItem.text = StatusIcon.Busy;
}

public setError(): void {
this.statusBarItem.text = StatusIcon.Error;
}

public setReady(): void {
this.statusBarItem.text = StatusIcon.Ready;
}

public updateTooltip(tooltip: string): void {
this.statusBarItem.tooltip = tooltip;
}

public dispose(): void {
this.statusBarItem.dispose();
}
}

enum StatusIcon {
Busy = "$(sync~spin)",
Ready = "$(thumbsup)",
Error = "$(thumbsdown)",
Launching = "$(rocket)",
}

export const extensionStatusBar: ExtensionStatusBarProvider = new ExtensionStatusBarProvider();

0 comments on commit fa64aeb

Please sign in to comment.