diff --git a/README.md b/README.md index cdb6f4c..e25aa80 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,9 @@ See [examples directory](example) on how to setup a project. ## Requirements - vscode 1.27.0 and up - macos, linux or windows +- Requires Live Preview extension + - vscode extension id: ms-vscode.live-server + - v0.2.12 or higher ## Extension Settings See extension setting options in IDE. diff --git a/package-lock.json b/package-lock.json index 2028710..3fb78c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "@types/sinon": "10.0.11", "@types/sinon-chai": "3.2.8", "@types/uuid": "8.3.4", - "@types/vscode": "1.64.0", + "@types/vscode": "1.66.0", "@vscode/test-electron": "2.1.2", "chai": "4.3.6", "cross-env": "7.0.3", @@ -39,7 +39,7 @@ }, "engines": { "node": "^16.11.0", - "vscode": "^1.59.0" + "vscode": "^1.66.0" } }, "node_modules/@babel/code-frame": { @@ -230,9 +230,9 @@ "dev": true }, "node_modules/@types/vscode": { - "version": "1.64.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.64.0.tgz", - "integrity": "sha512-bSlAWz5WtcSL3cO9tAT/KpEH9rv5OBnm93OIIFwdCshaAiqr2bp1AUyEwW9MWeCvZBHEXc3V0fTYVdVyzDNwHA==", + "version": "1.66.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.66.0.tgz", + "integrity": "sha512-ZfJck4M7nrGasfs4A4YbUoxis3Vu24cETw3DERsNYtDZmYSYtk6ljKexKFKhImO/ZmY6ZMsmegu2FPkXoUFImA==", "dev": true }, "node_modules/@ungap/promise-all-settled": { @@ -3368,9 +3368,9 @@ "dev": true }, "@types/vscode": { - "version": "1.64.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.64.0.tgz", - "integrity": "sha512-bSlAWz5WtcSL3cO9tAT/KpEH9rv5OBnm93OIIFwdCshaAiqr2bp1AUyEwW9MWeCvZBHEXc3V0fTYVdVyzDNwHA==", + "version": "1.66.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.66.0.tgz", + "integrity": "sha512-ZfJck4M7nrGasfs4A4YbUoxis3Vu24cETw3DERsNYtDZmYSYtk6ljKexKFKhImO/ZmY6ZMsmegu2FPkXoUFImA==", "dev": true }, "@ungap/promise-all-settled": { diff --git a/package.json b/package.json index d736531..0832db4 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "bugs": "https://github.com/ryanluker/vscode-coverage-gutters/issues", "publisher": "ryanluker", "engines": { - "vscode": "^1.59.0", + "vscode": "^1.66.0", "node": "^16.11.0" }, "categories": [ @@ -130,7 +130,8 @@ "lcov.info", "cov.xml", "coverage.xml", - "jacoco.xml" + "jacoco.xml", + "coverage.cobertura.xml" ], "description": "coverage file names for the extension to automatically look for" }, @@ -264,7 +265,7 @@ "@types/sinon": "10.0.11", "@types/sinon-chai": "3.2.8", "@types/uuid": "8.3.4", - "@types/vscode": "1.64.0", + "@types/vscode": "1.66.0", "@vscode/test-electron": "2.1.2", "chai": "4.3.6", "cross-env": "7.0.3", @@ -283,5 +284,8 @@ "jacoco-parse": "2.0.1", "lcov-parse": "1.0.0", "uuid": "8.3.2" - } + }, + "extensionDependencies": [ + "ms-vscode.live-server" + ] } diff --git a/src/extension/gutters.ts b/src/extension/gutters.ts index 52feef4..d5b4f5a 100644 --- a/src/extension/gutters.ts +++ b/src/extension/gutters.ts @@ -1,9 +1,9 @@ +import { commands, extensions } from "vscode"; import { OutputChannel, window } from "vscode"; import { Coverage } from "../coverage-system/coverage"; import { CoverageService } from "../coverage-system/coverageservice"; import { Config } from "./config"; import { StatusBarToggler } from "./statusbartoggler"; -import { PreviewPanel } from "./webview"; export class Gutters { private coverage: Coverage; @@ -38,8 +38,29 @@ export class Gutters { window.showWarningMessage("Could not show Coverage Report file!"); return; } - const previewPanel = new PreviewPanel(pickedReport); - await previewPanel.createWebView(); + + // TODO: Figure out how to convert pickedReport to a workspace relative filename. + // Right now the livePreview.start.internalPreview.atFile is called with "false" as + // the second parameter. This means that the file specified has an absolute path. + // See the Live Preview extension source code: + // https://github.com/microsoft/vscode-livepreview/blob/ + // 3be1e2eb5c8a7b51aa4a88275ad73bb4d923432b/src/extension.ts#L169 + const livePreview = extensions.getExtension("ms-vscode.live-server"); + // is the ext loaded and ready? + if (livePreview?.isActive === false) { + livePreview.activate().then( + function() { + console.log("Extension activated"); + commands.executeCommand("livePreview.start.internalPreview.atFile", pickedReport, false); + }, + function() { + console.log("Extension activation failed"); + }, + ); + } else { + commands.executeCommand("livePreview.start.internalPreview.atFile", pickedReport, false); + } + } catch (error: any) { this.handleError("previewCoverageReport", error); } diff --git a/src/extension/webview.ts b/src/extension/webview.ts deleted file mode 100644 index 092c62e..0000000 --- a/src/extension/webview.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { - Uri, - ViewColumn, - WebviewPanel, - window, - workspace, -} from "vscode"; - -export class PreviewPanel { - private pickedReport: string; - private previewPanel: WebviewPanel | undefined; - - constructor(pickedReport: string) { - this.pickedReport = pickedReport; - } - - public async createWebView() { - // Read in the report html and send it to the webview - const reportUri = Uri.file(this.pickedReport); - const reportHtml = await workspace.openTextDocument(reportUri); - const reportHtmlWithPolicy = this.addContentSecurityPolicy(reportHtml.getText()); - - // Construct the webview panel for the coverage report to live in - this.previewPanel = window.createWebviewPanel( - "coverageReportPreview", - "Preview Coverage Report", - ViewColumn.One, - ); - - this.previewPanel.webview.html = reportHtmlWithPolicy; - } - - public dispose() { - if (this.previewPanel) { this.previewPanel.dispose(); } - } - - public addContentSecurityPolicy(text: string): string { - const securityPolicyHeader = `\n`; - let tag = text.indexOf(" { + const livePreview = vscode.extensions.getExtension("ms-vscode.live-server"); + expect(livePreview?.isActive).to.equal(true); + }); }); test("Run display coverage on a test file that has coverages generated remotely @integration", async () => { diff --git a/test/extension/webview.test.ts b/test/extension/webview.test.ts deleted file mode 100644 index 85af858..0000000 --- a/test/extension/webview.test.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { expect } from "chai"; -import { PreviewPanel } from "../../src/extension/webview"; - -suite("Preview panel Tests", () => { - test("Should append content security policy to preview HTML when head tag present @unit", () => { - const reportWithHeadTag = ` - - -
-