Skip to content

Commit 4bc2a15

Browse files
Merge pull request #21 from OmniSharp/oninit
Added OnInitialize handler
2 parents a08e998 + 9e5f1c2 commit 4bc2a15

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
namespace OmniSharp.Extensions.LanguageServer.Handlers
22
{
33
public delegate void ShutdownEventHandler(bool shutdownRequested);
4-
}
4+
}

src/Lsp/Handlers/ShutdownHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
22
using OmniSharp.Extensions.LanguageServer.Protocol;
33
using OmniSharp.Extensions.LanguageServer.Abstractions;
44

@@ -18,7 +18,7 @@ public Task Handle()
1818

1919
public bool ShutdownRequested { get; private set; }
2020

21-
private TaskCompletionSource<bool> shutdownSource = new TaskCompletionSource<bool>(TaskContinuationOptions.LongRunning);
21+
private readonly TaskCompletionSource<bool> shutdownSource = new TaskCompletionSource<bool>(TaskContinuationOptions.LongRunning);
2222
Task IAwaitableTermination.WasShutDown => shutdownSource.Task;
2323
}
24-
}
24+
}

src/Lsp/LanguageServer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717

1818
namespace OmniSharp.Extensions.LanguageServer
1919
{
20+
public delegate Task InitializeDelegate(InitializeParams request);
21+
2022
public class LanguageServer : ILanguageServer, IInitializeHandler, IInitializedHandler, IDisposable, IAwaitableTermination
2123
{
2224
private readonly Connection _connection;
2325
private readonly LspRequestRouter _requestRouter;
2426
private readonly ShutdownHandler _shutdownHandler = new ShutdownHandler();
27+
private readonly List<InitializeDelegate> _initializeDelegates = new List<InitializeDelegate>();
2528
private readonly ExitHandler _exitHandler;
2629
private ClientVersion? _clientVersion;
2730
private readonly HandlerCollection _collection = new HandlerCollection();
@@ -94,6 +97,8 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult>
9497
{
9598
Client = request;
9699

100+
await Task.WhenAll(_initializeDelegates.Select(c => c(request)));
101+
97102
_clientVersion = request.Capabilities.GetClientVersion();
98103

99104
if (_clientVersion == ClientVersion.Lsp3)
@@ -165,6 +170,12 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult>
165170
return result;
166171
}
167172

173+
public LanguageServer OnInitialize(InitializeDelegate @delegate)
174+
{
175+
_initializeDelegates.Add(@delegate);
176+
return this;
177+
}
178+
168179
public Task Handle()
169180
{
170181
if (_clientVersion == ClientVersion.Lsp3)

vscode-testextension/src/extension.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,25 @@ import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, T
1212
export function activate(context: ExtensionContext) {
1313

1414
// The server is implemented in node
15-
let serverExe = context.asAbsolutePath('../sample/SampleServer/bin/Debug/netcoreapp1.1/win7-x64/SampleServer.exe');
15+
let serverExe = 'D:/Development/Omnisharp/omnisharp-roslyn/bin/Debug/OmniSharp.Stdio/net46/OmniSharp.exe';
16+
// let serverExe = context.asAbsolutePath('D:/Development/Omnisharp/omnisharp-roslyn/artifacts/publish/OmniSharp.Stdio/win7-x64/OmniSharp.exe');
1617
// The debug options for the server
17-
let debugOptions = { execArgv: ["--nolazy", "--debug=6009"] };
18+
// let debugOptions = { execArgv: ['-lsp', '-d' };
1819

1920
// If the extension is launched in debug mode then the debug server options are used
2021
// Otherwise the run options are used
2122
let serverOptions: ServerOptions = {
22-
run : { command: serverExe },
23-
debug: { command: serverExe, options: debugOptions }
23+
run : { command: serverExe, args: ['-lsp'] },
24+
debug: { command: serverExe, args: ['-lsp', '-d'] }
2425
}
2526

2627
// Options to control the language client
2728
let clientOptions: LanguageClientOptions = {
2829
// Register the server for plain text documents
29-
documentSelector: [{
30-
language: 'xml',
31-
pattern: '*.csproj'
32-
}],
30+
// documentSelector: [{
31+
// language: 'xml',
32+
// pattern: '*.csproj'
33+
// }],
3334
synchronize: {
3435
// Synchronize the setting section 'languageServerExample' to the server
3536
configurationSection: 'languageServerExample',
@@ -39,7 +40,8 @@ export function activate(context: ExtensionContext) {
3940
}
4041

4142
// Create the language client and start the client.
42-
let disposable = new LanguageClient('languageServerExample', 'Language Server Example', serverOptions, clientOptions).start();
43+
const client = new LanguageClient('languageServerExample', 'Language Server Example', serverOptions, clientOptions);
44+
let disposable = client.start();
4345

4446
// Push the disposable to the context's subscriptions so that the
4547
// client can be deactivated on extension deactivation

0 commit comments

Comments
 (0)