Skip to content

Feature/constrained runspace support #1282

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

Closed
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7bf0f35
Modified previous ConstrainedLanguage changes to support spawning run…
dkattan May 3, 2020
e50beb5
Removed unused code for creating ConstrainedRunspace
dkattan May 3, 2020
e7e2bfe
Updated PowerShellContextFactory.cs to not specify a LanguageMode and…
dkattan May 3, 2020
0dc040e
Removed unnecessary changes.
dkattan May 3, 2020
bbbcd07
Fixed compilation error.
dkattan May 4, 2020
6d425d2
Created internal overload for CreateRunspace that accepts InitialSess…
dkattan May 8, 2020
fd0e360
Removed comment
dkattan May 8, 2020
0548349
Modified previous ConstrainedLanguage changes to support spawning run…
dkattan May 3, 2020
8af273c
Removed unused code for creating ConstrainedRunspace
dkattan May 3, 2020
fecc78f
Removed unnecessary changes.
dkattan May 3, 2020
d418d26
Fixed compilation error.
dkattan May 4, 2020
46f2324
Created internal overload for CreateRunspace that accepts InitialSess…
dkattan May 8, 2020
a8753ee
Removed comment
dkattan May 8, 2020
d7ea74e
This works in a constrained runspace, but performance poor as PSES co…
dkattan Jun 1, 2020
79f4b8c
Added null check for profile when loaded from a Constrained Runspace
dkattan Jun 2, 2020
6c7da2b
Added default TabExpansion2 implementation so PSES works out of the b…
dkattan Jun 2, 2020
18dd6df
Merge remote-tracking branch 'upstream/master' into feature/constrain…
dkattan Jun 2, 2020
3ba1f4e
Added Default InitialSessionState to test suite
dkattan Jun 2, 2020
8866896
Merged latest changes from upstream.
dkattan May 21, 2021
db87496
Modified code to work from a Constrained Runspace.
dkattan Jun 2, 2021
99854df
Got modules to load as expected in Constrained Runspace by switching …
dkattan Jun 3, 2021
7111814
Removed reference to local profile
dkattan Jun 7, 2021
bdd993c
Removed BuildInfo.cs
dkattan Jun 18, 2021
1f738a6
Revert "Removed BuildInfo.cs"
dkattan Jun 18, 2021
bce3396
Undoing changes to BuildInfo.cs
dkattan Jun 18, 2021
124bd95
Undoing changes to BuildInfo.cs
dkattan Jun 18, 2021
9309e27
Copied BuildInfo.cs from master
dkattan Jun 18, 2021
74013af
Copied BuildInfo.cs from master
dkattan Jun 18, 2021
1fad2d0
Merge branch 'feature/constrained-runspace-support' of github.com:dka…
dkattan Jun 18, 2021
54196a8
Added comment indicating the purpose of the InitialSessionState varia…
dkattan Jun 18, 2021
87b94c9
Removed profile null check changes as those are done differently in P…
dkattan Jun 18, 2021
c697af8
Adding comments, removing unnecessary changes.
dkattan Jun 18, 2021
b893e08
Removing more unnecessary changes
dkattan Jun 18, 2021
e281448
Removing unintentional changes
dkattan Jun 18, 2021
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
2 changes: 1 addition & 1 deletion src/PowerShellEditorServices.Hosting/BuildInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public static class BuildInfo
// TODO: Include a Git commit hash in this.
public static readonly string BuildVersion = "<development-build>";
public static readonly string BuildOrigin = "<development>";
public static readonly System.DateTime? BuildTime = System.DateTime.Parse("2019-12-06T21:43:41", CultureInfo.InvariantCulture.DateTimeFormat);
public static readonly System.DateTime? BuildTime = System.DateTime.Parse("2020-05-03T16:39:35", CultureInfo.InvariantCulture.DateTimeFormat);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert this? The build is supposed to mark this with git to not change... But it's not always worked.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ private EditorServicesConfig CreateConfigObject()
var profile = (PSObject)GetVariableValue("profile");

var hostInfo = new HostInfo(HostName, HostProfileId, HostVersion);
var initialSessionState = Runspace.DefaultRunspace.InitialSessionState;
var editorServicesConfig = new EditorServicesConfig(hostInfo, Host, SessionDetailsPath, bundledModulesPath, LogPath)
{
FeatureFlags = FeatureFlags,
Expand All @@ -357,15 +358,20 @@ private EditorServicesConfig CreateConfigObject()
AdditionalModules = AdditionalModules,
LanguageServiceTransport = GetLanguageServiceTransport(),
DebugServiceTransport = GetDebugServiceTransport(),
LanguageMode = Runspace.DefaultRunspace.SessionStateProxy.LanguageMode,
ProfilePaths = new ProfilePathConfig
InitialSessionState = initialSessionState,

};

if(profile != null)
{
editorServicesConfig.ProfilePaths = new ProfilePathConfig
{
AllUsersAllHosts = GetProfilePathFromProfileObject(profile, ProfileUserKind.AllUsers, ProfileHostKind.AllHosts),
AllUsersCurrentHost = GetProfilePathFromProfileObject(profile, ProfileUserKind.AllUsers, ProfileHostKind.CurrentHost),
CurrentUserAllHosts = GetProfilePathFromProfileObject(profile, ProfileUserKind.CurrentUser, ProfileHostKind.AllHosts),
CurrentUserCurrentHost = GetProfilePathFromProfileObject(profile, ProfileUserKind.CurrentUser, ProfileHostKind.CurrentHost),
},
};
};
}

if (StartupBanner != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;

namespace Microsoft.PowerShell.EditorServices.Hosting
{
Expand Down Expand Up @@ -111,10 +112,9 @@ public EditorServicesConfig(
public ProfilePathConfig ProfilePaths { get; set; }

/// <summary>
/// The language mode inherited from the orginal PowerShell process.
/// This will be used when creating runspaces so that we honor the same language mode.
/// The InitialSessionState to use when creating runspaces. LanguageMode can be set here.
/// </summary>
public PSLanguageMode LanguageMode { get; internal set; }
public InitialSessionState InitialSessionState { get; internal set; }

public string StartupBanner { get; set; } = @"

Expand Down
9 changes: 8 additions & 1 deletion src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SMA = System.Management.Automation;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Linq;

#if CoreCLR
using System.Runtime.Loader;
Expand Down Expand Up @@ -255,9 +256,15 @@ private void UpdatePSModulePath()
}

string psModulePath = Environment.GetEnvironmentVariable("PSModulePath").TrimEnd(Path.PathSeparator);
string[] psModulePaths = psModulePath.Split(Path.PathSeparator);
if (psModulePaths.Any(a => a == _hostConfig.BundledModulePath))
{
_logger.Log(PsesLogLevel.Verbose, $"PSModulePath already contains '{_hostConfig.BundledModulePath}'");
return;
}

psModulePath = $"{psModulePath}{Path.PathSeparator}{_hostConfig.BundledModulePath}";
Environment.SetEnvironmentVariable("PSModulePath", psModulePath);

_logger.Log(PsesLogLevel.Verbose, $"Updated PSModulePath to: '{psModulePath}'");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private HostStartupInfo CreateHostStartupInfo()
profilePaths,
_config.FeatureFlags,
_config.AdditionalModules,
_config.LanguageMode,
_config.InitialSessionState,
_config.LogPath,
(int)_config.LogLevel,
consoleReplEnabled: _config.ConsoleRepl != ConsoleReplKind.None,
Expand Down
13 changes: 7 additions & 6 deletions src/PowerShellEditorServices/Hosting/HostStartupInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;

namespace Microsoft.PowerShell.EditorServices.Hosting
{
Expand Down Expand Up @@ -92,10 +93,10 @@ public sealed class HostStartupInfo
public string LogPath { get; }

/// <summary>
/// The language mode inherited from the orginal PowerShell process.
/// This will be used when creating runspaces so that we honor the same language mode.
/// The initialSessionState will be inherited from the orginal PowerShell process.
/// This will be used when creating runspaces so that we honor the same initialSessionState including allowed modules, cmdlets and language mode.
/// </summary>
public PSLanguageMode LanguageMode { get; }
public InitialSessionState InitialSessionState { get; }

/// <summary>
/// The minimum log level of log events to be logged.
Expand Down Expand Up @@ -130,7 +131,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="initialSessionState">The language mode inherited from the orginal PowerShell process. This will be used when creating runspaces so that we honor the same initialSessionState including allowed modules, cmdlets and 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 @@ -143,7 +144,7 @@ public HostStartupInfo(
ProfilePathInfo profilePaths,
IReadOnlyList<string> featureFlags,
IReadOnlyList<string> additionalModules,
PSLanguageMode languageMode,
InitialSessionState initialSessionState,
string logPath,
int logLevel,
bool consoleReplEnabled,
Expand All @@ -156,7 +157,7 @@ public HostStartupInfo(
ProfilePaths = profilePaths;
FeatureFlags = featureFlags ?? Array.Empty<string>();
AdditionalModules = additionalModules ?? Array.Empty<string>();
LanguageMode = languageMode;
InitialSessionState = initialSessionState;
LogPath = logPath;
LogLevel = logLevel;
ConsoleReplEnabled = consoleReplEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
</ItemGroup>

<ItemGroup>
<Compile Remove="Extensions\Api\DocumentSymbolService.cs"/>
<Compile Remove="Extensions\Api\DocumentSymbolService.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ private async Task DelayThenInvokeDiagnosticsAsync(ScriptFile[] filesToAnalyze,

foreach (ScriptFile scriptFile in filesToAnalyze)
{
if (string.IsNullOrWhiteSpace(scriptFile.Contents))
continue;
ScriptFileMarker[] semanticMarkers = await AnalysisEngine.AnalyzeScriptAsync(scriptFile.Contents).ConfigureAwait(false);

scriptFile.DiagnosticMarkers.AddRange(semanticMarkers);
Expand Down
Loading