Skip to content

Commit b2c26e2

Browse files
Started on support for manyhandlers, needs unit tests to verify working as intedned
1 parent a191b5f commit b2c26e2

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/Lsp/LspRequestRouter.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
34
using System.Linq;
45
using System.Reflection;
56
using System.Threading;
@@ -18,7 +19,7 @@ namespace OmniSharp.Extensions.LanguageServer
1819
class LspRequestRouter : IRequestRouter
1920
{
2021
private readonly IHandlerCollection _collection;
21-
private ITextDocumentSyncHandler _textDocumentSyncHandler;
22+
private ITextDocumentSyncHandler[] _textDocumentSyncHandlers;
2223
private readonly ConcurrentDictionary<string, CancellationTokenSource> _requests = new ConcurrentDictionary<string, CancellationTokenSource>();
2324

2425
public LspRequestRouter(IHandlerCollection collection)
@@ -46,19 +47,20 @@ private ILspHandlerDescriptor FindDescriptor(string method, JToken @params)
4647
var descriptor = _collection.FirstOrDefault(x => x.Method == method);
4748
if (descriptor is null) return null;
4849

49-
if (_textDocumentSyncHandler == null)
50+
if (_textDocumentSyncHandlers == null)
5051
{
51-
_textDocumentSyncHandler = _collection
52+
_textDocumentSyncHandlers = _collection
5253
.Select(x => x.Handler is ITextDocumentSyncHandler r ? r : null)
53-
.FirstOrDefault(x => x != null);
54+
.Where(x => x != null)
55+
.ToArray();
5456
}
5557

56-
if (_textDocumentSyncHandler is null) return descriptor;
57-
5858
if (typeof(ITextDocumentIdentifierParams).GetTypeInfo().IsAssignableFrom(descriptor.Params))
5959
{
6060
var textDocumentIdentifierParams = @params.ToObject(descriptor.Params) as ITextDocumentIdentifierParams;
61-
var attributes = _textDocumentSyncHandler.GetTextDocumentAttributes(textDocumentIdentifierParams.TextDocument.Uri);
61+
var attributes = _textDocumentSyncHandlers
62+
.Select(x => x.GetTextDocumentAttributes(textDocumentIdentifierParams.TextDocument.Uri))
63+
.Where(x => x != null);
6264

6365
return GetHandler(method, attributes);
6466
}
@@ -75,6 +77,13 @@ private ILspHandlerDescriptor FindDescriptor(string method, JToken @params)
7577
return descriptor;
7678
}
7779

80+
private ILspHandlerDescriptor GetHandler(string method, IEnumerable<TextDocumentAttributes> attributes)
81+
{
82+
return attributes
83+
.Select(x => GetHandler(method, x))
84+
.FirstOrDefault(x => x != null);
85+
}
86+
7887
private ILspHandlerDescriptor GetHandler(string method, TextDocumentAttributes attributes)
7988
{
8089
foreach (var handler in _collection.Where(x => x.Method == method))

vscode-testextension/src/extension.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import * as path from 'path';
88

99
import { workspace, Disposable, ExtensionContext } from 'vscode';
10-
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind } from 'vscode-languageclient';
10+
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind, InitializeParams } from 'vscode-languageclient';
11+
import { Trace } from 'vscode-jsonrpc';
1112

1213
export function activate(context: ExtensionContext) {
1314

1415
// The server is implemented in node
15-
// let serverExe = 'D:/Development/Omnisharp/omnisharp-roslyn/bin/Debug/OmniSharp.Stdio/net46/OmniSharp.exe';
16-
let serverExe = 'D:/Development/Omnisharp/omnisharp-roslyn/artifacts/publish/OmniSharp.Stdio/win7-x64/OmniSharp.exe';
16+
let serverExe = 'C:/other/omnisharp-roslyn/bin/Debug/OmniSharp.Stdio/net46/OmniSharp.exe';
17+
// let serverExe = 'C:/other/omnisharp-roslyn/artifacts/publish/OmniSharp.Stdio/win7-x64/OmniSharp.exe';
1718
// let serverExe = context.asAbsolutePath('D:/Development/Omnisharp/omnisharp-roslyn/artifacts/publish/OmniSharp.Stdio/win7-x64/OmniSharp.exe');
1819
// The debug options for the server
1920
// let debugOptions = { execArgv: ['-lsp', '-d' };5
@@ -40,11 +41,12 @@ export function activate(context: ExtensionContext) {
4041
configurationSection: 'languageServerExample',
4142
// Notify the server about file changes to '.clientrc files contain in the workspace
4243
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
43-
}
44+
},
4445
}
4546

4647
// Create the language client and start the client.
4748
const client = new LanguageClient('languageServerExample', 'Language Server Example', serverOptions, clientOptions);
49+
client.trace = Trace.Verbose;
4850
let disposable = client.start();
4951

5052
// Push the disposable to the context's subscriptions so that the

0 commit comments

Comments
 (0)