Skip to content

Commit 80e1b38

Browse files
Merge pull request #42 from OmniSharp/serially-parallel
Serially parallel
2 parents 55725f4 + 8768555 commit 80e1b38

File tree

73 files changed

+552
-321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+552
-321
lines changed

sample/SampleServer/Program.cs

-102
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
using System.Threading.Tasks;
44
using Microsoft.Extensions.Logging;
55
using OmniSharp.Extensions.LanguageServer;
6-
using OmniSharp.Extensions.LanguageServer.Abstractions;
7-
using OmniSharp.Extensions.LanguageServer.Capabilities.Client;
8-
using OmniSharp.Extensions.LanguageServer.Capabilities.Server;
9-
using OmniSharp.Extensions.LanguageServer.Models;
10-
using OmniSharp.Extensions.LanguageServer.Protocol;
11-
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
126

137
namespace SampleServer
148
{
@@ -34,100 +28,4 @@ static async Task MainAsync(string[] args)
3428
await server.WasShutDown;
3529
}
3630
}
37-
38-
class TextDocumentHandler : ITextDocumentSyncHandler
39-
{
40-
private readonly ILanguageServer _router;
41-
42-
private readonly DocumentSelector _documentSelector = new DocumentSelector(
43-
new DocumentFilter()
44-
{
45-
Pattern = "**/*.csproj",
46-
Language = "xml"
47-
}
48-
);
49-
50-
private SynchronizationCapability _capability;
51-
52-
public TextDocumentHandler(ILanguageServer router)
53-
{
54-
_router = router;
55-
}
56-
57-
public TextDocumentSyncOptions Options { get; } = new TextDocumentSyncOptions()
58-
{
59-
WillSaveWaitUntil = false,
60-
WillSave = true,
61-
Change = TextDocumentSyncKind.Full,
62-
Save = new SaveOptions()
63-
{
64-
IncludeText = true
65-
},
66-
OpenClose = true
67-
};
68-
69-
public Task Handle(DidChangeTextDocumentParams notification)
70-
{
71-
_router.LogMessage(new LogMessageParams()
72-
{
73-
Type = MessageType.Log,
74-
Message = "Hello World!!!!"
75-
});
76-
return Task.CompletedTask;
77-
}
78-
79-
TextDocumentChangeRegistrationOptions IRegistration<TextDocumentChangeRegistrationOptions>.GetRegistrationOptions()
80-
{
81-
return new TextDocumentChangeRegistrationOptions()
82-
{
83-
DocumentSelector = _documentSelector,
84-
SyncKind = Options.Change
85-
};
86-
}
87-
88-
public void SetCapability(SynchronizationCapability capability)
89-
{
90-
_capability = capability;
91-
}
92-
93-
public async Task Handle(DidOpenTextDocumentParams notification)
94-
{
95-
_router.LogMessage(new LogMessageParams()
96-
{
97-
Type = MessageType.Log,
98-
Message = "Hello World!!!!"
99-
});
100-
}
101-
102-
TextDocumentRegistrationOptions IRegistration<TextDocumentRegistrationOptions>.GetRegistrationOptions()
103-
{
104-
return new TextDocumentRegistrationOptions()
105-
{
106-
DocumentSelector = _documentSelector,
107-
};
108-
}
109-
110-
public Task Handle(DidCloseTextDocumentParams notification)
111-
{
112-
return Task.CompletedTask;
113-
}
114-
115-
public Task Handle(DidSaveTextDocumentParams notification)
116-
{
117-
return Task.CompletedTask;
118-
}
119-
120-
TextDocumentSaveRegistrationOptions IRegistration<TextDocumentSaveRegistrationOptions>.GetRegistrationOptions()
121-
{
122-
return new TextDocumentSaveRegistrationOptions()
123-
{
124-
DocumentSelector = _documentSelector,
125-
IncludeText = Options.Save.IncludeText
126-
};
127-
}
128-
public TextDocumentAttributes GetTextDocumentAttributes(Uri uri)
129-
{
130-
return new TextDocumentAttributes(uri, "csharp");
131-
}
132-
}
13331
}
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using OmniSharp.Extensions.LanguageServer;
4+
using OmniSharp.Extensions.LanguageServer.Abstractions;
5+
using OmniSharp.Extensions.LanguageServer.Capabilities.Client;
6+
using OmniSharp.Extensions.LanguageServer.Capabilities.Server;
7+
using OmniSharp.Extensions.LanguageServer.Models;
8+
using OmniSharp.Extensions.LanguageServer.Protocol;
9+
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
10+
11+
namespace SampleServer
12+
{
13+
class TextDocumentHandler : ITextDocumentSyncHandler
14+
{
15+
private readonly ILanguageServer _router;
16+
17+
private readonly DocumentSelector _documentSelector = new DocumentSelector(
18+
new DocumentFilter()
19+
{
20+
Pattern = "**/*.csproj",
21+
Language = "xml"
22+
}
23+
);
24+
25+
private SynchronizationCapability _capability;
26+
27+
public TextDocumentHandler(ILanguageServer router)
28+
{
29+
_router = router;
30+
}
31+
32+
public TextDocumentSyncOptions Options { get; } = new TextDocumentSyncOptions()
33+
{
34+
WillSaveWaitUntil = false,
35+
WillSave = true,
36+
Change = TextDocumentSyncKind.Full,
37+
Save = new SaveOptions()
38+
{
39+
IncludeText = true
40+
},
41+
OpenClose = true
42+
};
43+
44+
public Task Handle(DidChangeTextDocumentParams notification)
45+
{
46+
_router.LogMessage(new LogMessageParams()
47+
{
48+
Type = MessageType.Log,
49+
Message = "Hello World!!!!"
50+
});
51+
return Task.CompletedTask;
52+
}
53+
54+
TextDocumentChangeRegistrationOptions IRegistration<TextDocumentChangeRegistrationOptions>.GetRegistrationOptions()
55+
{
56+
return new TextDocumentChangeRegistrationOptions()
57+
{
58+
DocumentSelector = _documentSelector,
59+
SyncKind = Options.Change
60+
};
61+
}
62+
63+
public void SetCapability(SynchronizationCapability capability)
64+
{
65+
_capability = capability;
66+
}
67+
68+
public async Task Handle(DidOpenTextDocumentParams notification)
69+
{
70+
_router.LogMessage(new LogMessageParams()
71+
{
72+
Type = MessageType.Log,
73+
Message = "Hello World!!!!"
74+
});
75+
}
76+
77+
TextDocumentRegistrationOptions IRegistration<TextDocumentRegistrationOptions>.GetRegistrationOptions()
78+
{
79+
return new TextDocumentRegistrationOptions()
80+
{
81+
DocumentSelector = _documentSelector,
82+
};
83+
}
84+
85+
public Task Handle(DidCloseTextDocumentParams notification)
86+
{
87+
return Task.CompletedTask;
88+
}
89+
90+
public Task Handle(DidSaveTextDocumentParams notification)
91+
{
92+
return Task.CompletedTask;
93+
}
94+
95+
TextDocumentSaveRegistrationOptions IRegistration<TextDocumentSaveRegistrationOptions>.GetRegistrationOptions()
96+
{
97+
return new TextDocumentSaveRegistrationOptions()
98+
{
99+
DocumentSelector = _documentSelector,
100+
IncludeText = Options.Save.IncludeText
101+
};
102+
}
103+
public TextDocumentAttributes GetTextDocumentAttributes(Uri uri)
104+
{
105+
return new TextDocumentAttributes(uri, "csharp");
106+
}
107+
}
108+
}

src/JsonRpc/Events.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.Extensions.Logging;
2+
3+
namespace OmniSharp.Extensions.JsonRpc
4+
{
5+
public static class Events
6+
{
7+
public static EventId UnhandledException = new EventId(1337_100);
8+
public static EventId UnhandledRequest = new EventId(1337_101);
9+
public static EventId UnhandledNotification = new EventId(1337_102);
10+
}
11+
}

src/JsonRpc/HandlerCollection.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
namespace OmniSharp.Extensions.JsonRpc
88
{
9-
class HandlerCollection : IEnumerable<IHandlerInstance>
9+
class HandlerCollection : IEnumerable<IHandlerDescriptor>
1010
{
1111
internal readonly List<HandlerInstance> _handlers = new List<HandlerInstance>();
1212

13-
internal class HandlerInstance : IHandlerInstance, IDisposable
13+
internal class HandlerInstance : IHandlerDescriptor, IDisposable
1414
{
1515
private readonly Action _disposeAction;
1616

@@ -34,7 +34,7 @@ public void Dispose()
3434
}
3535
}
3636

37-
public IEnumerator<IHandlerInstance> GetEnumerator()
37+
public IEnumerator<IHandlerDescriptor> GetEnumerator()
3838
{
3939
return _handlers.GetEnumerator();
4040
}

src/JsonRpc/IHandlerInstance.cs renamed to src/JsonRpc/IHandlerDescriptor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace OmniSharp.Extensions.JsonRpc
44
{
5-
public interface IHandlerInstance
5+
public interface IHandlerDescriptor
66
{
77
string Method { get; }
88
IJsonRpcHandler Handler { get; }
99
Type HandlerType { get; }
1010
Type Params { get; }
1111
}
12-
}
12+
}

src/JsonRpc/IRequestProcessIdentifier.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace OmniSharp.Extensions.JsonRpc
44
{
55
public interface IRequestProcessIdentifier
66
{
7-
RequestProcessType Identify(Renor renor);
7+
RequestProcessType Identify(IHandlerDescriptor descriptor);
88
}
9-
}
9+
}

src/JsonRpc/IRequestRouter.cs

+5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ namespace OmniSharp.Extensions.JsonRpc
66
{
77
public interface IRequestRouter
88
{
9+
IHandlerDescriptor GetDescriptor(Notification notification);
10+
IHandlerDescriptor GetDescriptor(Request request);
11+
912
Task RouteNotification(Notification notification);
13+
Task RouteNotification(IHandlerDescriptor descriptor, Notification notification);
1014
Task<ErrorResponse> RouteRequest(Request request);
15+
Task<ErrorResponse> RouteRequest(IHandlerDescriptor descriptor, Request request);
1116
}
1217
}

src/JsonRpc/InputHandler.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,20 @@ private void HandleRequest(string request)
162162
return;
163163
}
164164

165-
foreach (var (type, item) in requests.Select(x => (type: _requestProcessIdentifier.Identify(x), item: x)))
165+
foreach (var item in requests)
166166
{
167167
if (item.IsRequest)
168168
{
169+
var descriptor = _requestRouter.GetDescriptor(item.Request);
170+
if (descriptor is null) continue;
171+
var type = _requestProcessIdentifier.Identify(descriptor);
169172
_scheduler.Add(
170173
type,
171174
item.Request.Method,
172175
async () => {
173176
try
174177
{
175-
var result = await _requestRouter.RouteRequest(item.Request);
178+
var result = await _requestRouter.RouteRequest(descriptor, item.Request);
176179
_outputHandler.Send(result.Value);
177180
}
178181
catch (Exception e)
@@ -187,13 +190,16 @@ private void HandleRequest(string request)
187190
}
188191
else if (item.IsNotification)
189192
{
193+
var descriptor = _requestRouter.GetDescriptor(item.Notification);
194+
if (descriptor is null) continue;
195+
var type = _requestProcessIdentifier.Identify(descriptor);
190196
_scheduler.Add(
191197
type,
192198
item.Notification.Method,
193199
async () => {
194200
try
195201
{
196-
await _requestRouter.RouteNotification(item.Notification);
202+
await _requestRouter.RouteNotification(descriptor, item.Notification);
197203
}
198204
catch (Exception e)
199205
{

src/JsonRpc/MethodAttribute.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
namespace OmniSharp.Extensions.JsonRpc
44
{
@@ -12,4 +12,4 @@ public MethodAttribute(string method)
1212
Method = method;
1313
}
1414
}
15-
}
15+
}

src/JsonRpc/ParallelAttrbute.cs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace OmniSharp.Extensions.JsonRpc
2+
{
3+
public sealed class ParallelAttribute : ProcessAttribute
4+
{
5+
public ParallelAttribute() : base(RequestProcessType.Parallel) { }
6+
}
7+
}

src/JsonRpc/ParallelRequestProcessIdentifier.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ namespace OmniSharp.Extensions.JsonRpc
44
{
55
public class ParallelRequestProcessIdentifier : IRequestProcessIdentifier
66
{
7-
public RequestProcessType Identify(Renor renor)
7+
public RequestProcessType Identify(IHandlerDescriptor descriptor)
88
{
99
return RequestProcessType.Parallel;
1010
}
1111
}
12-
}
12+
}

src/JsonRpc/ProcessAttribute.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace OmniSharp.Extensions.JsonRpc
4+
{
5+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
6+
public class ProcessAttribute : Attribute
7+
{
8+
public ProcessAttribute(RequestProcessType type)
9+
{
10+
Type = type;
11+
}
12+
13+
public RequestProcessType Type { get; }
14+
}
15+
}

0 commit comments

Comments
 (0)