Skip to content

Commit 5f9cfd6

Browse files
committed
Apply bundledModulesPath setting only when in development mode
This change improves our handling of the bundledModulesPath setting by only making it active when VS Code is in development mode (either running in the debugger or with the --extensionDevelopmentPath setting). This enables extension developers to use their installed PowerShell extension's bundled modules in normal circumstances, only switching to the bundledModulesPath when they are running a development build. This code also sets the default bundledModulesPath to a peer (co-located) PowerShellEditorServices folder since most developers will probably clone the two repos into the same folder. One would only need to set their bundledModulesPath if their PSES repo folder was in an unconventional path. The bundledModulesPath setting will likely be renamed to something more appropriate in the next update.
1 parent 3d9319b commit 5f9cfd6

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@
323323
},
324324
"powershell.developer.bundledModulesPath": {
325325
"type": "string",
326-
"default": "../modules/",
327326
"description": "Specifies the path to the folder containing modules that are bundled with the PowerShell extension (i.e. PowerShell Editor Services, PowerShell Script Analyzer, Plaster)"
328327
},
329328
"powershell.developer.editorServicesLogLevel": {

src/session.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ export class SessionManager {
7272
private languageServerClient: LanguageClient = undefined;
7373
private sessionSettings: Settings.ISettings = undefined;
7474

75+
// When in development mode, VS Code's session ID is a fake
76+
// value of "someValue.machineId". Use that to detect dev
77+
// mode for now until Microsoft/vscode#10272 gets implemented.
78+
private readonly inDevelopmentMode =
79+
vscode.env.sessionId === "someValue.sessionId";
80+
7581
constructor(
7682
private requiredEditorServicesVersion: string,
7783
private log: Logger,
@@ -100,9 +106,24 @@ export class SessionManager {
100106
if (this.sessionConfiguration.type === SessionType.UsePath ||
101107
this.sessionConfiguration.type === SessionType.UseBuiltIn) {
102108

103-
var bundledModulesPath = this.sessionSettings.developer.bundledModulesPath;
104-
if (!path.isAbsolute(bundledModulesPath)) {
105-
bundledModulesPath = path.resolve(__dirname, bundledModulesPath);
109+
var bundledModulesPath = path.resolve(__dirname, "../modules");
110+
111+
if (this.inDevelopmentMode) {
112+
var devBundledModulesPath =
113+
// this.sessionSettings.developer.bundledModulesPath ||
114+
path.resolve(
115+
__dirname,
116+
this.sessionSettings.developer.bundledModulesPath ||
117+
"../../PowerShellEditorServices/module");
118+
119+
// Make sure the module's bin path exists
120+
if (fs.existsSync(path.join(devBundledModulesPath, "PowerShellEditorServices/bin"))) {
121+
bundledModulesPath = devBundledModulesPath;
122+
}
123+
else {
124+
this.log.write(
125+
`\nWARNING: In development mode but PowerShellEditorServices dev module path cannot be found (or has not been built yet): ${devBundledModulesPath}\n`);
126+
}
106127
}
107128

108129
var startArgs =

src/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function load(myPluginId: string): ISettings {
4242

4343
let defaultDeveloperSettings: IDeveloperSettings = {
4444
powerShellExePath: undefined,
45-
bundledModulesPath: "../modules/",
45+
bundledModulesPath: undefined,
4646
editorServicesLogLevel: "Normal",
4747
editorServicesWaitForDebugger: false,
4848
powerShellExeIsWindowsDevBuild: false

0 commit comments

Comments
 (0)