Skip to content

Commit

Permalink
Merge pull request #76 from OmniSharp/preprocessing
Browse files Browse the repository at this point in the history
Added preprocessing for notifications
  • Loading branch information
david-driscoll authored Feb 16, 2018
2 parents b85e6da + 88584d9 commit 3f0a57a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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

0 comments on commit 3f0a57a

Please sign in to comment.