-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add status icon feature and cleanup (#56)
* 54: remove process env GA method * 55: use rel sf compare by default add metric to judge the number of people swapping back * 53: collapse watch commands and add remove * cleanup tslint * 53: add statusbar item and toggler * 51: switch to DI for gutters * cleanup tool tip naming * add more tests to gutters * cleanup textEditor being null * cleanup error case on render coverage
- Loading branch information
Showing
9 changed files
with
207 additions
and
89 deletions.
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
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 |
---|---|---|
@@ -1,117 +1,131 @@ | ||
import { | ||
ExtensionContext, | ||
Disposable, | ||
FileSystemWatcher, | ||
StatusBarItem, | ||
TextEditor, | ||
version, | ||
window, | ||
} from "vscode"; | ||
|
||
import {Fs} from "./wrappers/fs"; | ||
import {LcovParse} from "./wrappers/lcov-parse"; | ||
import {Vscode} from "./wrappers/vscode"; | ||
|
||
import {Config, IConfigStore} from "./config"; | ||
import {IConfigStore} from "./config"; | ||
import {Indicators} from "./indicators"; | ||
import {Lcov} from "./lcov"; | ||
import {Reporter} from "./reporter"; | ||
import {StatusBarToggler} from "./statusbartoggler"; | ||
|
||
const vscodeImpl = new Vscode(); | ||
const fsImpl = new Fs(); | ||
const parseImpl = new LcovParse(); | ||
|
||
export class Gutters { | ||
private configStore: IConfigStore; | ||
private lcovWatcher: FileSystemWatcher; | ||
private editorWatcher: Disposable; | ||
private statusBarItem: StatusBarItem; | ||
private lcov: Lcov; | ||
private indicators: Indicators; | ||
private reporter: Reporter; | ||
private statusBar: StatusBarToggler; | ||
|
||
constructor(context: ExtensionContext, reporter: Reporter) { | ||
this.configStore = new Config(vscodeImpl, context, reporter).setup(); | ||
this.lcov = new Lcov(this.configStore, vscodeImpl, fsImpl); | ||
this.indicators = new Indicators(parseImpl, vscodeImpl, this.configStore); | ||
constructor( | ||
configStore: IConfigStore, | ||
lcov: Lcov, | ||
indicators: Indicators, | ||
reporter: Reporter, | ||
statusBar: StatusBarToggler, | ||
) { | ||
this.configStore = configStore; | ||
this.lcov = lcov; | ||
this.indicators = indicators; | ||
this.statusBar = statusBar; | ||
this.reporter = reporter; | ||
|
||
this.reporter.sendEvent("user", "start"); | ||
this.reporter.sendEvent("user", "vscodeVersion", version); | ||
} | ||
|
||
public async displayCoverageForActiveFile() { | ||
const textEditor = window.activeTextEditor; | ||
try { | ||
if (!textEditor) { return; } | ||
const lcovPath = await this.lcov.find(); | ||
await this.loadAndRenderCoverage(textEditor, lcovPath); | ||
|
||
this.reporter.sendEvent("user", "display-coverage"); | ||
} catch (error) { | ||
this.handleError(error); | ||
} | ||
} | ||
|
||
/** | ||
* Watch the lcov file and iterate over textEditors when changes occur | ||
*/ | ||
public async watchLcovFile() { | ||
if (this.lcovWatcher) { return; } | ||
public async watchLcovAndVisibleEditors() { | ||
if (this.lcovWatcher && this.editorWatcher) { return; } | ||
|
||
try { | ||
const lcovPath = await this.lcov.find(); | ||
this.lcovWatcher = vscodeImpl.watchFile(lcovPath); | ||
this.lcovWatcher.onDidChange(async (event) => { | ||
window.visibleTextEditors.forEach(async (editor) => { | ||
await this.loadAndRenderCoverage(editor, lcovPath); | ||
}); | ||
}); | ||
this.reporter.sendEvent("user", "watch-lcov"); | ||
this.lcovWatcher.onDidChange((event) => this.renderCoverageOnVisible(lcovPath)); | ||
this.editorWatcher = window.onDidChangeVisibleTextEditors( | ||
(event) => this.renderCoverageOnVisible(lcovPath)); | ||
this.statusBar.toggle(); | ||
|
||
this.reporter.sendEvent("user", "watch-lcov-editors"); | ||
} catch (error) { | ||
this.handleError(error); | ||
} | ||
} | ||
|
||
/** | ||
* Watch the visible editors and render coverage when changes occur | ||
*/ | ||
public async watchVisibleEditors() { | ||
try { | ||
const lcovPath = await this.lcov.find(); | ||
window.onDidChangeVisibleTextEditors(async (event) => { | ||
window.visibleTextEditors.forEach(async (editor) => { | ||
await this.loadAndRenderCoverage(editor, lcovPath); | ||
}); | ||
}); | ||
this.reporter.sendEvent("user", "watch-editors"); | ||
} catch (error) { | ||
this.handleError(error); | ||
} | ||
public removeWatch() { | ||
this.lcovWatcher.dispose(); | ||
this.editorWatcher.dispose(); | ||
this.lcovWatcher = null; | ||
this.editorWatcher = null; | ||
this.statusBar.toggle(); | ||
|
||
this.reporter.sendEvent("user", "remove-watch"); | ||
} | ||
|
||
public removeCoverageForActiveFile() { | ||
const activeEditor = window.activeTextEditor; | ||
this.removeDecorationsForTextEditor(activeEditor); | ||
|
||
this.reporter.sendEvent("user", "remove-coverage"); | ||
} | ||
|
||
public dispose() { | ||
this.lcovWatcher.dispose(); | ||
this.editorWatcher.dispose(); | ||
this.statusBar.dispose(); | ||
|
||
this.reporter.sendEvent("cleanup", "dispose"); | ||
} | ||
|
||
private handleError(error: Error) { | ||
const message = error.message ? error.message : error; | ||
window.showWarningMessage(message.toString()); | ||
|
||
this.reporter.sendEvent("error", message.toString()); | ||
} | ||
|
||
private removeDecorationsForTextEditor(editor: TextEditor) { | ||
if (!editor) { return; } | ||
editor.setDecorations(this.configStore.fullCoverageDecorationType, []); | ||
editor.setDecorations(this.configStore.partialCoverageDecorationType, []); | ||
editor.setDecorations(this.configStore.noCoverageDecorationType, []); | ||
private removeDecorationsForTextEditor(textEditor: TextEditor) { | ||
if (!textEditor) { return; } | ||
textEditor.setDecorations(this.configStore.fullCoverageDecorationType, []); | ||
textEditor.setDecorations(this.configStore.partialCoverageDecorationType, []); | ||
textEditor.setDecorations(this.configStore.noCoverageDecorationType, []); | ||
} | ||
|
||
private async loadAndRenderCoverage(textEditor: TextEditor, lcovPath: string): Promise<void> { | ||
const lcovFile = await this.lcov.load(lcovPath); | ||
const file = textEditor.document.fileName; | ||
const coveredLines = await this.indicators.extract(lcovFile, file); | ||
await this.indicators.renderToTextEditor(coveredLines, textEditor); | ||
|
||
this.reporter.sendEvent("user", "loadAndRenderCoverage"); | ||
} | ||
|
||
private renderCoverageOnVisible(lcovPath: string) { | ||
window.visibleTextEditors.forEach(async (editor) => { | ||
if (!editor) { return; } | ||
await this.loadAndRenderCoverage(editor, lcovPath); | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.