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 all 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
8 changes: 5 additions & 3 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ task SetupDotNet -Before Clean, Build, TestServerWinPS, TestServerPS7, TestServe
$dotnetExePath = if ($script:IsNix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" }

if (!(Test-Path $dotnetExePath)) {
# TODO: Test .NET 5 with PowerShell 7.1, and add that channel here.
Install-Dotnet -Channel '3.1','release/6.0.1xx-preview2'
# TODO: Test .NET 5 with PowerShell 7.1
Install-Dotnet -Channel '3.1','5.0','6.0'
}

# This variable is used internally by 'dotnet' to know where it's installed
Expand Down Expand Up @@ -174,6 +174,7 @@ task GetProductVersion -Before PackageModule, UploadArtifacts {
task CreateBuildInfo -Before Build {
$buildVersion = "<development-build>"
$buildOrigin = "Development"
$buildCommit = git rev-parse HEAD

# Set build info fields on build platforms
if ($env:TF_BUILD) {
Expand Down Expand Up @@ -215,6 +216,7 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
{
public static readonly string BuildVersion = "$buildVersion";
public static readonly string BuildOrigin = "$buildOrigin";
public static readonly string BuildCommit = "$buildCommit";
public static readonly System.DateTime? BuildTime = System.DateTime.Parse("$buildTime", CultureInfo.InvariantCulture.DateTimeFormat);
}
}
Expand Down Expand Up @@ -446,4 +448,4 @@ task UploadArtifacts -If ($null -ne $env:TF_BUILD) {
}

# The default task is to run the entire CI build
task . GetProductVersion, Clean, Build, Test, BuildCmdletHelp, PackageModule, UploadArtifacts
task . GetProductVersion, Clean, Build, Test, BuildCmdletHelp, PackageModule, UploadArtifacts
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ if ($Bootstrap) {
if($Test) {
Invoke-Build Test
}
}
}
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,7 +358,7 @@ private EditorServicesConfig CreateConfigObject()
AdditionalModules = AdditionalModules,
LanguageServiceTransport = GetLanguageServiceTransport(),
DebugServiceTransport = GetDebugServiceTransport(),
LanguageMode = Runspace.DefaultRunspace.SessionStateProxy.LanguageMode,
InitialSessionState = initialSessionState,
ProfilePaths = new ProfilePathConfig
{
AllUsersAllHosts = GetProfilePathFromProfileObject(profile, ProfileUserKind.AllUsers, ProfileHostKind.AllHosts),
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
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ private void LogHostInformation()
== Build Details ==
- Editor Services version: {BuildInfo.BuildVersion}
- Build origin: {BuildInfo.BuildOrigin}
- Build commit: {BuildInfo.BuildCommit}
- Build time: {BuildInfo.BuildTime}
");

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
19 changes: 10 additions & 9 deletions src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal static string GetUniqueIdFromDiagnostic(Diagnostic diagnostic)

private readonly ConfigurationService _configurationService;

private readonly WorkspaceService _workplaceService;
private readonly WorkspaceService _workspaceService;

private readonly int _analysisDelayMillis;

Expand Down Expand Up @@ -115,7 +115,7 @@ public AnalysisService(
_logger = loggerFactory.CreateLogger<AnalysisService>();
_languageServer = languageServer;
_configurationService = configurationService;
_workplaceService = workspaceService;
_workspaceService = workspaceService;
_analysisDelayMillis = 750;
_mostRecentCorrectionsByFile = new ConcurrentDictionary<ScriptFile, CorrectionTableEntry>();
_analysisEngineLazy = new Lazy<PssaCmdletAnalysisEngine>(InstantiateAnalysisEngine);
Expand Down Expand Up @@ -223,9 +223,10 @@ public async Task<string> GetCommentHelpText(string functionText, string helpLoc
/// </summary>
/// <param name="documentUri">The URI string of the file to get code actions for.</param>
/// <returns>A threadsafe readonly dictionary of the code actions of the particular file.</returns>
public async Task<IReadOnlyDictionary<string, MarkerCorrection>> GetMostRecentCodeActionsForFileAsync(ScriptFile scriptFile)
public async Task<IReadOnlyDictionary<string, MarkerCorrection>> GetMostRecentCodeActionsForFileAsync(DocumentUri uri)
{
if (!_mostRecentCorrectionsByFile.TryGetValue(scriptFile, out CorrectionTableEntry corrections))
if (!_workspaceService.TryGetFile(uri, out ScriptFile file)
|| !_mostRecentCorrectionsByFile.TryGetValue(file, out CorrectionTableEntry corrections))
{
return null;
}
Expand Down Expand Up @@ -334,7 +335,7 @@ private bool TryFindSettingsFile(out string settingsFilePath)
return false;
}

settingsFilePath = _workplaceService.ResolveWorkspacePath(configuredPath);
settingsFilePath = _workspaceService.ResolveWorkspacePath(configuredPath);

if (settingsFilePath == null
|| !File.Exists(settingsFilePath))
Expand All @@ -349,7 +350,7 @@ private bool TryFindSettingsFile(out string settingsFilePath)

private void ClearOpenFileMarkers()
{
foreach (ScriptFile file in _workplaceService.GetOpenedFiles())
foreach (ScriptFile file in _workspaceService.GetOpenedFiles())
{
ClearMarkers(file);
}
Expand Down Expand Up @@ -455,10 +456,10 @@ private static DiagnosticSeverity MapDiagnosticSeverity(ScriptFileMarkerLevel ma
{
switch (markerLevel)
{
case ScriptFileMarkerLevel.Error: return DiagnosticSeverity.Error;
case ScriptFileMarkerLevel.Warning: return DiagnosticSeverity.Warning;
case ScriptFileMarkerLevel.Error: return DiagnosticSeverity.Error;
case ScriptFileMarkerLevel.Warning: return DiagnosticSeverity.Warning;
case ScriptFileMarkerLevel.Information: return DiagnosticSeverity.Information;
default: return DiagnosticSeverity.Error;
default: return DiagnosticSeverity.Error;
};
}

Expand Down
Loading