Skip to content

Commit 73a4c7d

Browse files
feat: question-link (#67)
1 parent 24b624c commit 73a4c7d

File tree

12 files changed

+84
-7
lines changed

12 files changed

+84
-7
lines changed

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "code-snippet",
3-
"version": "0.0.25",
3+
"version": "0.0.26",
44
"displayName": "Code Snippet",
55
"publisher": "SAPOSS",
66
"author": {

backend/src/app-events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface AppEvents {
44
doApply(we: vscode.WorkspaceEdit): Promise<any>;
55
doSnippeDone(success: boolean, message: string, targetFolderPath?: string): void;
66
doClose(): void;
7+
executeCommand(id: string, ...args: any[]): Thenable<any>;
78
}

backend/src/code-snippet.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class CodeSnippet {
4141
this.rpc.registerMethod({ func: this.toggleOutput, thisArg: this });
4242
this.rpc.registerMethod({ func: this.logError, thisArg: this });
4343
this.rpc.registerMethod({ func: this.getState, thisArg: this });
44+
this.rpc.registerMethod({ func: this.executeCommand, thisArg: this });
4445

4546
this.promptCount = 0;
4647
this.currentQuestions = {};
@@ -71,6 +72,10 @@ export class CodeSnippet {
7172
entry.set(methodName, handler);
7273
}
7374

75+
private executeCommand(id: string, ...args: any[]): void {
76+
this.appEvents.executeCommand(id, ...args);
77+
}
78+
7479
private async logError(error: any, prefixMessage?: string) {
7580
let errorMessage = this.getErrorInfo(error);
7681
if (prefixMessage) {

backend/src/vscode-events.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class VSCodeEvents implements AppEvents {
2727
}
2828
}
2929

30+
public executeCommand(id: string, ...args: any[]): Thenable<any> {
31+
return vscode.commands.executeCommand(id, ...args);
32+
}
33+
3034
private showDoneMessage(success: boolean, message: string, targetFolderPath?: string): Thenable<any> {
3135

3236
if (success) {

backend/src/webSocketServer/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ function createCodeSnippetQuestions(): any[] {
7979
},
8080
{
8181
guiOptions: {
82-
hint: "hint actionType"
82+
hint: "hint actionType",
83+
link: {
84+
text: "Open Global Settings",
85+
command: {
86+
id: "workbench.action.openGlobalSettings",
87+
}
88+
}
8389
},
8490
type: "list",
8591
name: "actionType",

backend/src/webSocketServer/server-events.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export class ServerEvents implements AppEvents {
1616
this.rpc.invoke("snippetDone", [suceeded, message, targetPath]);
1717
}
1818

19+
executeCommand(id: string, ...args: any[]): Thenable<any> {
20+
return;
21+
}
22+
1923
public doClose(): void {
2024
return;
2125
}

backend/tests/code-snippet.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ describe('codeSnippet unit test', () => {
2929
public doClose(): void {
3030
return;
3131
}
32+
public executeCommand(command: string, ...rest: any[]): Thenable<any> {
33+
return;
34+
}
3235
}
3336
class TestRpc implements IRpc {
3437
public timeout: number;
@@ -281,6 +284,16 @@ describe('codeSnippet unit test', () => {
281284
});
282285
});
283286

287+
describe("executeCommand", () => {
288+
it("called with command id & args", async () => {
289+
const commandId = "vscode.open";
290+
const commandArgs = [ { fsPath: "https://en.wikipedia.org"} ];
291+
appEventsMock.expects("executeCommand").withExactArgs(commandId, commandArgs);
292+
await codeSnippet["executeCommand"](commandId, commandArgs);
293+
});
294+
295+
});
296+
284297
describe("Custom Question Event Handlers", () => {
285298
it("addCustomQuestionEventHandlers()", async () => {
286299
const testEventFunction = () => {

backend/tests/vscode-events.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,11 @@ describe('vscode-events unit test', () => {
8787

8888
});
8989

90+
it("executeCommand", () => {
91+
const commandId = "vscode.open";
92+
const commandArgs = [vscode.Uri.file("https://en.wikipedia.org")];
93+
commandsMock.expects("executeCommand").withExactArgs(commandId, commandArgs).resolves();
94+
events.executeCommand(commandId, commandArgs);
95+
});
96+
9097
});

frontend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code-snippet-frontend",
33
"displayName": "Code Snippet Frontend",
4-
"version": "0.0.4",
4+
"version": "0.0.5",
55
"publisher": "SAP",
66
"license": "Apache 2.0",
77
"description": "Frontend for the Code Snippet framework",
@@ -16,7 +16,7 @@
1616
},
1717
"dependencies": {
1818
"@mdi/font": "^5.1.45",
19-
"@sap-devx/inquirer-gui": "0.1.19",
19+
"@sap-devx/inquirer-gui": "0.1.25",
2020
"@sap-devx/inquirer-gui-file-browser-plugin": "0.0.5",
2121
"@sap-devx/inquirer-gui-folder-browser-plugin": "0.0.3",
2222
"@sap-devx/inquirer-gui-login-plugin": "0.0.4",

frontend/src/App.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<Form
2727
ref="form"
2828
:questions="currentPrompt ? currentPrompt.questions : []"
29+
@parentExecuteCommand="executeCommand"
2930
@answered="onAnswered"
3031
/>
3132
</v-slide-x-transition>
@@ -155,6 +156,11 @@ export default {
155156
this.resolve(this.currentPrompt.answers);
156157
}
157158
},
159+
executeCommand(event) {
160+
const command = event.target.getAttribute("command");
161+
const params = event.target.getAttribute("params");
162+
this.rpc.invoke("executeCommand", [command, params]);
163+
},
158164
onAnswered(answers, issues) {
159165
this.stepValidated = issues === undefined;
160166
const currentPrompt = this.currentPrompt;

0 commit comments

Comments
 (0)