Revert "Never load a module targeting the PSReadLine module's SessionState" (#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.
This commit is contained in:
Dongbo Wang
2025-07-29 14:32:21 -07:00
committed by GitHub
parent ce76ae1def
commit b801027560
@@ -136,12 +136,17 @@ namespace Microsoft.PowerShell.Commands
internal SessionState TargetSessionState
{
// Module loading could happen during tab completion triggered by PSReadLine,
// but that doesn't mean the module should be loaded targeting the PSReadLine
// module's session state. In that case, use Global session state instead.
get => BaseGlobal || Context.EngineSessionState.Module?.Name is "PSReadLine"
? Context.TopLevelSessionState.PublicSessionState
: Context.SessionState;
get
{
if (BaseGlobal)
{
return this.Context.TopLevelSessionState.PublicSessionState;
}
else
{
return this.Context.SessionState;
}
}
}
/// <summary>