Skip to content

Commit 4572db7

Browse files
authored
Merge pull request #724 from jpogran/pdk-new-module-native-window
(GH-724) PDK New Module with Native window
2 parents 0a4c75b + 65800eb commit 4572db7

File tree

1 file changed

+60
-41
lines changed

1 file changed

+60
-41
lines changed

src/feature/PDKFeature.ts

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
import * as fs from 'fs';
4+
import * as path from 'path';
35
import * as vscode from 'vscode';
46
import { IFeature } from '../feature';
57
import { ILogger } from '../logging';
@@ -47,25 +49,21 @@ export class PDKFeature implements IFeature {
4749
{ id: 'extension.pdkNewDefinedType', request: 'pdk new defined_type', type: 'Puppet defined_type' },
4850
].forEach((command) => {
4951
context.subscriptions.push(
50-
vscode.commands.registerCommand(command.id, () => {
51-
const nameOpts: vscode.QuickPickOptions = {
52-
placeHolder: `Enter a name for the new ${command.type}`,
53-
matchOnDescription: true,
54-
matchOnDetail: true,
55-
};
56-
57-
vscode.window.showInputBox(nameOpts).then((name) => {
58-
if (name === undefined) {
59-
vscode.window.showWarningMessage(`No ${command.type} value specifed. Exiting.`);
60-
return;
61-
}
62-
const request = `${command.request} ${name}`;
63-
this.terminal.sendText(request);
64-
this.terminal.show();
65-
if (reporter) {
66-
reporter.sendTelemetryEvent(command.id);
67-
}
52+
vscode.commands.registerCommand(command.id, async () => {
53+
const name = await vscode.window.showInputBox({
54+
prompt: `Enter a name for the new ${command.type}`,
6855
});
56+
if (name === undefined) {
57+
vscode.window.showWarningMessage('No module name specifed. Exiting.');
58+
return;
59+
}
60+
61+
const request = `${command.request} ${name}`;
62+
this.terminal.sendText(request);
63+
this.terminal.show();
64+
if (reporter) {
65+
reporter.sendTelemetryEvent(command.id);
66+
}
6967
}),
7068
);
7169
logger.debug(`Registered ${command.id} command`);
@@ -76,31 +74,52 @@ export class PDKFeature implements IFeature {
7674
this.terminal.dispose();
7775
}
7876

79-
private pdkNewModuleCommand(): void {
80-
const nameOpts: vscode.QuickPickOptions = {
81-
placeHolder: 'Enter a name for the new Puppet module',
82-
matchOnDescription: true,
83-
matchOnDetail: true,
84-
};
85-
const dirOpts: vscode.QuickPickOptions = {
86-
placeHolder: 'Enter a path for the new Puppet module',
87-
matchOnDescription: true,
88-
matchOnDetail: true,
89-
};
77+
private async pdkNewModuleCommand(): Promise<void> {
78+
const name = await vscode.window.showInputBox({
79+
prompt: 'Enter a name for the new Puppet module',
80+
});
81+
if (name === undefined) {
82+
vscode.window.showWarningMessage('No module name specifed. Exiting.');
83+
return;
84+
}
85+
const directory = await vscode.window.showOpenDialog({
86+
canSelectMany: false,
87+
canSelectFiles: false,
88+
canSelectFolders: true,
89+
openLabel: 'Choose the path for the new Puppet module',
90+
});
91+
if (directory === undefined) {
92+
vscode.window.showWarningMessage('No directory specifed. Exiting.');
93+
return;
94+
}
95+
96+
const p = path.join(directory[0].fsPath, name);
97+
98+
this.terminal.sendText(`pdk new module --skip-interview ${name} ${p}`);
99+
this.terminal.show();
90100

91-
vscode.window.showInputBox(nameOpts).then((moduleName) => {
92-
if (moduleName === undefined) {
93-
vscode.window.showWarningMessage('No module name specifed. Exiting.');
94-
return;
95-
}
96-
vscode.window.showInputBox(dirOpts).then((dir) => {
97-
this.terminal.sendText(`pdk new module --skip-interview ${moduleName} ${dir}`);
98-
this.terminal.sendText(`code ${dir}`);
99-
this.terminal.show();
100-
if (reporter) {
101-
reporter.sendTelemetryEvent(PDKCommandStrings.PdkNewModuleCommandId);
101+
await new Promise<void>((resolve) => {
102+
let count = 0;
103+
const handle = setInterval(() => {
104+
count++;
105+
if (count >= 30) {
106+
clearInterval(handle);
107+
resolve();
108+
return;
102109
}
103-
});
110+
111+
if (fs.existsSync(p)) {
112+
resolve();
113+
return;
114+
}
115+
}, 1000);
104116
});
117+
118+
const uri = vscode.Uri.file(p);
119+
await vscode.commands.executeCommand('vscode.openFolder', uri);
120+
121+
if (reporter) {
122+
reporter.sendTelemetryEvent(PDKCommandStrings.PdkNewModuleCommandId);
123+
}
105124
}
106125
}

0 commit comments

Comments
 (0)