Skip to content

Commit a55cdd4

Browse files
committed
(GH-684) Fix pdk new module activation
This fixes a bug when a user tries to use the 'PDK new Module' button in a VS Code window that is empty or has no workspace open. This bug was introduced when the Puppetfile view was added and did not properly catch this error case.
1 parent eea61a7 commit a55cdd4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/extension.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ export function activate(context: vscode.ExtensionContext) {
6969
pdkVersion: configSettings.ruby.pdkVersion,
7070
});
7171

72-
const puppetfile = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, 'Puppetfile');
73-
const exists = fs.existsSync(puppetfile);
74-
if (exists && configSettings.workspace.editorService.enable) {
75-
vscode.commands.executeCommand('setContext', 'puppet:puppetfileEnabled', true);
72+
const workspaceFolders = vscode.workspace.workspaceFolders;
73+
if (workspaceFolders) {
74+
const currentWorkspaceFolder = workspaceFolders[0];
75+
const puppetfile = path.join(currentWorkspaceFolder.uri.fsPath, 'Puppetfile');
76+
const exists = fs.existsSync(puppetfile);
77+
if (exists && configSettings.workspace.editorService.enable) {
78+
vscode.commands.executeCommand('setContext', 'puppet:puppetfileEnabled', true);
79+
}
7680
}
7781

7882
const statusBar = new PuppetStatusBarFeature([puppetLangID, puppetFileLangID], configSettings, logger, context);

0 commit comments

Comments
 (0)