Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Run and Debug buttons to Spec Explorer #700

Merged
merged 4 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 35 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description": "Gauge support for VScode.",
"author": "ThoughtWorks",
"license": "MIT",
"version": "0.0.20",
"version": "0.0.21",
"publisher": "getgauge",
"engines": {
"vscode": "^1.59.0"
Expand Down Expand Up @@ -115,6 +115,18 @@
"dark": "resources/dark/play.svg"
}
},
{
"command": "gauge.specexplorer.runNode",
"title": "Run",
"category": "Gauge",
"icon": "$(debug-start)"
},
{
"command": "gauge.specexplorer.debugNode",
"title": "Debug",
"category": "Gauge",
"icon": "$(bug)"
},
{
"command": "gauge.execute.scenario",
"title": "Run Scenario",
Expand Down Expand Up @@ -148,7 +160,7 @@
},
{
"command": "gauge.specexplorer.switchProject",
"when": "false"
"when": "config.noExists"
},
{
"command": "gauge.execute.repeat",
Expand Down Expand Up @@ -192,7 +204,15 @@
},
{
"command": "gauge.specexplorer.runAllActiveProjectSpecs",
"when": "false"
"when": "config.noExists"
},
{
"command": "gauge.specexplorer.runNode",
"when": "config.noExists"
},
{
"command": "gauge.specexplorer.debugNode",
"when": "config.noExists"
}
],
"view/title": [
Expand All @@ -206,6 +226,18 @@
"when": "view == gauge:specExplorer",
"group": "navigation"
}
],
"view/item/context": [
{
"command": "gauge.specexplorer.runNode",
"when": "view == gauge:specExplorer",
"group": "inline"
},
{
"command": "gauge.specexplorer.debugNode",
"when": "view == gauge:specExplorer",
"group": "inline"
}
]
},
"configuration": {
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export enum GaugeVSCodeCommands {
ExecuteSpec = 'gauge.execute.specification',
ExecuteAllSpecs = 'gauge.execute.specification.all',
ExecuteAllSpecExplorer = 'gauge.specexplorer.runAllActiveProjectSpecs',
ExecuteNode = 'gauge.specexplorer.runNode',
DebugNode = 'gauge.specexplorer.debugNode',
ExecuteScenario = 'gauge.execute.scenario',
ExecuteScenarios = 'gauge.execute.scenarios',
GenerateStepStub = 'gauge.generate.step',
Expand Down
6 changes: 3 additions & 3 deletions src/execution/debug.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import getPort = require('get-port');
import { debug, DebugSession, window, workspace } from 'vscode';
import { debug, DebugSession, Uri, workspace } from 'vscode';
import { GaugeRunners } from '../constants';
import { GaugeClients } from '../gaugeClients';
import { ExecutionConfig } from './executionConfig';
Expand Down Expand Up @@ -135,8 +135,8 @@ export class GaugeDebugger {

public startDebugger() {
return new Promise((res, rej) => {
let folder = workspace.getWorkspaceFolder(window.activeTextEditor.document.uri);
let root = this.clientsMap.get(window.activeTextEditor.document.uri.fsPath).project.root();
const root = this.config.getProject().root();
const folder = workspace.getWorkspaceFolder(Uri.parse(root));
if (!folder) {
throw new Error(`The debugger does not work for a stand alone file. Please open the folder ${root}.`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/execution/lineProcessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class DebuggerAttachedEventProcessor extends BaseProcessor {
public process(lineText: string, gaugeDebugger: GaugeDebugger): void {
if (!this.canProcess(lineText)) return;
gaugeDebugger.addProcessId(+lineText.replace(/^\D+/g, ''));
gaugeDebugger.startDebugger().catch((reason) => {
window.showErrorMessage(reason);
gaugeDebugger.startDebugger().catch(error => {
window.showErrorMessage(`Failed to start debugger: ${error.message}`);
this.executor.cancel(false);
});
}
Expand Down
16 changes: 15 additions & 1 deletion src/explorer/specExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,21 @@ export class SpecNodeProvider extends Disposable implements vscode.TreeDataProvi
}),
commands.registerCommand(GaugeVSCodeCommands.Open,
(node: GaugeNode) => workspace.openTextDocument(node.file)
.then(this.showDocumentWithSelection(node)))
.then(this.showDocumentWithSelection(node))),

commands.registerCommand(GaugeVSCodeCommands.ExecuteNode, (node: GaugeNode) =>
this.gaugeWorkspace.getGaugeExecutor().execute(
node instanceof Scenario ? node.executionIdentifier : node.file,
new ExecutionConfig().setStatus(node.file)
.setProject(this.gaugeWorkspace.getClientsMap().get(node.file).project))
),

commands.registerCommand(GaugeVSCodeCommands.DebugNode, (node: GaugeNode) =>
this.gaugeWorkspace.getGaugeExecutor().execute(
node instanceof Scenario ? node.executionIdentifier : node.file,
new ExecutionConfig().setStatus(node.file).setDebug()
.setProject(this.gaugeWorkspace.getClientsMap().get(node.file).project))
)
);
}
}
Expand Down