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 2 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.

3 changes: 3 additions & 0 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
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
37 changes: 12 additions & 25 deletions src/statusbar.ts → src/statusbar/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
import * as vscode from 'vscode';
import { activeReplWindow } from './repl-window';
import * as state from './state';
import * as util from './utilities';
import { activeReplWindow } from '../repl-window';
import configReader from "../configReader";
import * as state from '../state';
import * as util from '../utilities';

const connectionStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
const typeStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
const cljsBuildStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
const prettyPrintToggle = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
const color = {
active: "white",
inactive: "#b3b3b3"
};

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

return workspaceFolderValue || workspaceValue || globalValue || defaultValue;
}

function update() {

let currentConf = vscode.workspace.getConfiguration('calva.statusColor');
const color = configReader.colors;

let current = state.deref(),
doc = util.getDocument({}),
fileType = util.getFileType(doc),
cljsBuild = current.get('cljsBuild');

//let disconnectedColor = "rgb(192,192,192)";

const pprint = state.config().prettyPrintingOptions.enabled;
prettyPrintToggle.text = "pprint";
prettyPrintToggle.color = pprint ? color.active : color.inactive;
Expand All @@ -38,7 +26,7 @@ function update() {
typeStatus.command = null;
typeStatus.text = "Disconnected";
typeStatus.tooltip = "No active REPL session";
typeStatus.color = colorValue("disconnectedColor", currentConf);
typeStatus.color = color.disconnected;

connectionStatus.command = null;
connectionStatus.tooltip = "REPL connection status";
Expand All @@ -49,10 +37,10 @@ function update() {

if (current.get('connected')) {
connectionStatus.text = "nREPL $(zap)";
connectionStatus.color = colorValue("connectedSatusColor", currentConf);
connectionStatus.color = color.connected;
connectionStatus.tooltip = `nrepl://${current.get('hostname')}:${current.get('port')} (Click to reset connection)`;
connectionStatus.command = "calva.jackInOrConnect";
typeStatus.color = colorValue("typeStatusColor", currentConf);
typeStatus.color = color.typeStatus;
if (fileType == 'cljc' && util.getREPLSessionType() !== null && !activeReplWindow()) {
typeStatus.text = "cljc/" + util.getREPLSessionType()
if (util.getSession('clj') !== null && util.getSession('cljs') !== null) {
Expand All @@ -76,7 +64,7 @@ function update() {
}
}
} else if (util.getLaunchingState()) {
connectionStatus.color = colorValue("launchingColor", currentConf);
connectionStatus.color = color.launching;
connectionStatus.text = "Launching REPL using " + util.getLaunchingState();
connectionStatus.tooltip = "Click to interrupt jack-in or Connect to REPL Server";
connectionStatus.command = "calva.disconnect";
Expand All @@ -87,7 +75,7 @@ function update() {
} else {
connectionStatus.text = "nREPL $(zap)";
connectionStatus.tooltip = "Click to jack-in or Connect to REPL Server";
connectionStatus.color = colorValue("disconnectedColor", currentConf);
connectionStatus.color = color.disconnected;
connectionStatus.command = "calva.jackInOrConnect";
}

Expand All @@ -102,6 +90,5 @@ function update() {
}

export default {
update,
color
};
update
}