Skip to content

Commit

Permalink
populate test explorer with response from gauge, #42
Browse files Browse the repository at this point in the history
  • Loading branch information
sriv committed Dec 4, 2017
1 parent 2f93ac7 commit a83f6d4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

"javascript.validate.enable": false,

"eslint.enable": false,
"eslint.enable": true,
"tslint.enable": false
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
"views": {
"explorer": [
{
"id": "gaugeSpecs",
"name": "Gauge Specs"
"id": "gauge:testExplorer",
"name": "Gauge Specs",
"when": "gauge:activated"
}
]
},
Expand Down
19 changes: 19 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

import { commands } from 'vscode';

export enum VSCodeCommands {
Open = 'vscode.open',
SetContext = 'setContext',
ShowReferences = 'editor.action.showReferences'
}

export enum GaugeCommandContext {
Enabled = 'gauge:enabled',
Activated = 'gauge:activated',
GaugeTestExplorer = 'gauge:testExplorer',
}

export function setCommandContext(key: GaugeCommandContext | string, value: any) {
return commands.executeCommand(VSCodeCommands.SetContext, key, value);
}
29 changes: 19 additions & 10 deletions src/explorer/specExplorer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
import { LanguageClient, TextDocumentIdentifier } from 'vscode-languageclient';

export class SpecNodeProvider implements vscode.TreeDataProvider<GaugeNode> {

private _onDidChangeTreeData: vscode.EventEmitter<Spec | undefined> = new vscode.EventEmitter<Spec | undefined>();
readonly onDidChangeTreeData: vscode.Event<Spec | undefined> = this._onDidChangeTreeData.event;

constructor(private workspaceRoot: string) {
constructor(private workspaceRoot: string, private languageClient: LanguageClient) {
}

refresh(): void {
Expand All @@ -24,17 +25,21 @@ export class SpecNodeProvider implements vscode.TreeDataProvider<GaugeNode> {
return Promise.resolve([]);
}

return new Promise(resolve => {
return new Promise((resolve,reject) => {
if (element && element.contextValue==="specification") {
resolve([
new Scenario(element.label+"scn1", ""),
new Scenario(element.label+"scn1", "")
]);
let uri = TextDocumentIdentifier.create(element.file);
return this.languageClient.sendRequest("gauge/scenarios", { textDocument: uri, position: new vscode.Position(1,1) }, new vscode.CancellationTokenSource().token).then(
(val: any[]) => {
resolve(val.map(x => new Scenario(x.heading, x.executionIdentifier)));
},
(reason) => {console.log(reason);reject(reason)}
);
} else {
resolve([
new Spec("foo", ""),
new Spec("bar", "")
]);
return this.languageClient.sendRequest("gauge/specs", {}, new vscode.CancellationTokenSource().token).then(
(val: any[]) => {
resolve(val.map(x => new Spec(x.heading, x.executionIdentifier)));
}
);
}
});
}
Expand Down Expand Up @@ -66,6 +71,8 @@ class Spec extends GaugeNode {
};

contextValue = 'specification';

command= {title:'Open File', command: 'vscode.window.open', args: {uri: this.file}}
}

class Scenario extends GaugeNode {
Expand All @@ -83,4 +90,6 @@ class Scenario extends GaugeNode {
};

contextValue = 'scenario';

command= {title:'Open File', command: 'vscode.window.showTextDocument', args: {uri: this.file}}
}
19 changes: 17 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import opn = require('opn');
import copyPaste = require('copy-paste');
import { execute, runScenario, runSpecification } from "./execution/gaugeExecution";
import { SpecNodeProvider } from './explorer/specExplorer'
import * as gaugeCommands from './commands'

const DEBUG_LOG_LEVEL_CONFIG = 'enableDebugLogs';
const GAUGE_LAUNCH_CONFIG = 'gauge.launch';
Expand Down Expand Up @@ -69,8 +70,22 @@ export function activate(context: ExtensionContext) {
context.subscriptions.push(onConfigurationChange());
context.subscriptions.push(disposable);

const specNodeProvider = new SpecNodeProvider(vscode.workspace.rootPath);
const specNodeProvider = new SpecNodeProvider(vscode.workspace.rootPath, languageClient);
vscode.window.registerTreeDataProvider('gaugeSpecs', specNodeProvider);
languageClient.onReady().then(
() => {
let treeDataProvider = vscode.window.registerTreeDataProvider(gaugeCommands.GaugeCommandContext.GaugeTestExplorer, new SpecNodeProvider(vscode.workspace.rootPath, languageClient));
context.subscriptions.push(treeDataProvider);
setTimeout(gaugeCommands.setCommandContext, 1000, gaugeCommands.GaugeCommandContext.Activated, true);
}
);

return {
extendMarkdownIt(md) {
md.options.html = false;
return md;
}
}
}

function reportIssue(gaugeVersion: cp.SpawnSyncReturns<string>) {
Expand Down Expand Up @@ -107,7 +122,7 @@ function showStepReferencesAtCursor(languageClient: LanguageClient): () => Thena

function showReferences(locations: LSLocation[], uri: string, languageClient: LanguageClient, position: LSPosition): Thenable<any> {
if (locations) {
return vscode.commands.executeCommand('editor.action.showReferences', Uri.parse(uri), languageClient.protocol2CodeConverter.asPosition(position),
return vscode.commands.executeCommand(gaugeCommands.VSCodeCommands.ShowReferences, Uri.parse(uri), languageClient.protocol2CodeConverter.asPosition(position),
locations.map(languageClient.protocol2CodeConverter.asLocation));
}
vscode.window.showInformationMessage('No reference found!');
Expand Down

0 comments on commit a83f6d4

Please sign in to comment.