Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ConstrainedLanguage mode #1269

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
polish ConstrainedLanguage mode
  • Loading branch information
TylerLeonhardt committed Apr 23, 2020
commit c82c4627e45eb1a43ea3670c99f804226b497c99
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function Clear-Host {
param()

__clearhost
$psEditor.Window.Terminal.Clear()
if ($host.Runspace.LanguageMode -eq [System.Management.Automation.PSLanguageMode]::FullLanguage) {
$psEditor.Window.Terminal.Clear()
}
}

if (!$IsMacOS -or $IsLinux) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public EditorServicesConfig(
public ProfilePathConfig ProfilePaths { get; set; }

/// <summary>
/// The language mode of the original runspace that we will inherit from.
/// The language mode inherited from the orginal PowerShell process.
/// This will be used when creating runspaces so that we honor the same language mode.
/// </summary>
public PSLanguageMode LanguageMode { get; internal set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ private HostStartupInfo CreateHostStartupInfo()
profilePaths,
_config.FeatureFlags,
_config.AdditionalModules,
_config.LogPath,
_config.LanguageMode,
_config.LogPath,
(int)_config.LogLevel,
consoleReplEnabled: _config.ConsoleRepl != ConsoleReplKind.None,
usesLegacyReadLine: _config.ConsoleRepl == ConsoleReplKind.LegacyReadLine);
Expand Down
8 changes: 5 additions & 3 deletions src/PowerShellEditorServices/Hosting/HostStartupInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public sealed class HostStartupInfo
public string LogPath { get; }

/// <summary>
/// The language mode of the original runspace that we will inherit from.
/// The language mode inherited from the orginal PowerShell process.
/// This will be used when creating runspaces so that we honor the same language mode.
/// </summary>
public PSLanguageMode LanguageMode { get; }

Expand Down Expand Up @@ -123,6 +124,7 @@ public sealed class HostStartupInfo
/// <param name="currentUsersProfilePath">The path to the user specific profile.</param>
/// <param name="featureFlags">Flags of features to enable.</param>
/// <param name="additionalModules">Names or paths of additional modules to import.</param>
/// <param name="languageMode">The language mode inherited from the orginal PowerShell process. This will be used when creating runspaces so that we honor the same language mode.</param>
/// <param name="logPath">The path to log to.</param>
/// <param name="logLevel">The minimum log event level.</param>
/// <param name="consoleReplEnabled">Enable console if true.</param>
Expand All @@ -135,8 +137,8 @@ public HostStartupInfo(
ProfilePathInfo profilePaths,
IReadOnlyList<string> featureFlags,
IReadOnlyList<string> additionalModules,
string logPath,
PSLanguageMode languageMode,
string logPath,
int logLevel,
bool consoleReplEnabled,
bool usesLegacyReadLine)
Expand All @@ -148,8 +150,8 @@ public HostStartupInfo(
ProfilePaths = profilePaths;
FeatureFlags = featureFlags ?? Array.Empty<string>();
AdditionalModules = additionalModules ?? Array.Empty<string>();
LogPath = logPath;
LanguageMode = languageMode;
LogPath = logPath;
LogLevel = logLevel;
ConsoleReplEnabled = consoleReplEnabled;
UsesLegacyReadLine = usesLegacyReadLine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ public static PowerShellContextService Create(
/// </summary>
/// <param name="hostDetails"></param>
/// <param name="powerShellContext"></param>
/// <param name="hostUserInterface">
/// The EditorServicesPSHostUserInterface to use for this instance.
/// </param>
/// <param name="hostUserInterface">The EditorServicesPSHostUserInterface to use for this instance.</param>
/// <param name="logger">An ILogger implementation to use for this instance.</param>
/// <returns></returns>
public static Runspace CreateRunspace(
Expand All @@ -266,7 +264,8 @@ public static Runspace CreateRunspace(
/// <summary>
///
/// </summary>
/// <param name="psHost"></param>
/// <param name="psHost">The PSHost that will be used for this Runspace.</param>
/// <param name="languageMode">The language mode inherited from the orginal PowerShell process. This will be used when creating runspaces so that we honor the same language mode.</param>
/// <returns></returns>
public static Runspace CreateRunspace(PSHost psHost, PSLanguageMode languageMode)
{
Expand All @@ -277,8 +276,9 @@ public static Runspace CreateRunspace(PSHost psHost, PSLanguageMode languageMode
initialSessionState = InitialSessionState.CreateDefault2();
}

// Create and initialize a new Runspace while honoring the LanguageMode.
Console.WriteLine(languageMode);
// Create and initialize a new Runspace while honoring the LanguageMode of the original runspace
// that started PowerShell Editor Services. This is because the PowerShell Integrated Console
// should have the same LanguageMode of whatever is set by the system.
initialSessionState.LanguageMode = languageMode;
TylerLeonhardt marked this conversation as resolved.
Show resolved Hide resolved

Runspace runspace = RunspaceFactory.CreateRunspace(psHost, initialSessionState);
Expand Down Expand Up @@ -414,6 +414,8 @@ public void Initialize(

if (powerShellVersion.Major >= 5 &&
this.isPSReadLineEnabled &&
// TODO: Figure out why PSReadLine isn't working in ConstrainedLanguage mode.
initialRunspace.SessionStateProxy.LanguageMode == PSLanguageMode.FullLanguage &&
PSReadLinePromptContext.TryGetPSReadLineProxy(logger, initialRunspace, out PSReadLineProxy proxy))
{
this.PromptContext = new PSReadLinePromptContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public static PowerShellContextService Create(ILogger logger)
TestProfilePaths,
new List<string>(),
new List<string>(),
null,
PSLanguageMode.FullLanguage,
null,
0,
consoleReplEnabled: false,
usesLegacyReadLine: false);
Expand Down