-
Notifications
You must be signed in to change notification settings - Fork 514
Show formatting status in status bar #461
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
Changes from 5 commits
3ca0e93
8456749
00c6a13
19b20d2
e592d5a
6a438d2
99a17cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
|
||
import { | ||
StatusBarItem, | ||
StatusBarAlignment, | ||
Disposable, | ||
window} from "vscode"; | ||
|
||
export function setAnimatedStatusBarMessage(text: string, hideWhenDone: Thenable<any>): Disposable { | ||
let animatedStatusBarItem: AnimatedStatuBarItem = new AnimatedStatuBarItem(text); | ||
animatedStatusBarItem.show(hideWhenDone); | ||
return animatedStatusBarItem; | ||
} | ||
|
||
class AnimatedStatuBarItem implements StatusBarItem { | ||
private readonly animationRate: number; | ||
private statusBarItem: StatusBarItem; | ||
private maxCount: number; | ||
private counter: number; | ||
private baseText: string; | ||
private timerInterval: number; | ||
private elapsedTime: number; | ||
private intervalId: NodeJS.Timer; | ||
private suffixStates: string[]; | ||
|
||
get alignment(): StatusBarAlignment { | ||
return this.statusBarItem.alignment; | ||
} | ||
|
||
get priority(): number { | ||
return this.statusBarItem.priority; | ||
} | ||
|
||
get text(): string { | ||
return this.statusBarItem.text; | ||
} | ||
|
||
set text(value: string) { | ||
this.statusBarItem.text = value; | ||
} | ||
|
||
get tooltip(): string { | ||
return this.statusBarItem.tooltip; | ||
} | ||
|
||
set tooltip(value: string) { | ||
this.statusBarItem.tooltip = value; | ||
} | ||
|
||
get color(): string { | ||
return this.statusBarItem.color; | ||
} | ||
|
||
set color(value: string) { | ||
this.statusBarItem.color = value; | ||
} | ||
|
||
get command(): string { | ||
return this.statusBarItem.command; | ||
} | ||
|
||
set command(value: string) { | ||
this.statusBarItem.command = value; | ||
} | ||
|
||
constructor(baseText: string, alignment?: StatusBarAlignment, priority?: number) { | ||
this.animationRate = 1; | ||
this.statusBarItem = window.createStatusBarItem(alignment, priority); | ||
this.baseText = baseText; | ||
this.counter = 0; | ||
this.suffixStates = [" ", ". ", ".. ", "..."]; | ||
this.maxCount = this.suffixStates.length; | ||
this.timerInterval = ((1/this.maxCount) * 1000) / this.animationRate; | ||
this.elapsedTime = 0; | ||
} | ||
|
||
show(hideWhenDone?: Thenable<any>): void { | ||
this.statusBarItem.show(); | ||
this._start(); | ||
if (hideWhenDone !== undefined) { | ||
hideWhenDone.then(() => this.hide()); | ||
} | ||
} | ||
|
||
hide(): void { | ||
this._stop(); | ||
this.statusBarItem.hide(); | ||
} | ||
|
||
dispose(): void { | ||
this.statusBarItem.dispose(); | ||
} | ||
|
||
_updateCounter(): void { | ||
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. TypeScript has 'private' visibility, you should use that instead of the underscore naming convention 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. fixed. |
||
this.counter = (this.counter + 1) % this.maxCount; | ||
this.elapsedTime = this.elapsedTime + this.timerInterval; | ||
} | ||
|
||
_updateText(): void { | ||
this.text = this.baseText + this.suffixStates[this.counter]; | ||
} | ||
|
||
_update(): void { | ||
this._updateCounter(); | ||
this._updateText(); | ||
} | ||
|
||
_reset(): void { | ||
this.counter = 0; | ||
this._updateText(); | ||
} | ||
|
||
_start(): void { | ||
this._reset(); | ||
this.intervalId = setInterval(() => this._update(), this.timerInterval); | ||
} | ||
|
||
_stop(): void { | ||
clearInterval(this.intervalId); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import Window = vscode.window; | |
import { IFeature } from '../feature'; | ||
import * as Settings from '../settings'; | ||
import * as Utils from '../utils'; | ||
import * as AnimatedStatusBar from '../animatedStatusBar'; | ||
|
||
export namespace ScriptFileMarkersRequest { | ||
export const type: RequestType<any, any, void> = { get method(): string { return "powerShell/getScriptFileMarkers"; } }; | ||
|
@@ -110,14 +111,17 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider | |
range: Range, | ||
options: FormattingOptions, | ||
token: CancellationToken): TextEdit[] | Thenable<TextEdit[]> { | ||
return this.executeRulesInOrder(document, range, options, 0); | ||
|
||
let textEdits: Thenable<TextEdit[]> = this.executeRulesInOrder(document, range, options, 0); | ||
AnimatedStatusBar.setAnimatedStatusBarMessage("formatting", textEdits); | ||
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'd recommend a more obvious string like "PowerShell code formatting in progress" |
||
return textEdits; | ||
} | ||
|
||
executeRulesInOrder( | ||
document: TextDocument, | ||
range: Range, | ||
options: FormattingOptions, | ||
index: number): Thenable<TextEdit[]> | TextEdit[] { | ||
index: number): Thenable<TextEdit[]> { | ||
if (this.languageClient !== null && index < this.ruleOrder.length) { | ||
let rule = this.ruleOrder[index]; | ||
let uniqueEdits: ScriptRegion[] = []; | ||
|
@@ -172,7 +176,7 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider | |
return this.executeRulesInOrder(document, range, options, index + 1); | ||
}); | ||
} else { | ||
return TextEdit[0]; | ||
return Promise.resolve(TextEdit[0]); | ||
} | ||
} | ||
|
||
|
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.
Slight typo, should be AnimatedStatusBarItem
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.
fixed.