Skip to content

Commit 75a58fb

Browse files
move to helper function and only run on Windows PowerShell
1 parent e7a7cfd commit 75a58fb

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetVersionHandler.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ internal class GetVersionHandler : IGetVersionHandler
2424
private readonly ILogger<GetVersionHandler> _logger;
2525
private readonly PowerShellContextService _powerShellContextService;
2626
private readonly ILanguageServer _languageServer;
27+
private readonly ConfigurationService _configurationService;
2728

28-
public GetVersionHandler(ILoggerFactory factory, PowerShellContextService powerShellContextService, ILanguageServer languageServer)
29+
public GetVersionHandler(
30+
ILoggerFactory factory,
31+
PowerShellContextService powerShellContextService,
32+
ILanguageServer languageServer,
33+
ConfigurationService configurationService)
2934
{
3035
_logger = factory.CreateLogger<GetVersionHandler>();
3136
_powerShellContextService = powerShellContextService;
3237
_languageServer = languageServer;
38+
_configurationService = configurationService;
3339
}
3440

3541
public async Task<PowerShellVersion> Handle(GetVersionParams request, CancellationToken cancellationToken)
@@ -49,6 +55,29 @@ public async Task<PowerShellVersion> Handle(GetVersionParams request, Cancellati
4955
}
5056
}
5157

58+
if (VersionUtils.IsPS5 && _configurationService.CurrentSettings.PromptToUpdatePackageManagement)
59+
{
60+
await CheckPackageManagement();
61+
}
62+
63+
return new PowerShellVersion
64+
{
65+
Version = VersionUtils.PSVersionString,
66+
Edition = VersionUtils.PSEdition,
67+
DisplayVersion = VersionUtils.PSVersion.ToString(2),
68+
Architecture = architecture.ToString()
69+
};
70+
}
71+
72+
private enum PowerShellProcessArchitecture
73+
{
74+
Unknown,
75+
X86,
76+
X64
77+
}
78+
79+
private async Task CheckPackageManagement()
80+
{
5281
PSCommand getModule = new PSCommand().AddCommand("Get-Module").AddParameter("ListAvailable").AddParameter("Name", "PackageManagement");
5382
foreach (PSModuleInfo module in await _powerShellContextService.ExecuteCommandAsync<PSModuleInfo>(getModule))
5483
{
@@ -117,21 +146,6 @@ public async Task<PowerShellVersion> Handle(GetVersionParams request, Cancellati
117146
}
118147
}
119148
}
120-
121-
return new PowerShellVersion
122-
{
123-
Version = VersionUtils.PSVersionString,
124-
Edition = VersionUtils.PSEdition,
125-
DisplayVersion = VersionUtils.PSVersion.ToString(2),
126-
Architecture = architecture.ToString()
127-
};
128-
}
129-
130-
private enum PowerShellProcessArchitecture
131-
{
132-
Unknown,
133-
X86,
134-
X64
135149
}
136150
}
137151
}

src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ internal class LanguageServerSettings
2020
private readonly object updateLock = new object();
2121
public bool EnableProfileLoading { get; set; }
2222

23+
public bool PromptToUpdatePackageManagement { get; set; }
24+
2325
public ScriptAnalysisSettings ScriptAnalysis { get; set; }
2426

2527
public CodeFormattingSettings CodeFormatting { get; set; }
@@ -46,6 +48,7 @@ public void Update(
4648
lock (updateLock)
4749
{
4850
this.EnableProfileLoading = settings.EnableProfileLoading;
51+
this.PromptToUpdatePackageManagement = settings.PromptToUpdatePackageManagement;
4952
this.ScriptAnalysis.Update(
5053
settings.ScriptAnalysis,
5154
workspaceRootPath,

0 commit comments

Comments
 (0)