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

Refactor status bars #485

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
59 changes: 59 additions & 0 deletions src/configReader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { workspace, WorkspaceConfiguration } from 'vscode';

export interface ColorsConfig {
disconnected: string,
launching: string,
connected: string,
typeStatus: string,
active: string,
inactive: string,
error: string
}

export class ConfigReader {
private changeEventDisposable;
constructor() {
this.changeEventDisposable = workspace.onDidChangeConfiguration(configChange => {
if(configChange.affectsConfiguration("calva.statusColor")){
this._colors = this.readColorConfig();
}
});
}

private _colors: ColorsConfig;

get colors() {
if(this._colors === undefined){
this._colors = this.readColorConfig();
}
return this._colors;
}

private readColorConfig(): ColorsConfig {
let colorConfig = workspace.getConfiguration('calva.statusColor');
return {
disconnected: this.colorValue("disconnectedColor", colorConfig),
launching: this.colorValue("launchingColor", colorConfig),
// TODO: Fix config typo
connected: this.colorValue("connectedSatusColor", colorConfig),
typeStatus: this.colorValue("typeStatusColor", colorConfig),
// TODO: Create config entries
active: "white",
inactive: "#b3b3b3",
error: "#FF2D00"
}
}

private colorValue(section: string, currentConf: WorkspaceConfiguration):string {
let { defaultValue, globalValue, workspaceFolderValue, workspaceValue} = currentConf.inspect(section);
return workspaceFolderValue || workspaceValue || globalValue || defaultValue;
}

dispose() {
this.changeEventDisposable.dispose();
}
}

// TODO: This should be somewhere else
const configReader = new ConfigReader();
export default configReader;
Comment on lines +57 to +59
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you are improving the config reading. This is just a note to us all to be alert to how this work can be continued. There are a few other config watchers, I think. And also we are reading up most config in the state module, where I do not think it really belongs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and maybe it would be a good idea to consume the config reader from state to keep aligned with the single source of truth. Config reader could emit change events to be picked up by state. Or if using redux, dispatch config change actions. Tomato/Tomato.

9 changes: 7 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import configReader from "./configReader";
import * as paredit from "./paredit/extension";
import * as fmt from "./calva-fmt/src/extension";
import * as highlight from "./highlight/src/extension";
Expand Down Expand Up @@ -54,6 +55,8 @@ function onDidOpen(document) {


function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(configReader);

state.cursor.set('analytics', new Analytics(context));
state.analytics().logPath("/start").logEvent("LifeCycle", "Started").send();

Expand Down Expand Up @@ -104,7 +107,9 @@ function activate(context: vscode.ExtensionContext) {

chan.appendLine("Calva activated.");

status.update();
const statusbars = statusbar.init();
context.subscriptions.push(...statusbars);
util.updateREPLSessionType();

// COMMANDS
context.subscriptions.push(vscode.commands.registerCommand('calva.jackInOrConnect', jackIn.calvaJackInOrConnect));
Expand Down Expand Up @@ -159,7 +164,7 @@ function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.languages.registerHoverProvider(state.documentSelector, new HoverProvider()));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(state.documentSelector, new DefinitionProvider()));
context.subscriptions.push(vscode.languages.registerSignatureHelpProvider(state.documentSelector, new CalvaSignatureHelpProvider(), ' ', ' '));


vscode.workspace.registerTextDocumentContentProvider('jar', new TextDocumentContentProvider());

Expand Down
12 changes: 6 additions & 6 deletions src/paredit/statusbar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
import { window, StatusBarAlignment, StatusBarItem } from 'vscode';
import statusbar from '../statusbar';
import configReader from "../configReader";
import * as paredit from './extension';

export class StatusBar {
Expand All @@ -22,15 +22,14 @@ export class StatusBar {

paredit.onPareditKeyMapChanged((keymap) => {
this.keyMap = keymap;
})
})
}

get keyMap() {
return this._keyMap;
}

set keyMap(keymap: String) {

switch (keymap.trim().toLowerCase()) {
case 'original':
this._keyMap = 'original';
Expand Down Expand Up @@ -62,10 +61,11 @@ export class StatusBar {
set enabled(value: Boolean) {
this._enabled = value;

// NOTE: Changes to color config are not picked up
if (this._enabled) {
this._toggleBarItem.color = statusbar.color.active;
this._toggleBarItem.color = configReader.colors.active;
} else {
this._toggleBarItem.color = statusbar.color.inactive;
this._toggleBarItem.color = configReader.colors.inactive;
}
}

Expand All @@ -84,4 +84,4 @@ export class StatusBar {
dispose() {
this._toggleBarItem.dispose();
}
}
}
1 change: 1 addition & 0 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function _trimAliasName(name: string): string {
return name.replace(/^[\s,:]*/, "").replace(/[\s,:]*$/, "")
}

// TODO: Refactor config reader to provide all config values
// TODO find a way to validate the configs
function config() {
let configOptions = vscode.workspace.getConfiguration('calva');
Expand Down
107 changes: 0 additions & 107 deletions src/statusbar.ts

This file was deleted.

44 changes: 44 additions & 0 deletions src/statusbar/cljs-build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { window, StatusBarAlignment, StatusBarItem } from "vscode";
import * as state from '../state';
import * as util from '../utilities';

export class CljsBuildStatusBarItem {
private statusBarItem: StatusBarItem;
constructor(alignment: StatusBarAlignment) {
this.statusBarItem = window.createStatusBarItem(alignment);
this.statusBarItem.command = "calva.switchCljsBuild";
}

update() {
const current = state.deref();
const cljsBuild = current.get('cljsBuild');
const connected = current.get("connected");
const sessionType = util.getREPLSessionType();

let text = null;
let tooltip = null;

if(connected && sessionType === 'cljs' && state.extensionContext.workspaceState.get('cljsReplTypeHasBuilds')) {
if (cljsBuild !== null) {
this.statusBarItem.text = cljsBuild;
this.statusBarItem.tooltip = "Click to switch CLJS build REPL";
} else {
this.statusBarItem.text = "no build connected"
this.statusBarItem.tooltip = "Click to connect to a CLJS build REPL";
}
}

this.statusBarItem.text = text;
this.statusBarItem.tooltip = tooltip;

if(this.statusBarItem.text) {
this.statusBarItem.show();
} else {
this.statusBarItem.hide();
}
}

dispose() {
this.statusBarItem.dispose();
}
}
49 changes: 49 additions & 0 deletions src/statusbar/connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { window, StatusBarAlignment, StatusBarItem } from "vscode";
import configReader from "../configReader";
import * as state from '../state';
import * as util from '../utilities';

export class ConnectionStatusBarItem {
private statusBarItem: StatusBarItem;

constructor(alignment: StatusBarAlignment) {
this.statusBarItem = window.createStatusBarItem(alignment);
}

update() {
let current = state.deref();
const colors = configReader.colors;

let text = "nREPL $(zap)";
let tooltip = "Click to jack-in or connect";
let command = "calva.jackInOrConnect";
let color = colors.disconnected;

if (current.get('connected')) {
text = "nREPL $(zap)";
color = colors.connected;
tooltip = `nrepl://${current.get('hostname')}:${current.get('port')} (Click to reset connection)`;
} else if (util.getLaunchingState()) {
color = colors.launching;
text = "Launching REPL using " + util.getLaunchingState();
tooltip = "Click to interrupt jack-in or Connect to REPL Server";
command = "calva.disconnect";
} else if (util.getConnectingState()) {
color = colors.launching;
text = "nREPL - trying to connect";
tooltip = "Click to interrupt jack-in or Connect to REPL Server";
command = "calva.disconnect";
}

this.statusBarItem.text = text;
this.statusBarItem.tooltip = tooltip;
this.statusBarItem.command = command;
this.statusBarItem.color = color;

this.statusBarItem.show();
}

dispose() {
this.statusBarItem.dispose();
}
}
Loading