Skip to content

Commit a1882b8

Browse files
authored
Merge pull request PowerShell#15 from TylerLeonhardt/add-workspacesymbolshandler
add dummy workspace symbols handler
2 parents fd2f3c8 + bcc803f commit a1882b8

File tree

5 files changed

+167
-12
lines changed

5 files changed

+167
-12
lines changed

PowerShellEditorServices.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellEditorServices.Te
2828
EndProject
2929
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellEditorServices.VSCode", "src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj", "{3B38E8DA-8BFF-4264-AF16-47929E6398A3}"
3030
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerShellEditorServices.Engine", "src\PowerShellEditorServices.Engine\PowerShellEditorServices.Engine.csproj", "{29EEDF03-0990-45F4-846E-2616970D1FA2}"
32+
EndProject
3133
Global
3234
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3335
Debug|Any CPU = Debug|Any CPU
@@ -134,6 +136,18 @@ Global
134136
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|x64.Build.0 = Release|Any CPU
135137
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|x86.ActiveCfg = Release|Any CPU
136138
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|x86.Build.0 = Release|Any CPU
139+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
140+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
141+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|x64.ActiveCfg = Debug|Any CPU
142+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|x64.Build.0 = Debug|Any CPU
143+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|x86.ActiveCfg = Debug|Any CPU
144+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|x86.Build.0 = Debug|Any CPU
145+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
146+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|Any CPU.Build.0 = Release|Any CPU
147+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x64.ActiveCfg = Release|Any CPU
148+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x64.Build.0 = Release|Any CPU
149+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x86.ActiveCfg = Release|Any CPU
150+
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x86.Build.0 = Release|Any CPU
137151
EndGlobalSection
138152
GlobalSection(SolutionProperties) = preSolution
139153
HideSolutionNode = FALSE
@@ -147,5 +161,6 @@ Global
147161
{F8A0946A-5D25-4651-8079-B8D5776916FB} = {F594E7FD-1E72-4E51-A496-B019C2BA3180}
148162
{E3A5CF5D-6E41-44AC-AE0A-4C227E4BACD4} = {422E561A-8118-4BE7-A54F-9309E4F03AAE}
149163
{3B38E8DA-8BFF-4264-AF16-47929E6398A3} = {F594E7FD-1E72-4E51-A496-B019C2BA3180}
164+
{29EEDF03-0990-45F4-846E-2616970D1FA2} = {F594E7FD-1E72-4E51-A496-B019C2BA3180}
150165
EndGlobalSection
151166
EndGlobal

src/PowerShellEditorServices.Engine/Hosting/EditorServicesHost.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
//
55

66
using System;
7-
using System.Collections.Generic;
87
using System.Diagnostics;
9-
using System.IO;
108
using System.Linq;
119
using System.Management.Automation;
1210
using System.Management.Automation.Host;
1311
using System.Reflection;
1412
using System.Runtime.InteropServices;
13+
using System.Threading;
1514
using System.Threading.Tasks;
1615
using Microsoft.Extensions.DependencyInjection;
1716
using Microsoft.Extensions.Logging;
1817
using Serilog;
19-
using Serilog.Extensions.Logging;
2018

2119
namespace Microsoft.PowerShell.EditorServices.Engine
2220
{
@@ -64,7 +62,9 @@ public class EditorServicesHost
6462

6563
private ILanguageServer _languageServer;
6664

67-
private Extensions.Logging.ILogger _logger;
65+
private readonly Extensions.Logging.ILogger _logger;
66+
67+
private readonly ILoggerFactory _factory;
6868

6969
#endregion
7070

@@ -130,10 +130,8 @@ public EditorServicesHost(
130130
Log.Logger = new LoggerConfiguration().Enrich.FromLogContext()
131131
.WriteTo.Console()
132132
.CreateLogger();
133-
134-
_logger = new SerilogLoggerProvider().CreateLogger(nameof(EditorServicesHost));
135-
136-
_serviceCollection.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true));
133+
_factory = new LoggerFactory().AddSerilog(Log.Logger);
134+
_logger = _factory.CreateLogger<EditorServicesHost>();
137135

138136
_hostDetails = hostDetails;
139137

@@ -231,12 +229,16 @@ public void StartLanguageService(
231229
{
232230
NamedPipeName = config.InOutPipeName ?? config.InPipeName,
233231
OutNamedPipeName = config.OutPipeName,
232+
LoggerFactory = _factory
234233
}
235234
.BuildLanguageServer();
236235

237236
_logger.LogInformation("Starting language server");
238237

239-
Task.Run(_languageServer.StartAsync);
238+
Task.Factory.StartNew(() => _languageServer.StartAsync(),
239+
CancellationToken.None,
240+
TaskCreationOptions.LongRunning,
241+
TaskScheduler.Default);
240242

241243
_logger.LogInformation(
242244
string.Format(

src/PowerShellEditorServices.Engine/LanguageServer/OmnisharpLanguageServer.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Microsoft.Extensions.Logging;
77
using OS = OmniSharp.Extensions.LanguageServer.Server;
88
using System.Security.AccessControl;
9+
using OmniSharp.Extensions.LanguageServer.Server;
10+
using PowerShellEditorServices.Engine.Services.Workspace.Handlers;
911

1012
namespace Microsoft.PowerShell.EditorServices.Engine
1113
{
@@ -61,14 +63,14 @@ public async Task StartAsync()
6163
}
6264

6365
options.Input = namedPipe;
64-
options.Output = outNamedPipe != null
65-
? outNamedPipe
66-
: namedPipe;
66+
options.Output = outNamedPipe ?? namedPipe;
6767

6868
options.LoggerFactory = _configuration.LoggerFactory;
6969
options.MinimumLogLevel = _configuration.MinimumLogLevel;
7070
options.Services = _configuration.Services;
71+
options.WithHandler<WorkspaceSymbolsHandler>();
7172
});
73+
7274
_serverStart.SetResult(true);
7375
}
7476

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Microsoft.Extensions.Logging;
7+
using Microsoft.PowerShell.EditorServices;
8+
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
9+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
10+
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
11+
12+
namespace PowerShellEditorServices.Engine.Services.Workspace.Handlers
13+
{
14+
public class WorkspaceSymbolsHandler : IWorkspaceSymbolsHandler
15+
{
16+
private readonly ILogger _logger;
17+
18+
public WorkspaceSymbolsHandler(ILoggerFactory loggerFactory) {
19+
_logger = loggerFactory.CreateLogger<WorkspaceSymbolsHandler>();
20+
}
21+
22+
public object GetRegistrationOptions()
23+
{
24+
return null;
25+
// throw new NotImplementedException();
26+
}
27+
28+
public Task<SymbolInformationContainer> Handle(WorkspaceSymbolParams request, CancellationToken cancellationToken)
29+
{
30+
var symbols = new List<SymbolInformation>();
31+
32+
// foreach (ScriptFile scriptFile in editorSession.Workspace.GetOpenedFiles())
33+
// {
34+
// FindOccurrencesResult foundSymbols =
35+
// editorSession.LanguageService.FindSymbolsInFile(
36+
// scriptFile);
37+
38+
// // TODO: Need to compute a relative path that is based on common path for all workspace files
39+
// string containerName = Path.GetFileNameWithoutExtension(scriptFile.FilePath);
40+
41+
// if (foundSymbols != null)
42+
// {
43+
// foreach (SymbolReference foundOccurrence in foundSymbols.FoundOccurrences)
44+
// {
45+
// if (!IsQueryMatch(request.Query, foundOccurrence.SymbolName))
46+
// {
47+
// continue;
48+
// }
49+
50+
// var location = new Location
51+
// {
52+
// Uri = GetFileUri(foundOccurrence.FilePath),
53+
// Range = GetRangeFromScriptRegion(foundOccurrence.ScriptRegion)
54+
// };
55+
56+
// symbols.Add(new SymbolInformation
57+
// {
58+
// ContainerName = containerName,
59+
// Kind = foundOccurrence.SymbolType == SymbolType.Variable ? SymbolKind.Variable : SymbolKind.Function,
60+
// Location = location,
61+
// Name = GetDecoratedSymbolName(foundOccurrence)
62+
// });
63+
// }
64+
// }
65+
// }
66+
_logger.LogWarning("Logging in a handler works now.");
67+
68+
return Task.FromResult(new SymbolInformationContainer(symbols));
69+
}
70+
71+
public void SetCapability(WorkspaceSymbolCapability capability)
72+
{
73+
// throw new NotImplementedException();
74+
}
75+
76+
#region private Methods
77+
78+
// private bool IsQueryMatch(string query, string symbolName)
79+
// {
80+
// return symbolName.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0;
81+
// }
82+
83+
// private static string GetFileUri(string filePath)
84+
// {
85+
// // If the file isn't untitled, return a URI-style path
86+
// return
87+
// !filePath.StartsWith("untitled") && !filePath.StartsWith("inmemory")
88+
// ? new Uri("file://" + filePath).AbsoluteUri
89+
// : filePath;
90+
// }
91+
92+
// private static Range GetRangeFromScriptRegion(ScriptRegion scriptRegion)
93+
// {
94+
// return new Range
95+
// {
96+
// Start = new Position
97+
// {
98+
// Line = scriptRegion.StartLineNumber - 1,
99+
// Character = scriptRegion.StartColumnNumber - 1
100+
// },
101+
// End = new Position
102+
// {
103+
// Line = scriptRegion.EndLineNumber - 1,
104+
// Character = scriptRegion.EndColumnNumber - 1
105+
// }
106+
// };
107+
// }
108+
109+
// private static string GetDecoratedSymbolName(SymbolReference symbolReference)
110+
// {
111+
// string name = symbolReference.SymbolName;
112+
113+
// if (symbolReference.SymbolType == SymbolType.Configuration ||
114+
// symbolReference.SymbolType == SymbolType.Function ||
115+
// symbolReference.SymbolType == SymbolType.Workflow)
116+
// {
117+
// name += " { }";
118+
// }
119+
120+
// return name;
121+
// }
122+
123+
#endregion
124+
}
125+
}

test/Pester/EditorServices.Integration.Tests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ Describe "Loading and running PowerShellEditorServices" {
7878
#ReportLogErrors -LogPath $psesServer.LogPath -FromIndex ([ref]$logIdx)
7979
}
8080

81+
It "Can handle WorkspaceSymbol request" {
82+
$request = Send-LspRequest -Client $client -Method "workspace/symbol" -Parameters @{
83+
query = ""
84+
}
85+
$response = Get-LspResponse -Client $client -Id $request.Id #-WaitMillis 99999
86+
$response.Id | Should -BeExactly $request.Id
87+
CheckErrorResponse -Response $response
88+
89+
# ReportLogErrors -LogPath $psesServer.LogPath -FromIndex ([ref]$logIdx)
90+
}
91+
8192
# This test MUST be last
8293
It "Shuts down the process properly" {
8394
$request = Send-LspShutdownRequest -Client $client

0 commit comments

Comments
 (0)