Skip to content

Commit

Permalink
Cleanup watch and render functions (#79)
Browse files Browse the repository at this point in the history
* prevent document is not defined error

* always start watch even on coverage error for active file

* add lcov file content check to prevent failed to parse error

* convert icon to png

* remove uuid use unique machine id

* increment image vscode version

* increment appveyor code version
  • Loading branch information
ryanluker authored Jul 15, 2017
1 parent 1d411bb commit d2c7616
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 140 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
environment:
CODE_VERSION: 1.12.2
CODE_VERSION: 1.14.0

install:
- ps: Install-Product node 6.11.0 x64
Expand Down
Binary file added images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 0 additions & 103 deletions images/icon.svg

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"type": "git",
"url": "https://github.com/ryanluker/vscode-coverage-gutters"
},
"icon": "images/icon.svg",
"icon": "images/icon.png",
"galleryBanner": {
"color": "#24381b",
"theme": "dark"
},
"bugs": "https://github.com/ryanluker/vscode-coverage-gutters/issues",
"publisher": "ryanluker",
"engines": {
"vscode": "^1.11.0"
"vscode": "^1.14.0"
},
"categories": [
"Other"
Expand Down
3 changes: 1 addition & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {Fs} from "./wrappers/fs";
import {Glob} from "./wrappers/glob";
import {LcovParse} from "./wrappers/lcov-parse";
import {Request} from "./wrappers/request";
import {Uuid} from "./wrappers/uuid";
import {Vscode} from "./wrappers/vscode";

const fsImpl = new Fs();
Expand All @@ -19,7 +18,7 @@ const globImpl = new Glob();

export function activate(context: vscode.ExtensionContext) {
const enableMetrics = vscode.workspace.getConfiguration("telemetry").get("enableTelemetry") as boolean;
const reporter = new Reporter(new Request(), new Uuid(), "", enableMetrics);
const reporter = new Reporter(new Request(), vscode.env.machineId, "", enableMetrics);
const configStore = new Config(vscodeImpl, context, reporter).get();
const statusBarToggler = new StatusBarToggler(configStore);
const lcov = new Lcov(configStore, globImpl, vscodeImpl, fsImpl);
Expand Down
6 changes: 5 additions & 1 deletion src/gutters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export class Gutters {
const textEditor = window.activeTextEditor;
try {
const lcovPath = await this.lcov.find();
await this.loadAndRenderCoverage(textEditor, lcovPath);

// When we try to load the coverage when watch is actived we dont want to error
// if the active file has no coverage
this.loadAndRenderCoverage(textEditor, lcovPath).catch(() => {});

this.lcovWatcher = vscodeImpl.watchFile(lcovPath);
this.lcovWatcher.onDidChange((event) => this.renderCoverageOnVisible(lcovPath));
Expand Down Expand Up @@ -124,6 +127,7 @@ export class Gutters {
}

private async loadAndRenderCoverage(textEditor: TextEditor, lcovPath: string): Promise<void> {
if (!textEditor.document) { return ; }
const lcovFile = await this.lcov.load(lcovPath);
const file = textEditor.document.fileName;
const coveredLines = await this.indicators.extract(lcovFile, file);
Expand Down
1 change: 1 addition & 0 deletions src/indicators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class Indicators {
}

public extract(lcovFile: string, file: string): Promise<LcovSection> {
if (lcovFile === "") { return Promise.reject("No coverage details inside lcov file!"); }
return new Promise<LcovSection>((resolve, reject) => {
this.parse.source(lcovFile, (err, data) => {
if (err) { return reject(err); }
Expand Down
7 changes: 3 additions & 4 deletions src/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import {Request} from "./wrappers/request";
import {Uuid} from "./wrappers/uuid";

const EXT_NAME = "vscode-coverage-gutters";
const EXT_VERSION = "1.0.0";
const EXT_VERSION = "1.1.0";

export class Reporter {
private readonly cid: string;
private readonly enableMetrics: boolean;
private readonly gaTrackingId: string;
private readonly request: Request;

constructor(request: Request, uuid: Uuid, gaTrackingId: string, enableMetrics: boolean) {
constructor(request: Request, machineId: string, gaTrackingId: string, enableMetrics: boolean) {
this.gaTrackingId = gaTrackingId;
this.request = request;
this.cid = uuid.get();
this.cid = machineId;
this.enableMetrics = enableMetrics;
}

Expand Down
7 changes: 0 additions & 7 deletions src/wrappers/uuid.ts

This file was deleted.

24 changes: 4 additions & 20 deletions test/reporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ suite("Reporter Tests", function() {
},
};

const fakeUuid = {
get() {
return "fakeuuidhere";
},
};
const fakeUuid = "fakeuuidhere";

const reporter = new Reporter(fakeRequest, fakeUuid, "", false);
reporter.sendEvent("test", "action");
Expand All @@ -30,11 +26,7 @@ suite("Reporter Tests", function() {
},
};

const fakeUuid = {
get() {
return "fakeuuidhere";
},
};
const fakeUuid = "fakeuuidhere";

const reporter = new Reporter(fakeRequest, fakeUuid, "", true);
reporter.sendEvent("test", "action");
Expand All @@ -49,11 +41,7 @@ suite("Reporter Tests", function() {
},
};

const fakeUuid = {
get() {
return "fakeuuidhere";
},
};
const fakeUuid = "fakeuuidhere";

const reporter = new Reporter(fakeRequest, fakeUuid, "", true);
reporter.sendEvent("test", "action");
Expand All @@ -68,11 +56,7 @@ suite("Reporter Tests", function() {
},
};

const fakeUuid = {
get() {
return "fakeuuidhere";
},
};
const fakeUuid = "fakeuuidhere";

const reporter = new Reporter(fakeRequest, fakeUuid, "123", true);
reporter.sendEvent("test", "action");
Expand Down

0 comments on commit d2c7616

Please sign in to comment.