Skip to content

Commit df295ec

Browse files
Fix prerelease version discovery and fix omnisharp change (#1073)
1 parent aa38ae8 commit df295ec

File tree

7 files changed

+29
-26
lines changed

7 files changed

+29
-26
lines changed

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public async Task StartAsync()
7474
_additionalModules))
7575
.ConfigureLogging(builder => builder
7676
.AddSerilog(Log.Logger)
77+
.AddLanguageServer(LogLevel.Trace)
7778
.SetMinimumLevel(LogLevel.Trace))
78-
.AddDefaultLoggingProvider()
7979
.WithHandler<WorkspaceSymbolsHandler>()
8080
.WithHandler<TextDocumentHandler>()
8181
.WithHandler<GetVersionHandler>()

src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public ReferencesCodeLensProvider(WorkspaceService workspaceService, SymbolsServ
4545
_workspaceService = workspaceService;
4646
_symbolsService = symbolsService;
4747
// TODO: Pull this from components
48-
_symbolProvider = new ScriptDocumentSymbolProvider(
49-
VersionUtils.PSVersion);
48+
_symbolProvider = new ScriptDocumentSymbolProvider();
5049
}
5150

5251
/// <summary>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Task<PowerShellVersion> Handle(GetVersionParams request, CancellationToke
3939

4040
return Task.FromResult(new PowerShellVersion
4141
{
42-
Version = VersionUtils.PSVersion.ToString(),
42+
Version = VersionUtils.PSVersionString,
4343
Edition = VersionUtils.PSEdition,
4444
DisplayVersion = VersionUtils.PSVersion.ToString(2),
4545
Architecture = architecture.ToString()

src/PowerShellEditorServices/Services/Symbols/ScriptDocumentSymbolProvider.cs

+2-17
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols
1717
/// </summary>
1818
public class ScriptDocumentSymbolProvider : IDocumentSymbolProvider
1919
{
20-
private Version powerShellVersion;
21-
22-
/// <summary>
23-
/// Creates an instance of the ScriptDocumentSymbolProvider to
24-
/// target the specified PowerShell version.
25-
/// </summary>
26-
/// <param name="powerShellVersion">The target PowerShell version.</param>
27-
public ScriptDocumentSymbolProvider(Version powerShellVersion)
28-
{
29-
this.powerShellVersion = powerShellVersion;
30-
}
31-
3220
IEnumerable<SymbolReference> IDocumentSymbolProvider.ProvideDocumentSymbols(
3321
ScriptFile scriptFile)
3422
{
@@ -37,10 +25,7 @@ IEnumerable<SymbolReference> IDocumentSymbolProvider.ProvideDocumentSymbols(
3725
(scriptFile.FilePath.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase) ||
3826
scriptFile.FilePath.EndsWith(".psm1", StringComparison.OrdinalIgnoreCase)))
3927
{
40-
return
41-
FindSymbolsInDocument(
42-
scriptFile.ScriptAst,
43-
this.powerShellVersion);
28+
return FindSymbolsInDocument(scriptFile.ScriptAst);
4429
}
4530

4631
return Enumerable.Empty<SymbolReference>();
@@ -52,7 +37,7 @@ IEnumerable<SymbolReference> IDocumentSymbolProvider.ProvideDocumentSymbols(
5237
/// <param name="scriptAst">The abstract syntax tree of the given script</param>
5338
/// <param name="powerShellVersion">The PowerShell version the Ast was generated from</param>
5439
/// <returns>A collection of SymbolReference objects</returns>
55-
static public IEnumerable<SymbolReference> FindSymbolsInDocument(Ast scriptAst, Version powerShellVersion)
40+
static public IEnumerable<SymbolReference> FindSymbolsInDocument(Ast scriptAst)
5641
{
5742
IEnumerable<SymbolReference> symbolReferences = null;
5843

src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public SymbolsService(
5454
_workspaceService = workspaceService;
5555
_documentSymbolProviders = new IDocumentSymbolProvider[]
5656
{
57-
new ScriptDocumentSymbolProvider(VersionUtils.PSVersion),
57+
new ScriptDocumentSymbolProvider(),
5858
new PsdDocumentSymbolProvider(),
5959
new PesterDocumentSymbolProvider()
6060
};

src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public DocumentSymbolHandler(ILoggerFactory factory, ConfigurationService config
4444
_workspaceService = workspaceService;
4545
_providers = new IDocumentSymbolProvider[]
4646
{
47-
new ScriptDocumentSymbolProvider(
48-
VersionUtils.PSVersion),
47+
new ScriptDocumentSymbolProvider(),
4948
new PsdDocumentSymbolProvider(),
5049
new PesterDocumentSymbolProvider()
5150
};

src/PowerShellEditorServices/Utility/VersionUtils.cs

+22-2
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,20 @@ internal static class VersionUtils
2020
public static bool IsNetCore { get; } = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.Ordinal);
2121

2222
/// <summary>
23-
/// Get's the Version of PowerShell being used.
23+
/// Gets the Version of PowerShell being used.
2424
/// </summary>
2525
public static Version PSVersion { get; } = PowerShellReflectionUtils.PSVersion;
2626

2727
/// <summary>
28-
/// Get's the Edition of PowerShell being used.
28+
/// Gets the Edition of PowerShell being used.
2929
/// </summary>
3030
public static string PSEdition { get; } = PowerShellReflectionUtils.PSEdition;
3131

32+
/// <summary>
33+
/// Gets the string of the PSVersion including prerelease tags if it applies.
34+
/// </summary>
35+
public static string PSVersionString { get; } = PowerShellReflectionUtils.PSVersionString;
36+
3237
/// <summary>
3338
/// True if we are running in Windows PowerShell, false otherwise.
3439
/// </summary>
@@ -49,8 +54,16 @@ internal static class PowerShellReflectionUtils
4954
{
5055

5156
private static readonly Type s_psVersionInfoType = typeof(System.Management.Automation.Runspaces.Runspace).Assembly.GetType("System.Management.Automation.PSVersionInfo");
57+
58+
// This property is a Version type in PowerShell. It's existed since 5.1, but it was only made public in 6.2.
5259
private static readonly PropertyInfo s_psVersionProperty = s_psVersionInfoType
5360
.GetProperty("PSVersion", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
61+
62+
// This property is a SemanticVersion in PowerShell that contains the prerelease tag as well.
63+
// It was added in 6.2 so we can't depend on it for anything before.
64+
private static readonly PropertyInfo s_psCurrentVersionProperty = s_psVersionInfoType
65+
.GetProperty("PSCurrentVersion", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
66+
5467
private static readonly PropertyInfo s_psEditionProperty = s_psVersionInfoType
5568
.GetProperty("PSEdition", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
5669

@@ -64,5 +77,12 @@ internal static class PowerShellReflectionUtils
6477
/// Get's the Edition of PowerShell being used.
6578
/// </summary>
6679
public static string PSEdition { get; } = s_psEditionProperty.GetValue(null) as string;
80+
81+
/// <summary>
82+
/// Gets the stringified version of PowerShell including prerelease tags if it applies.
83+
/// </summary>
84+
public static string PSVersionString { get; } = s_psCurrentVersionProperty != null
85+
? s_psCurrentVersionProperty.GetValue(null).ToString()
86+
: s_psVersionProperty.GetValue(null).ToString();
6787
}
6888
}

0 commit comments

Comments
 (0)