Skip to content

Commit

Permalink
Merge pull request PowerShell#15 from TylerLeonhardt/add-workspacesym…
Browse files Browse the repository at this point in the history
…bolshandler

add dummy workspace symbols handler
  • Loading branch information
rjmholt authored Jul 9, 2019
2 parents fd2f3c8 + bcc803f commit a1882b8
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 12 deletions.
15 changes: 15 additions & 0 deletions PowerShellEditorServices.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellEditorServices.Te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellEditorServices.VSCode", "src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj", "{3B38E8DA-8BFF-4264-AF16-47929E6398A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerShellEditorServices.Engine", "src\PowerShellEditorServices.Engine\PowerShellEditorServices.Engine.csproj", "{29EEDF03-0990-45F4-846E-2616970D1FA2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -134,6 +136,18 @@ Global
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|x64.Build.0 = Release|Any CPU
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|x86.ActiveCfg = Release|Any CPU
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|x86.Build.0 = Release|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|x64.ActiveCfg = Debug|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|x64.Build.0 = Debug|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|x86.ActiveCfg = Debug|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Debug|x86.Build.0 = Debug|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|Any CPU.Build.0 = Release|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x64.ActiveCfg = Release|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x64.Build.0 = Release|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x86.ActiveCfg = Release|Any CPU
{29EEDF03-0990-45F4-846E-2616970D1FA2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -147,5 +161,6 @@ Global
{F8A0946A-5D25-4651-8079-B8D5776916FB} = {F594E7FD-1E72-4E51-A496-B019C2BA3180}
{E3A5CF5D-6E41-44AC-AE0A-4C227E4BACD4} = {422E561A-8118-4BE7-A54F-9309E4F03AAE}
{3B38E8DA-8BFF-4264-AF16-47929E6398A3} = {F594E7FD-1E72-4E51-A496-B019C2BA3180}
{29EEDF03-0990-45F4-846E-2616970D1FA2} = {F594E7FD-1E72-4E51-A496-B019C2BA3180}
EndGlobalSection
EndGlobal
20 changes: 11 additions & 9 deletions src/PowerShellEditorServices.Engine/Hosting/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
//

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Extensions.Logging;

namespace Microsoft.PowerShell.EditorServices.Engine
{
Expand Down Expand Up @@ -64,7 +62,9 @@ public class EditorServicesHost

private ILanguageServer _languageServer;

private Extensions.Logging.ILogger _logger;
private readonly Extensions.Logging.ILogger _logger;

private readonly ILoggerFactory _factory;

#endregion

Expand Down Expand Up @@ -130,10 +130,8 @@ public EditorServicesHost(
Log.Logger = new LoggerConfiguration().Enrich.FromLogContext()
.WriteTo.Console()
.CreateLogger();

_logger = new SerilogLoggerProvider().CreateLogger(nameof(EditorServicesHost));

_serviceCollection.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true));
_factory = new LoggerFactory().AddSerilog(Log.Logger);
_logger = _factory.CreateLogger<EditorServicesHost>();

_hostDetails = hostDetails;

Expand Down Expand Up @@ -231,12 +229,16 @@ public void StartLanguageService(
{
NamedPipeName = config.InOutPipeName ?? config.InPipeName,
OutNamedPipeName = config.OutPipeName,
LoggerFactory = _factory
}
.BuildLanguageServer();

_logger.LogInformation("Starting language server");

Task.Run(_languageServer.StartAsync);
Task.Factory.StartNew(() => _languageServer.StartAsync(),
CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);

_logger.LogInformation(
string.Format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Microsoft.Extensions.Logging;
using OS = OmniSharp.Extensions.LanguageServer.Server;
using System.Security.AccessControl;
using OmniSharp.Extensions.LanguageServer.Server;
using PowerShellEditorServices.Engine.Services.Workspace.Handlers;

namespace Microsoft.PowerShell.EditorServices.Engine
{
Expand Down Expand Up @@ -61,14 +63,14 @@ public async Task StartAsync()
}

options.Input = namedPipe;
options.Output = outNamedPipe != null
? outNamedPipe
: namedPipe;
options.Output = outNamedPipe ?? namedPipe;

options.LoggerFactory = _configuration.LoggerFactory;
options.MinimumLogLevel = _configuration.MinimumLogLevel;
options.Services = _configuration.Services;
options.WithHandler<WorkspaceSymbolsHandler>();
});

_serverStart.SetResult(true);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;

namespace PowerShellEditorServices.Engine.Services.Workspace.Handlers
{
public class WorkspaceSymbolsHandler : IWorkspaceSymbolsHandler
{
private readonly ILogger _logger;

public WorkspaceSymbolsHandler(ILoggerFactory loggerFactory) {
_logger = loggerFactory.CreateLogger<WorkspaceSymbolsHandler>();
}

public object GetRegistrationOptions()
{
return null;
// throw new NotImplementedException();
}

public Task<SymbolInformationContainer> Handle(WorkspaceSymbolParams request, CancellationToken cancellationToken)
{
var symbols = new List<SymbolInformation>();

// foreach (ScriptFile scriptFile in editorSession.Workspace.GetOpenedFiles())
// {
// FindOccurrencesResult foundSymbols =
// editorSession.LanguageService.FindSymbolsInFile(
// scriptFile);

// // TODO: Need to compute a relative path that is based on common path for all workspace files
// string containerName = Path.GetFileNameWithoutExtension(scriptFile.FilePath);

// if (foundSymbols != null)
// {
// foreach (SymbolReference foundOccurrence in foundSymbols.FoundOccurrences)
// {
// if (!IsQueryMatch(request.Query, foundOccurrence.SymbolName))
// {
// continue;
// }

// var location = new Location
// {
// Uri = GetFileUri(foundOccurrence.FilePath),
// Range = GetRangeFromScriptRegion(foundOccurrence.ScriptRegion)
// };

// symbols.Add(new SymbolInformation
// {
// ContainerName = containerName,
// Kind = foundOccurrence.SymbolType == SymbolType.Variable ? SymbolKind.Variable : SymbolKind.Function,
// Location = location,
// Name = GetDecoratedSymbolName(foundOccurrence)
// });
// }
// }
// }
_logger.LogWarning("Logging in a handler works now.");

return Task.FromResult(new SymbolInformationContainer(symbols));
}

public void SetCapability(WorkspaceSymbolCapability capability)
{
// throw new NotImplementedException();
}

#region private Methods

// private bool IsQueryMatch(string query, string symbolName)
// {
// return symbolName.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0;
// }

// private static string GetFileUri(string filePath)
// {
// // If the file isn't untitled, return a URI-style path
// return
// !filePath.StartsWith("untitled") && !filePath.StartsWith("inmemory")
// ? new Uri("file://" + filePath).AbsoluteUri
// : filePath;
// }

// private static Range GetRangeFromScriptRegion(ScriptRegion scriptRegion)
// {
// return new Range
// {
// Start = new Position
// {
// Line = scriptRegion.StartLineNumber - 1,
// Character = scriptRegion.StartColumnNumber - 1
// },
// End = new Position
// {
// Line = scriptRegion.EndLineNumber - 1,
// Character = scriptRegion.EndColumnNumber - 1
// }
// };
// }

// private static string GetDecoratedSymbolName(SymbolReference symbolReference)
// {
// string name = symbolReference.SymbolName;

// if (symbolReference.SymbolType == SymbolType.Configuration ||
// symbolReference.SymbolType == SymbolType.Function ||
// symbolReference.SymbolType == SymbolType.Workflow)
// {
// name += " { }";
// }

// return name;
// }

#endregion
}
}
11 changes: 11 additions & 0 deletions test/Pester/EditorServices.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ Describe "Loading and running PowerShellEditorServices" {
#ReportLogErrors -LogPath $psesServer.LogPath -FromIndex ([ref]$logIdx)
}

It "Can handle WorkspaceSymbol request" {
$request = Send-LspRequest -Client $client -Method "workspace/symbol" -Parameters @{
query = ""
}
$response = Get-LspResponse -Client $client -Id $request.Id #-WaitMillis 99999
$response.Id | Should -BeExactly $request.Id
CheckErrorResponse -Response $response

# ReportLogErrors -LogPath $psesServer.LogPath -FromIndex ([ref]$logIdx)
}

# This test MUST be last
It "Shuts down the process properly" {
$request = Send-LspShutdownRequest -Client $client
Expand Down

0 comments on commit a1882b8

Please sign in to comment.