Skip to content

Commit 3f0a57a

Browse files
Merge pull request #76 from OmniSharp/preprocessing
Added preprocessing for notifications
2 parents b85e6da + 88584d9 commit 3f0a57a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Server/LspRequestRouter.cs

+10
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ public async Task RouteNotification(IHandlerDescriptor descriptor, Notification
9393
{
9494
_logger.LogDebug("Converting params for Notification {Method} to {Type}", notification.Method, descriptor.Params.FullName);
9595
var @params = notification.Params.ToObject(descriptor.Params, _serializer.JsonSerializer);
96+
97+
var lspDescriptor = descriptor as ILspHandlerDescriptor;
98+
99+
foreach (var preProcessor in _routeMatchers.ForHandlerPreProcessorMatcher()
100+
.SelectMany(strat => strat.FindPreProcessor(lspDescriptor, @params)))
101+
{
102+
@params = preProcessor.Process(lspDescriptor, @params);
103+
}
104+
96105
await ReflectionRequestHandlers.HandleNotification(descriptor, @params);
97106
}
98107
}
@@ -138,6 +147,7 @@ public async Task<ErrorResponse> RouteRequest(IHandlerDescriptor descriptor, Req
138147
_logger.LogError(new EventId(-32602), cannotDeserializeRequestParams, "Failed to deserialise request parameters.");
139148
return new InvalidParams(request.Id);
140149
}
150+
141151
var lspDescriptor = descriptor as ILspHandlerDescriptor;
142152

143153
foreach (var preProcessor in _routeMatchers.ForHandlerPreProcessorMatcher()

src/Server/Matchers/ResolveCommandMatcher.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

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

82+
public IEnumerable<IHandlerPreProcessor> FindPreProcessor(ILspHandlerDescriptor descriptor, object parameters)
83+
{
84+
if (parameters is ICanBeResolved canBeResolved)
85+
{
86+
_logger.LogTrace("Using handler {Method}:{Handler}",
87+
descriptor.Method,
88+
descriptor.Handler.GetType().FullName);
89+
yield return this;
90+
}
91+
}
92+
8293
public IEnumerable<IHandlerPostProcessor> FindPostProcessor(ILspHandlerDescriptor descriptor, object parameters, object response)
8394
{
8495
if (descriptor.Method == DocumentNames.CodeLens || descriptor.Method == DocumentNames.Completion)

0 commit comments

Comments
 (0)