Skip to content

Commit 1df5286

Browse files
daxian-dbwAmro Khalil
authored andcommitted
Revert "Never load a module targeting the PSReadLine module's SessionState" (PowerShell#25792)
The change causes nested modules of PSReadLine to be loaded to global session state as well. It's possible to check if we are currently importing the PSReadLine module but the check would depend on the current design of the PSReadLine module, such as how many nested modules it has, its module type, and etc., which is fragile. It's safer to just revert the change.
1 parent f8eab14 commit 1df5286

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,17 @@ protected internal struct ImportModuleOptions
136136

137137
internal SessionState TargetSessionState
138138
{
139-
// Module loading could happen during tab completion triggered by PSReadLine,
140-
// but that doesn't mean the module should be loaded targeting the PSReadLine
141-
// module's session state. In that case, use Global session state instead.
142-
get => BaseGlobal || Context.EngineSessionState.Module?.Name is "PSReadLine"
143-
? Context.TopLevelSessionState.PublicSessionState
144-
: Context.SessionState;
139+
get
140+
{
141+
if (BaseGlobal)
142+
{
143+
return this.Context.TopLevelSessionState.PublicSessionState;
144+
}
145+
else
146+
{
147+
return this.Context.SessionState;
148+
}
149+
}
145150
}
146151

147152
/// <summary>

0 commit comments

Comments
 (0)