From 070f2220a5b6f8e66b17821b22fc097756adefc3 Mon Sep 17 00:00:00 2001 From: stefan toubia Date: Sat, 23 Nov 2019 16:31:37 -0800 Subject: [PATCH 1/5] Move statusbar file --- src/{statusbar.ts => statusbar/index.ts} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename src/{statusbar.ts => statusbar/index.ts} (97%) diff --git a/src/statusbar.ts b/src/statusbar/index.ts similarity index 97% rename from src/statusbar.ts rename to src/statusbar/index.ts index be46f2b83..d4787151c 100644 --- a/src/statusbar.ts +++ b/src/statusbar/index.ts @@ -1,7 +1,7 @@ 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 * 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); From d5108fed804e4580ec3c562633ac181aa6f43c5e Mon Sep 17 00:00:00 2001 From: stefan toubia Date: Sat, 23 Nov 2019 18:55:57 -0800 Subject: [PATCH 2/5] Refactor color config --- src/configReader.ts | 59 ++++++++++++++++++++++++++++++++++++++++ src/extension.ts | 3 ++ src/paredit/statusbar.ts | 12 ++++---- src/state.ts | 1 + src/statusbar/index.ts | 31 ++++++--------------- 5 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 src/configReader.ts diff --git a/src/configReader.ts b/src/configReader.ts new file mode 100644 index 000000000..ec731e919 --- /dev/null +++ b/src/configReader.ts @@ -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; diff --git a/src/extension.ts b/src/extension.ts index 68316677c..bbf36e3b9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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"; @@ -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(); diff --git a/src/paredit/statusbar.ts b/src/paredit/statusbar.ts index 747b42669..b4f99c9b8 100644 --- a/src/paredit/statusbar.ts +++ b/src/paredit/statusbar.ts @@ -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 { @@ -22,7 +22,7 @@ export class StatusBar { paredit.onPareditKeyMapChanged((keymap) => { this.keyMap = keymap; - }) + }) } get keyMap() { @@ -30,7 +30,6 @@ export class StatusBar { } set keyMap(keymap: String) { - switch (keymap.trim().toLowerCase()) { case 'original': this._keyMap = 'original'; @@ -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; } } @@ -84,4 +84,4 @@ export class StatusBar { dispose() { this._toggleBarItem.dispose(); } -} \ No newline at end of file +} diff --git a/src/state.ts b/src/state.ts index 8d03b73aa..b39422674 100644 --- a/src/state.ts +++ b/src/state.ts @@ -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'); diff --git a/src/statusbar/index.ts b/src/statusbar/index.ts index d4787151c..7e056f9c5 100644 --- a/src/statusbar/index.ts +++ b/src/statusbar/index.ts @@ -1,5 +1,6 @@ import * as vscode from 'vscode'; import { activeReplWindow } from '../repl-window'; +import configReader from "../configReader"; import * as state from '../state'; import * as util from '../utilities'; @@ -7,28 +8,15 @@ const connectionStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlign 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; @@ -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"; @@ -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) { @@ -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"; @@ -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"; } @@ -102,6 +90,5 @@ function update() { } export default { - update, - color -}; + update +} From b0a0d06fe2d98fee3467556ec574d0b97a7816a0 Mon Sep 17 00:00:00 2001 From: stefan toubia Date: Sat, 23 Nov 2019 19:06:18 -0800 Subject: [PATCH 3/5] Split status bars to individual files --- src/statusbar/cljsBuildStatusBar.ts | 48 ++++++++++++++ src/statusbar/connectionStatusBar.ts | 51 ++++++++++++++ src/statusbar/index.ts | 96 ++++----------------------- src/statusbar/prettyPrintStatusBar.ts | 31 +++++++++ src/statusbar/typeStatusBar.ts | 50 ++++++++++++++ 5 files changed, 194 insertions(+), 82 deletions(-) create mode 100644 src/statusbar/cljsBuildStatusBar.ts create mode 100644 src/statusbar/connectionStatusBar.ts create mode 100644 src/statusbar/prettyPrintStatusBar.ts create mode 100644 src/statusbar/typeStatusBar.ts diff --git a/src/statusbar/cljsBuildStatusBar.ts b/src/statusbar/cljsBuildStatusBar.ts new file mode 100644 index 000000000..f4f6db92a --- /dev/null +++ b/src/statusbar/cljsBuildStatusBar.ts @@ -0,0 +1,48 @@ +import { window, StatusBarAlignment, StatusBarItem } from "vscode"; +import * as state from '../state'; +import * as util from '../utilities'; + +export class CljsBuildStatusBar { + private statusBarItem: StatusBarItem; + constructor() { + this.statusBarItem = this.createStatusBarItem(); + this.update(); + } + + private createStatusBarItem() { + let sbi = window.createStatusBarItem(StatusBarAlignment.Left); + sbi.command = "calva.switchCljsBuild"; + sbi.text = null; + sbi.tooltip = null; + return sbi; + } + + show = () => this.statusBarItem.show(); + + update() { + let current = state.deref(), + cljsBuild = current.get('cljsBuild'); + + if(current.get("connected")) { + if (util.getREPLSessionType() === 'cljs' && state.extensionContext.workspaceState.get('cljsReplTypeHasBuilds')) { + if (cljsBuild !== null && util.getREPLSessionType() === 'cljs') { + this.statusBarItem.text = cljsBuild; + this.statusBarItem.tooltip = "Click to switch CLJS build REPL"; + } else if (cljsBuild === null) { + this.statusBarItem.text = "no build connected" + this.statusBarItem.tooltip = "Click to connect to a CLJS build REPL"; + } + } + } + + if(this.statusBarItem.text) { + this.statusBarItem.show(); + } else { + this.statusBarItem.hide(); + } + } + + dispose() { + this.statusBarItem.dispose(); + } +} diff --git a/src/statusbar/connectionStatusBar.ts b/src/statusbar/connectionStatusBar.ts new file mode 100644 index 000000000..cdfec81bb --- /dev/null +++ b/src/statusbar/connectionStatusBar.ts @@ -0,0 +1,51 @@ +import { window, StatusBarAlignment, StatusBarItem } from "vscode"; +import { activeReplWindow } from '../repl-window'; +import configReader from "../configReader"; +import * as state from '../state'; +import * as util from '../utilities'; + +export class ConnectionStatusBar { + private statusBarItem: StatusBarItem; + constructor() { + this.statusBarItem = this.createStatusBarItem(); + } + + private createStatusBarItem() { + let sbi = window.createStatusBarItem(StatusBarAlignment.Left); + sbi.command = null; + sbi.tooltip = "REPL connection status"; + return sbi; + } + + show = () => this.statusBarItem.show(); + + update() { + let current = state.deref(); + const color = configReader.colors; + + if (current.get('connected')) { + this.statusBarItem.text = "nREPL $(zap)"; + this.statusBarItem.color = color.connected; + this.statusBarItem.tooltip = `nrepl://${current.get('hostname')}:${current.get('port')} (Click to reset connection)`; + this.statusBarItem.command = "calva.jackInOrConnect"; + } else if (util.getLaunchingState()) { + this.statusBarItem.color = color.launching; + this.statusBarItem.text = "Launching REPL using " + util.getLaunchingState(); + this.statusBarItem.tooltip = "Click to interrupt jack-in or Connect to REPL Server"; + this.statusBarItem.command = "calva.disconnect"; + } else if (util.getConnectingState()) { + this.statusBarItem.text = "nREPL - trying to connect"; + this.statusBarItem.tooltip = "Click to interrupt jack-in or Connect to REPL Server"; + this.statusBarItem.command = "calva.disconnect"; + } else { + this.statusBarItem.text = "nREPL $(zap)"; + this.statusBarItem.tooltip = "Click to jack-in or Connect to REPL Server"; + this.statusBarItem.color = color.disconnected; + this.statusBarItem.command = "calva.jackInOrConnect"; + } + } + + dispose() { + this.statusBarItem.dispose(); + } +} diff --git a/src/statusbar/index.ts b/src/statusbar/index.ts index 7e056f9c5..a875f8616 100644 --- a/src/statusbar/index.ts +++ b/src/statusbar/index.ts @@ -1,91 +1,23 @@ -import * as vscode from 'vscode'; -import { activeReplWindow } from '../repl-window'; -import configReader from "../configReader"; -import * as state from '../state'; -import * as util from '../utilities'; +import { TypeStatusBar } from "./typeStatusBar"; +import { PrettyPrintStatusBar } from "./prettyPrintStatusBar"; +import { CljsBuildStatusBar } from "./cljsBuildStatusBar"; +import { ConnectionStatusBar } from "./connectionStatusBar"; -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 connectionStatus = new ConnectionStatusBar(); +const typeStatus = new TypeStatusBar(); +const cljsBuildStatus = new CljsBuildStatusBar(); +const prettyPrintToggle = new PrettyPrintStatusBar(); function update() { - const color = configReader.colors; - - let current = state.deref(), - doc = util.getDocument({}), - fileType = util.getFileType(doc), - cljsBuild = current.get('cljsBuild'); - - const pprint = state.config().prettyPrintingOptions.enabled; - prettyPrintToggle.text = "pprint"; - prettyPrintToggle.color = pprint ? color.active : color.inactive; - prettyPrintToggle.tooltip = `Turn pretty printing ${pprint ? 'off' : 'on'}` - prettyPrintToggle.command = "calva.togglePrettyPrint" - - typeStatus.command = null; - typeStatus.text = "Disconnected"; - typeStatus.tooltip = "No active REPL session"; - typeStatus.color = color.disconnected; - - connectionStatus.command = null; - connectionStatus.tooltip = "REPL connection status"; + connectionStatus.update(); + connectionStatus.show(); - cljsBuildStatus.text = null; - cljsBuildStatus.command = "calva.switchCljsBuild"; - cljsBuildStatus.tooltip = null; + typeStatus.update(); + typeStatus.show(); - if (current.get('connected')) { - connectionStatus.text = "nREPL $(zap)"; - connectionStatus.color = color.connected; - connectionStatus.tooltip = `nrepl://${current.get('hostname')}:${current.get('port')} (Click to reset connection)`; - connectionStatus.command = "calva.jackInOrConnect"; - 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) { - typeStatus.command = "calva.toggleCLJCSession"; - typeStatus.tooltip = `Click to use ${(util.getREPLSessionType() === 'clj' ? 'cljs' : 'clj')} REPL for cljc`; - } - } else if (util.getREPLSessionType() === 'cljs') { - typeStatus.text = "cljs"; - typeStatus.tooltip = "Connected to ClojureScript REPL"; - } else if (util.getREPLSessionType() === 'clj') { - typeStatus.text = "clj" - typeStatus.tooltip = "Connected to Clojure REPL"; - } - if (util.getREPLSessionType() === 'cljs' && state.extensionContext.workspaceState.get('cljsReplTypeHasBuilds')) { - if (cljsBuild !== null && util.getREPLSessionType() === 'cljs') { - cljsBuildStatus.text = cljsBuild; - cljsBuildStatus.tooltip = "Click to switch CLJS build REPL"; - } else if (cljsBuild === null) { - cljsBuildStatus.text = "no build connected" - cljsBuildStatus.tooltip = "Click to connect to a CLJS build REPL"; - } - } - } else if (util.getLaunchingState()) { - 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"; - } else if (util.getConnectingState()) { - connectionStatus.text = "nREPL - trying to connect"; - connectionStatus.tooltip = "Click to interrupt jack-in or Connect to REPL Server"; - connectionStatus.command = "calva.disconnect"; - } else { - connectionStatus.text = "nREPL $(zap)"; - connectionStatus.tooltip = "Click to jack-in or Connect to REPL Server"; - connectionStatus.color = color.disconnected; - connectionStatus.command = "calva.jackInOrConnect"; - } + cljsBuildStatus.update(); - connectionStatus.show(); - typeStatus.show(); - if (cljsBuildStatus.text) { - cljsBuildStatus.show(); - } else { - cljsBuildStatus.hide(); - } + prettyPrintToggle.update(); prettyPrintToggle.show(); } diff --git a/src/statusbar/prettyPrintStatusBar.ts b/src/statusbar/prettyPrintStatusBar.ts new file mode 100644 index 000000000..c85c4a04f --- /dev/null +++ b/src/statusbar/prettyPrintStatusBar.ts @@ -0,0 +1,31 @@ +import { window, StatusBarAlignment, StatusBarItem } from "vscode"; +import configReader from "../configReader"; +import * as state from '../state'; + +export class PrettyPrintStatusBar { + private statusBarItem: StatusBarItem; + constructor() { + this.statusBarItem = this.createStatusBarItem(); + this.update(); + } + + private createStatusBarItem() { + let sbi = window.createStatusBarItem(StatusBarAlignment.Right); + sbi.command = "calva.togglePrettyPrint"; + sbi.text = "pprint"; + return sbi; + } + + show = () => this.statusBarItem.show(); + + update() { + const color = configReader.colors; + const pprint = state.config().prettyPrintingOptions.enabled; + this.statusBarItem.tooltip = `Turn pretty printing ${pprint ? 'off' : 'on'}`; + this.statusBarItem.color = pprint ? color.active : color.inactive; + } + + dispose() { + this.statusBarItem.dispose(); + } +} diff --git a/src/statusbar/typeStatusBar.ts b/src/statusbar/typeStatusBar.ts new file mode 100644 index 000000000..dd35787b1 --- /dev/null +++ b/src/statusbar/typeStatusBar.ts @@ -0,0 +1,50 @@ +import { window, StatusBarAlignment, StatusBarItem } from "vscode"; +import { activeReplWindow } from '../repl-window'; +import configReader from "../configReader"; +import * as state from '../state'; +import * as util from '../utilities'; + +export class TypeStatusBar { + private statusBarItem: StatusBarItem; + constructor() { + this.statusBarItem = this.createStatusBarItem(); + } + + private createStatusBarItem() { + let sbi = window.createStatusBarItem(StatusBarAlignment.Left); + sbi.command = null; + sbi.text = "Disconnected"; + sbi.tooltip = "No active REPL session"; + sbi.color = configReader.colors.disconnected; + return sbi; + } + + show = () => this.statusBarItem.show(); + + update() { + let current = state.deref(), + doc = util.getDocument({}), + fileType = util.getFileType(doc); + + if(current.get('connected')) { + this.statusBarItem.color = configReader.colors.typeStatus; + if (fileType == 'cljc' && util.getREPLSessionType() !== null && !activeReplWindow()) { + this.statusBarItem.text = "cljc/" + util.getREPLSessionType() + if (util.getSession('clj') !== null && util.getSession('cljs') !== null) { + this.statusBarItem.command = "calva.toggleCLJCSession"; + this.statusBarItem.tooltip = `Click to use ${(util.getREPLSessionType() === 'clj' ? 'cljs' : 'clj')} REPL for cljc`; + } + } else if (util.getREPLSessionType() === 'cljs') { + this.statusBarItem.text = "cljs"; + this.statusBarItem.tooltip = "Connected to ClojureScript REPL"; + } else if (util.getREPLSessionType() === 'clj') { + this.statusBarItem.text = "clj" + this.statusBarItem.tooltip = "Connected to Clojure REPL"; + } + } + } + + dispose() { + this.statusBarItem.dispose(); + } +} From 7746aae1072823810406c3a3b8197bda84158dd0 Mon Sep 17 00:00:00 2001 From: stefan toubia Date: Sat, 23 Nov 2019 20:16:50 -0800 Subject: [PATCH 4/5] Refactor status bars --- src/extension.ts | 6 ++- src/statusbar/cljsBuildStatusBar.ts | 44 ++++++++++----------- src/statusbar/connectionStatusBar.ts | 54 ++++++++++++------------- src/statusbar/index.ts | 27 ++++++------- src/statusbar/prettyPrintStatusBar.ts | 18 +++------ src/statusbar/typeStatusBar.ts | 57 ++++++++++++++------------- 6 files changed, 98 insertions(+), 108 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index bbf36e3b9..37838971d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -107,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)); @@ -162,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()); diff --git a/src/statusbar/cljsBuildStatusBar.ts b/src/statusbar/cljsBuildStatusBar.ts index f4f6db92a..abfcfe7f3 100644 --- a/src/statusbar/cljsBuildStatusBar.ts +++ b/src/statusbar/cljsBuildStatusBar.ts @@ -4,37 +4,33 @@ import * as util from '../utilities'; export class CljsBuildStatusBar { private statusBarItem: StatusBarItem; - constructor() { - this.statusBarItem = this.createStatusBarItem(); - this.update(); + constructor(alignment: StatusBarAlignment) { + this.statusBarItem = window.createStatusBarItem(alignment); + this.statusBarItem.command = "calva.switchCljsBuild"; } - private createStatusBarItem() { - let sbi = window.createStatusBarItem(StatusBarAlignment.Left); - sbi.command = "calva.switchCljsBuild"; - sbi.text = null; - sbi.tooltip = null; - return sbi; - } - - show = () => this.statusBarItem.show(); - update() { - let current = state.deref(), - cljsBuild = current.get('cljsBuild'); + const current = state.deref(); + const cljsBuild = current.get('cljsBuild'); + const connected = current.get("connected"); + const sessionType = util.getREPLSessionType(); - if(current.get("connected")) { - if (util.getREPLSessionType() === 'cljs' && state.extensionContext.workspaceState.get('cljsReplTypeHasBuilds')) { - if (cljsBuild !== null && util.getREPLSessionType() === 'cljs') { - this.statusBarItem.text = cljsBuild; - this.statusBarItem.tooltip = "Click to switch CLJS build REPL"; - } else if (cljsBuild === null) { - this.statusBarItem.text = "no build connected" - this.statusBarItem.tooltip = "Click to connect to a CLJS build REPL"; - } + 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 { diff --git a/src/statusbar/connectionStatusBar.ts b/src/statusbar/connectionStatusBar.ts index cdfec81bb..f2eacae6c 100644 --- a/src/statusbar/connectionStatusBar.ts +++ b/src/statusbar/connectionStatusBar.ts @@ -1,48 +1,46 @@ import { window, StatusBarAlignment, StatusBarItem } from "vscode"; -import { activeReplWindow } from '../repl-window'; import configReader from "../configReader"; import * as state from '../state'; import * as util from '../utilities'; export class ConnectionStatusBar { private statusBarItem: StatusBarItem; - constructor() { - this.statusBarItem = this.createStatusBarItem(); - } - private createStatusBarItem() { - let sbi = window.createStatusBarItem(StatusBarAlignment.Left); - sbi.command = null; - sbi.tooltip = "REPL connection status"; - return sbi; + constructor(alignment: StatusBarAlignment) { + this.statusBarItem = window.createStatusBarItem(alignment); } - show = () => this.statusBarItem.show(); - update() { let current = state.deref(); - const color = configReader.colors; + 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')) { - this.statusBarItem.text = "nREPL $(zap)"; - this.statusBarItem.color = color.connected; - this.statusBarItem.tooltip = `nrepl://${current.get('hostname')}:${current.get('port')} (Click to reset connection)`; - this.statusBarItem.command = "calva.jackInOrConnect"; + text = "nREPL $(zap)"; + color = colors.connected; + tooltip = `nrepl://${current.get('hostname')}:${current.get('port')} (Click to reset connection)`; } else if (util.getLaunchingState()) { - this.statusBarItem.color = color.launching; - this.statusBarItem.text = "Launching REPL using " + util.getLaunchingState(); - this.statusBarItem.tooltip = "Click to interrupt jack-in or Connect to REPL Server"; - this.statusBarItem.command = "calva.disconnect"; + 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()) { - this.statusBarItem.text = "nREPL - trying to connect"; - this.statusBarItem.tooltip = "Click to interrupt jack-in or Connect to REPL Server"; - this.statusBarItem.command = "calva.disconnect"; - } else { - this.statusBarItem.text = "nREPL $(zap)"; - this.statusBarItem.tooltip = "Click to jack-in or Connect to REPL Server"; - this.statusBarItem.color = color.disconnected; - this.statusBarItem.command = "calva.jackInOrConnect"; + 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() { diff --git a/src/statusbar/index.ts b/src/statusbar/index.ts index a875f8616..e76628a94 100644 --- a/src/statusbar/index.ts +++ b/src/statusbar/index.ts @@ -1,26 +1,25 @@ +import { StatusBarAlignment } from "vscode"; import { TypeStatusBar } from "./typeStatusBar"; import { PrettyPrintStatusBar } from "./prettyPrintStatusBar"; import { CljsBuildStatusBar } from "./cljsBuildStatusBar"; import { ConnectionStatusBar } from "./connectionStatusBar"; -const connectionStatus = new ConnectionStatusBar(); -const typeStatus = new TypeStatusBar(); -const cljsBuildStatus = new CljsBuildStatusBar(); -const prettyPrintToggle = new PrettyPrintStatusBar(); +const statusBarItems = []; -function update() { - connectionStatus.update(); - connectionStatus.show(); - - typeStatus.update(); - typeStatus.show(); - - cljsBuildStatus.update(); +function init(): any[] { + statusBarItems.push(new ConnectionStatusBar(StatusBarAlignment.Left)); + statusBarItems.push(new TypeStatusBar(StatusBarAlignment.Left)); + statusBarItems.push(new CljsBuildStatusBar(StatusBarAlignment.Left)); + statusBarItems.push(new PrettyPrintStatusBar(StatusBarAlignment.Right)); + update(); + return statusBarItems; +} - prettyPrintToggle.update(); - prettyPrintToggle.show(); +function update() { + statusBarItems.forEach(sbi => sbi.update()); } export default { + init, update } diff --git a/src/statusbar/prettyPrintStatusBar.ts b/src/statusbar/prettyPrintStatusBar.ts index c85c4a04f..ad0b6d21a 100644 --- a/src/statusbar/prettyPrintStatusBar.ts +++ b/src/statusbar/prettyPrintStatusBar.ts @@ -4,25 +4,19 @@ import * as state from '../state'; export class PrettyPrintStatusBar { private statusBarItem: StatusBarItem; - constructor() { - this.statusBarItem = this.createStatusBarItem(); - this.update(); + constructor(alignment: StatusBarAlignment) { + this.statusBarItem = window.createStatusBarItem(alignment); + this.statusBarItem.command = "calva.togglePrettyPrint"; + this.statusBarItem.text = "pprint"; } - private createStatusBarItem() { - let sbi = window.createStatusBarItem(StatusBarAlignment.Right); - sbi.command = "calva.togglePrettyPrint"; - sbi.text = "pprint"; - return sbi; - } - - show = () => this.statusBarItem.show(); - update() { const color = configReader.colors; const pprint = state.config().prettyPrintingOptions.enabled; this.statusBarItem.tooltip = `Turn pretty printing ${pprint ? 'off' : 'on'}`; this.statusBarItem.color = pprint ? color.active : color.inactive; + + this.statusBarItem.show(); } dispose() { diff --git a/src/statusbar/typeStatusBar.ts b/src/statusbar/typeStatusBar.ts index dd35787b1..5a46b2e2d 100644 --- a/src/statusbar/typeStatusBar.ts +++ b/src/statusbar/typeStatusBar.ts @@ -6,42 +6,43 @@ import * as util from '../utilities'; export class TypeStatusBar { private statusBarItem: StatusBarItem; - constructor() { - this.statusBarItem = this.createStatusBarItem(); + constructor(alignment: StatusBarAlignment) { + this.statusBarItem = window.createStatusBarItem(alignment); } - private createStatusBarItem() { - let sbi = window.createStatusBarItem(StatusBarAlignment.Left); - sbi.command = null; - sbi.text = "Disconnected"; - sbi.tooltip = "No active REPL session"; - sbi.color = configReader.colors.disconnected; - return sbi; - } - - show = () => this.statusBarItem.show(); - update() { - let current = state.deref(), - doc = util.getDocument({}), - fileType = util.getFileType(doc); + const connected = state.deref().get("connected"); + const doc = util.getDocument({}); + const fileType = util.getFileType(doc); + const sessionType = util.getREPLSessionType(); - if(current.get('connected')) { - this.statusBarItem.color = configReader.colors.typeStatus; - if (fileType == 'cljc' && util.getREPLSessionType() !== null && !activeReplWindow()) { - this.statusBarItem.text = "cljc/" + util.getREPLSessionType() + let command = null; + let text = "Disconnected"; + let tooltip = "No active REPL session"; + let color = configReader.colors.disconnected; + + if(connected) { + if (fileType == 'cljc' && sessionType !== null && !activeReplWindow()) { + text = "cljc/" + sessionType; if (util.getSession('clj') !== null && util.getSession('cljs') !== null) { - this.statusBarItem.command = "calva.toggleCLJCSession"; - this.statusBarItem.tooltip = `Click to use ${(util.getREPLSessionType() === 'clj' ? 'cljs' : 'clj')} REPL for cljc`; + command = "calva.toggleCLJCSession"; + tooltip = `Click to use ${(sessionType === 'clj' ? 'cljs' : 'clj')} REPL for cljc`; } - } else if (util.getREPLSessionType() === 'cljs') { - this.statusBarItem.text = "cljs"; - this.statusBarItem.tooltip = "Connected to ClojureScript REPL"; - } else if (util.getREPLSessionType() === 'clj') { - this.statusBarItem.text = "clj" - this.statusBarItem.tooltip = "Connected to Clojure REPL"; + } else if (sessionType === 'cljs') { + text = "cljs"; + tooltip = "Connected to ClojureScript REPL"; + } else if (sessionType === 'clj') { + text = "clj"; + tooltip = "Connected to Clojure REPL"; } + color = configReader.colors.typeStatus; } + + this.statusBarItem.command = command; + this.statusBarItem.text = text; + this.statusBarItem.tooltip = tooltip; + this.statusBarItem.color = color + this.statusBarItem.show(); } dispose() { From 38b2207df039a7032bc881723ab2d9f40359ed3b Mon Sep 17 00:00:00 2001 From: stefan toubia Date: Sun, 24 Nov 2019 17:32:07 -0800 Subject: [PATCH 5/5] Rename status bar item classes --- .../{cljsBuildStatusBar.ts => cljs-build.ts} | 2 +- .../{connectionStatusBar.ts => connection.ts} | 2 +- src/statusbar/{typeStatusBar.ts => file-type.ts} | 2 +- src/statusbar/index.ts | 16 ++++++++-------- .../{prettyPrintStatusBar.ts => pretty-print.ts} | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) rename src/statusbar/{cljsBuildStatusBar.ts => cljs-build.ts} (97%) rename src/statusbar/{connectionStatusBar.ts => connection.ts} (97%) rename src/statusbar/{typeStatusBar.ts => file-type.ts} (98%) rename src/statusbar/{prettyPrintStatusBar.ts => pretty-print.ts} (95%) diff --git a/src/statusbar/cljsBuildStatusBar.ts b/src/statusbar/cljs-build.ts similarity index 97% rename from src/statusbar/cljsBuildStatusBar.ts rename to src/statusbar/cljs-build.ts index abfcfe7f3..537c02239 100644 --- a/src/statusbar/cljsBuildStatusBar.ts +++ b/src/statusbar/cljs-build.ts @@ -2,7 +2,7 @@ import { window, StatusBarAlignment, StatusBarItem } from "vscode"; import * as state from '../state'; import * as util from '../utilities'; -export class CljsBuildStatusBar { +export class CljsBuildStatusBarItem { private statusBarItem: StatusBarItem; constructor(alignment: StatusBarAlignment) { this.statusBarItem = window.createStatusBarItem(alignment); diff --git a/src/statusbar/connectionStatusBar.ts b/src/statusbar/connection.ts similarity index 97% rename from src/statusbar/connectionStatusBar.ts rename to src/statusbar/connection.ts index f2eacae6c..370b6287b 100644 --- a/src/statusbar/connectionStatusBar.ts +++ b/src/statusbar/connection.ts @@ -3,7 +3,7 @@ import configReader from "../configReader"; import * as state from '../state'; import * as util from '../utilities'; -export class ConnectionStatusBar { +export class ConnectionStatusBarItem { private statusBarItem: StatusBarItem; constructor(alignment: StatusBarAlignment) { diff --git a/src/statusbar/typeStatusBar.ts b/src/statusbar/file-type.ts similarity index 98% rename from src/statusbar/typeStatusBar.ts rename to src/statusbar/file-type.ts index 5a46b2e2d..e10c141f7 100644 --- a/src/statusbar/typeStatusBar.ts +++ b/src/statusbar/file-type.ts @@ -4,7 +4,7 @@ import configReader from "../configReader"; import * as state from '../state'; import * as util from '../utilities'; -export class TypeStatusBar { +export class FileTypeStatusBarItem { private statusBarItem: StatusBarItem; constructor(alignment: StatusBarAlignment) { this.statusBarItem = window.createStatusBarItem(alignment); diff --git a/src/statusbar/index.ts b/src/statusbar/index.ts index e76628a94..7df827f7e 100644 --- a/src/statusbar/index.ts +++ b/src/statusbar/index.ts @@ -1,16 +1,16 @@ import { StatusBarAlignment } from "vscode"; -import { TypeStatusBar } from "./typeStatusBar"; -import { PrettyPrintStatusBar } from "./prettyPrintStatusBar"; -import { CljsBuildStatusBar } from "./cljsBuildStatusBar"; -import { ConnectionStatusBar } from "./connectionStatusBar"; +import { FileTypeStatusBarItem } from "./file-type"; +import { PrettyPrintStatusBarItem } from "./pretty-print"; +import { CljsBuildStatusBarItem } from "./cljs-build"; +import { ConnectionStatusBarItem } from "./connection"; const statusBarItems = []; function init(): any[] { - statusBarItems.push(new ConnectionStatusBar(StatusBarAlignment.Left)); - statusBarItems.push(new TypeStatusBar(StatusBarAlignment.Left)); - statusBarItems.push(new CljsBuildStatusBar(StatusBarAlignment.Left)); - statusBarItems.push(new PrettyPrintStatusBar(StatusBarAlignment.Right)); + statusBarItems.push(new ConnectionStatusBarItem(StatusBarAlignment.Left)); + statusBarItems.push(new FileTypeStatusBarItem(StatusBarAlignment.Left)); + statusBarItems.push(new CljsBuildStatusBarItem(StatusBarAlignment.Left)); + statusBarItems.push(new PrettyPrintStatusBarItem(StatusBarAlignment.Right)); update(); return statusBarItems; } diff --git a/src/statusbar/prettyPrintStatusBar.ts b/src/statusbar/pretty-print.ts similarity index 95% rename from src/statusbar/prettyPrintStatusBar.ts rename to src/statusbar/pretty-print.ts index ad0b6d21a..b076b8b26 100644 --- a/src/statusbar/prettyPrintStatusBar.ts +++ b/src/statusbar/pretty-print.ts @@ -2,7 +2,7 @@ import { window, StatusBarAlignment, StatusBarItem } from "vscode"; import configReader from "../configReader"; import * as state from '../state'; -export class PrettyPrintStatusBar { +export class PrettyPrintStatusBarItem { private statusBarItem: StatusBarItem; constructor(alignment: StatusBarAlignment) { this.statusBarItem = window.createStatusBarItem(alignment);