From f0f0604d5a82128f43391cbbeb1ae6a04e3ec932 Mon Sep 17 00:00:00 2001 From: lyyyuna Date: Wed, 2 Sep 2020 15:35:03 +0800 Subject: [PATCH] add extension readme --- tools/vscode-ext/CHANGELOG.md | 2 +- tools/vscode-ext/README.md | 45 +++++++++++++++++++++++++++++-- tools/vscode-ext/package.json | 2 +- tools/vscode-ext/src/extension.ts | 6 +++++ tools/vscode-ext/src/gocserver.ts | 11 +++++++- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/tools/vscode-ext/CHANGELOG.md b/tools/vscode-ext/CHANGELOG.md index 3f7025b..c1f6904 100644 --- a/tools/vscode-ext/CHANGELOG.md +++ b/tools/vscode-ext/CHANGELOG.md @@ -4,6 +4,6 @@ All notable changes to the "goc" extension will be documented in this file. Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. -## [Unreleased] +## 0.0.3 2020-09-02 - Initial release \ No newline at end of file diff --git a/tools/vscode-ext/README.md b/tools/vscode-ext/README.md index 55ad541..d2e1b2a 100644 --- a/tools/vscode-ext/README.md +++ b/tools/vscode-ext/README.md @@ -1,3 +1,44 @@ -# Goc Coverage README +# Goc Coverage -**Enjoy!** +This extension provides rich support for the [goc](https://github.com/qiniu/goc) tool. + +## Overview + +* [Getting started](#getting-started) +* [Ask for help](#ask-for-help) + +## Getting started + +Welcome! The [goc](https://github.com/qiniu/goc) is a coverage tool for Golang projects. The most interesting part of [goc](https://github.com/qiniu/goc) is that it can generate coverage report while the service is running! You can test the service manually or automatically, whatever, you don't have to stop the tested service to get the coverage report anymore. + +This extension provides a frontend to show the covered lines in real time. + +### Basic requirements + +Before you started, make sure that you have: + +1. Go +2. [goc](https://github.com/qiniu/goc) +3. source code of the tested service + +### Set up your environment + +Follow the [goc example](https://github.com/qiniu/goc#examples) guide to build and start the tested service. After you finished this step, there should be a **goc server** running at default port `7777`. + +Use `vscode` to open the source code. Make sure the vscode's `workspace` is in the Golang project's root directory. If your project uses `go module`, just open vscode in the repo's directory. If your project uses `GOPATH`, you should setup right `GOPATH` before you open vscode. + +Open any Go source files, you should see a `Goc Coverage OFF` button in the bottom status bar, click on the button to enable rendering covered lines in real time. + +### Configuration + +#### goc server url + +If you deploy the goc server on another host with a customized port, you can set: + +``` +"goc.serverUrl": "http://192.168.1.3:51234" +``` + +## Ask for help + +If you're having issues with this extension, please reach out to us by [filing an issue](https://github.com/qiniu/goc/issues/new/choose) directly. \ No newline at end of file diff --git a/tools/vscode-ext/package.json b/tools/vscode-ext/package.json index 4757c37..d5b92d7 100644 --- a/tools/vscode-ext/package.json +++ b/tools/vscode-ext/package.json @@ -2,7 +2,7 @@ "name": "goc", "displayName": "Goc Coverage", "description": "Goc Coverage can display coverage vairation in real time. Goc is a comprehensive coverage testing system for The Go Programming Language, especially for some complex scenarios, like system testing code coverage collection and accurate testing.", - "version": "0.0.1", + "version": "0.0.3", "publisher": "lyyyuna", "repository": { "url": "https://github.com/qiniu/goc" diff --git a/tools/vscode-ext/src/extension.ts b/tools/vscode-ext/src/extension.ts index 250e514..5304cd6 100644 --- a/tools/vscode-ext/src/extension.ts +++ b/tools/vscode-ext/src/extension.ts @@ -16,6 +16,12 @@ export function activate(context: vscode.ExtensionContext) { let disposable2 = vscode.commands.registerCommand('extension.switch', async () => { if (gocStatusBarItem.text == 'Goc Coverage OFF') { + let err = gocserver.checkGoEnv() + // check if pc meets extension's requirement + if (err) { + vscode.window.showErrorMessage('Cannot get Golang version, please check your go environment.') + return + } gocStatusBarItem.text = 'Goc Coverage ON'; // get current project package structure let packages = gocserver.getGoList(); diff --git a/tools/vscode-ext/src/gocserver.ts b/tools/vscode-ext/src/gocserver.ts index 9840654..e57eff2 100644 --- a/tools/vscode-ext/src/gocserver.ts +++ b/tools/vscode-ext/src/gocserver.ts @@ -67,6 +67,15 @@ export class GocServer { return ""; } + checkGoEnv() : Boolean { + let output = spawnSync('go', ['version']); + if (output.status != 0 || output.status == null) { + console.error(output.stderr.toString()) + return true; + } + return false; + } + getGoList(): Array { let cwd = ""; let workspaces = vscode.workspace.workspaceFolders || []; @@ -80,7 +89,7 @@ export class GocServer { 'cwd': cwd }; let output = spawnSync('go', ['list', '-json', './...'], opts); - if (output.error != null) { + if (output.status != 0 || output.status == null) { console.error(output.stderr.toString()); return []; }