Skip to content

Added preprocessing for notifications #76

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

Merged
merged 2 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions src/Server/LspRequestRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public async Task RouteNotification(IHandlerDescriptor descriptor, Notification
{
_logger.LogDebug("Converting params for Notification {Method} to {Type}", notification.Method, descriptor.Params.FullName);
var @params = notification.Params.ToObject(descriptor.Params, _serializer.JsonSerializer);

var lspDescriptor = descriptor as ILspHandlerDescriptor;

foreach (var preProcessor in _routeMatchers.ForHandlerPreProcessorMatcher()
.SelectMany(strat => strat.FindPreProcessor(lspDescriptor, @params)))
{
@params = preProcessor.Process(lspDescriptor, @params);
}

await ReflectionRequestHandlers.HandleNotification(descriptor, @params);
}
}
Expand Down Expand Up @@ -138,6 +147,7 @@ public async Task<ErrorResponse> RouteRequest(IHandlerDescriptor descriptor, Req
_logger.LogError(new EventId(-32602), cannotDeserializeRequestParams, "Failed to deserialise request parameters.");
return new InvalidParams(request.Id);
}

var lspDescriptor = descriptor as ILspHandlerDescriptor;

foreach (var preProcessor in _routeMatchers.ForHandlerPreProcessorMatcher()
Expand Down
13 changes: 12 additions & 1 deletion src/Server/Matchers/ResolveCommandMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace OmniSharp.Extensions.LanguageServer.Server.Matchers
{
public class ResolveCommandMatcher : IHandlerMatcher, IHandlerPostProcessorMatcher, IHandlerPreProcessor, IHandlerPostProcessor
public class ResolveCommandMatcher : IHandlerMatcher, IHandlerPreProcessorMatcher, IHandlerPostProcessorMatcher, IHandlerPreProcessor, IHandlerPostProcessor
{
private readonly ILogger _logger;
internal static string PrivateHandlerTypeName = "$$___handlerType___$$";
Expand Down Expand Up @@ -79,6 +79,17 @@ private static bool CanResolve<T>(ICanBeResolvedHandler<T> handler, T value)
return handler.CanResolve(value);
}

public IEnumerable<IHandlerPreProcessor> FindPreProcessor(ILspHandlerDescriptor descriptor, object parameters)
{
if (parameters is ICanBeResolved canBeResolved)
{
_logger.LogTrace("Using handler {Method}:{Handler}",
descriptor.Method,
descriptor.Handler.GetType().FullName);
yield return this;
}
}

public IEnumerable<IHandlerPostProcessor> FindPostProcessor(ILspHandlerDescriptor descriptor, object parameters, object response)
{
if (descriptor.Method == DocumentNames.CodeLens || descriptor.Method == DocumentNames.Completion)
Expand Down