Skip to content

Commit f4549b9

Browse files
committed
(GH-724) PDK New Module with Native Window Picker
This commit updates the PDK New Module command to use the native window picker instead of asking the user to enter in the fully qualified path. It also opens the newly created module inside the window the command was issued in, instead of opening a new VS Code window. By using the native window picker, we get the correct experience on WIndows, Mac and Linxu. Even inside WSL or even Remote Containers.
1 parent 0a4c75b commit f4549b9

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

src/feature/PDKFeature.ts

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
'use strict';
2-
1+
import * as fs from 'fs';
2+
import * as path from 'path';
33
import * as vscode from 'vscode';
44
import { IFeature } from '../feature';
55
import { ILogger } from '../logging';
@@ -76,31 +76,52 @@ export class PDKFeature implements IFeature {
7676
this.terminal.dispose();
7777
}
7878

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

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);
103+
await new Promise<void>((resolve) => {
104+
let count = 0;
105+
const handle = setInterval(() => {
106+
count++;
107+
if (count >= 30) {
108+
clearInterval(handle);
109+
resolve();
110+
return;
102111
}
103-
});
112+
113+
if (fs.existsSync(p)) {
114+
resolve();
115+
return;
116+
}
117+
}, 1000);
104118
});
119+
120+
const uri = vscode.Uri.file(p);
121+
await vscode.commands.executeCommand('vscode.openFolder', uri);
122+
123+
if (reporter) {
124+
reporter.sendTelemetryEvent(PDKCommandStrings.PdkNewModuleCommandId);
125+
}
105126
}
106127
}

0 commit comments

Comments
 (0)