forked from BetterThanTomorrow/calva
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add nREPL evaluation status bar indicator #1
Open
stefan-toubia
wants to merge
2
commits into
stefan/refactor-status-bars
Choose a base branch
from
wip/nrepl-client-events
base: stefan/refactor-status-bars
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,13 @@ | ||
interface Event { | ||
type: string | ||
} | ||
|
||
export class NReplEvaluationStartedEvent implements Event { | ||
type = "started" | ||
constructor(public fileName: string, public filePath: string){} | ||
} | ||
|
||
export class NReplEvaluationFinishedEvent implements Event { | ||
type = "finished"; | ||
constructor(public fileName: string, public filePath: string, public error?:string){} | ||
} |
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
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,143 @@ | ||
import { window, StatusBarAlignment, StatusBarItem } from "vscode"; | ||
import { activeReplWindow } from '../repl-window'; | ||
|
||
import { onNReplEvent } from "../nrepl"; | ||
import { NReplEvaluationStartedEvent, NReplEvaluationFinishedEvent } from "../nrepl/events"; | ||
|
||
import configReader from "../configReader"; | ||
import * as state from '../state'; | ||
import * as util from '../utilities'; | ||
|
||
export interface EvaluationError { | ||
fileName: string; | ||
filePath: string; | ||
message: string; | ||
} | ||
|
||
export class FileTypeStatusBarItem { | ||
private statusBarItem: StatusBarItem; | ||
|
||
private activeEvals = new Array<string>(); | ||
|
||
private errors = new Array<EvaluationError>(); | ||
|
||
private get isEvaluating() { | ||
return this.activeEvals.length > 0; | ||
} | ||
|
||
private get hasErrors(){ | ||
return this.errors.length > 0; | ||
} | ||
|
||
constructor(alignment: StatusBarAlignment) { | ||
this.statusBarItem = window.createStatusBarItem(alignment); | ||
// TODO: Event handling and resulting state should be moved to global state | ||
onNReplEvent(this.handleNreplEvent); | ||
} | ||
|
||
update() { | ||
const connected = state.deref().get("connected"); | ||
const doc = util.getDocument({}); | ||
const fileType = util.getFileType(doc); | ||
const sessionType = 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 = this.statusTextDecorator("cljc/" + sessionType); | ||
if (util.getSession('clj') !== null && util.getSession('cljs') !== null) { | ||
command = "calva.toggleCLJCSession"; | ||
tooltip = `Click to use ${(sessionType === 'clj' ? 'cljs' : 'clj')} REPL for cljc`; | ||
} | ||
} else if (sessionType === 'cljs') { | ||
text = this.statusTextDecorator("cljs"); | ||
tooltip = "Connected to ClojureScript REPL"; | ||
} else if (sessionType === 'clj') { | ||
text = this.statusTextDecorator("clj"); | ||
tooltip = "Connected to Clojure REPL"; | ||
} | ||
color = this.connectedStatusColor(); | ||
if(this.hasErrors) { | ||
tooltip = this.errorTooltip(); | ||
} | ||
} | ||
|
||
this.statusBarItem.command = command; | ||
this.statusBarItem.text = text; | ||
this.statusBarItem.tooltip = tooltip; | ||
this.statusBarItem.color = color | ||
this.statusBarItem.show(); | ||
} | ||
|
||
private statusTextDecorator(text): string { | ||
if(this.hasErrors) { | ||
const c = this.errors.length; | ||
text = `${text} $(alert) ${c > 1 ? c : ""}` | ||
} | ||
if(this.isEvaluating) { | ||
text = text + " $(gear~spin)"; | ||
} | ||
return text; | ||
} | ||
|
||
private connectedStatusColor(): string { | ||
const c = configReader.colors; | ||
if(this.hasErrors) { | ||
return c.error; | ||
} else if (this.isEvaluating) { | ||
return c.launching; | ||
} | ||
return c.typeStatus; | ||
} | ||
|
||
private errorTooltip(): string { | ||
if(this.errors.length > 1){ | ||
return "There are errors in multiple files"; | ||
} | ||
const err = this.errors[0]; | ||
return `Error: ${err.fileName}: ${err.message}`; | ||
} | ||
|
||
private handleNreplEvent = (e: NReplEvaluationStartedEvent | NReplEvaluationFinishedEvent) => { | ||
switch(e.type){ | ||
case "started": | ||
this.removeError(e.filePath); | ||
this.activeEvals.push(e.filePath); | ||
break; | ||
case "finished": | ||
this.removeActive(e.filePath); | ||
const fe = <NReplEvaluationFinishedEvent> e; | ||
if(fe.error) { | ||
this.errors.push({ | ||
fileName: fe.fileName, | ||
filePath: fe.filePath, | ||
message: fe.error | ||
}); | ||
} | ||
break; | ||
} | ||
this.update(); | ||
} | ||
|
||
private removeActive(filePath: string) { | ||
const idx = this.activeEvals.indexOf(filePath); | ||
if(idx !== -1) { | ||
this.activeEvals.splice(idx, 1); | ||
} | ||
} | ||
|
||
private removeError(filePath: string) { | ||
const idx = this.errors.findIndex(e => e.filePath === filePath); | ||
if(idx !== -1) { | ||
this.errors.splice(idx, 1); | ||
} | ||
} | ||
|
||
dispose() { | ||
this.statusBarItem.dispose(); | ||
} | ||
} |
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 |
---|---|---|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the +Item renames |
||
statusBarItems.push(new FileTypeStatusBarItem(StatusBarAlignment.Left)); | ||
statusBarItems.push(new CljsBuildStatusBarItem(StatusBarAlignment.Left)); | ||
statusBarItems.push(new PrettyPrintStatusBarItem(StatusBarAlignment.Right)); | ||
update(); | ||
return statusBarItems; | ||
} | ||
|
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 was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, what's this
$(alert)
do in this template literal? Or is it just a temporary placeholder?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an icon! https://code.visualstudio.com/api/references/icons-in-labels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks!