From 8e021f9119a9a57e16952189d0d4a4f6b46ebf1e Mon Sep 17 00:00:00 2001 From: Adam Friedman Date: Fri, 22 Sep 2017 16:45:12 +1000 Subject: [PATCH] Quick-and-dirty hack to call go-langserver. Doesn't work on Windows, though - their path-handling is all over the place (https://github.com/sourcegraph/go-langserver/issues/113). Will try again when things have stabilised. --- samples/Client/Program.cs | 65 ++++++++++++++++++++++---------- src/LSP.Client/LanguageClient.cs | 3 +- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/samples/Client/Program.cs b/samples/Client/Program.cs index fff710f..aa0ab43 100644 --- a/samples/Client/Program.cs +++ b/samples/Client/Program.cs @@ -1,5 +1,6 @@ using Common; using Lsp.Capabilities.Client; +using Lsp.Models; using LSP.Client; using Newtonsoft.Json.Linq; using Serilog; @@ -63,9 +64,9 @@ static void Main() /// static async Task AsyncMain() { - ProcessStartInfo serverStartInfo = new ProcessStartInfo("dotnet") + ProcessStartInfo serverStartInfo = new ProcessStartInfo(@"D:\Development\go\bin\go-langserver.exe") { - Arguments = $"\"{ServerAssembly}\"" + Arguments = @"-mode stdio -logfile ""D:\Stage\go-langserver.log""" }; Log.Information("Starting server..."); @@ -73,6 +74,20 @@ static async Task AsyncMain() { ClientCapabilities = { + TextDocument = new TextDocumentClientCapabilities + { + Hover = new HoverCapability + { + DynamicRegistration = false + }, + Synchronization = new SynchronizationCapability + { + DidSave = true, + WillSave = false, + WillSaveWaitUntil = false, + DynamicRegistration = false + } + }, Workspace = { DidChangeConfiguration = new DidChangeConfigurationCapability @@ -91,30 +106,42 @@ static async Task AsyncMain() }); // Listen for our custom notification from the language server. - client.HandleNotification("dummy/notify", notification => - { - Log.Information("Received dummy notification from language server: {Message}", - notification.Message - ); - }); + //client.HandleNotification("dummy/notify", notification => + //{ + // Log.Information("Received dummy notification from language server: {Message}", + // notification.Message + // ); + //}); - await client.Initialize(workspaceRoot: @"C:\Foo"); + await client.Initialize(workspaceRoot: @"D:\Development\go\src\github.com\sourcegraph\go-langserver"); Log.Information("Client started."); // Update server configuration. - client.Workspace.DidChangeConfiguration( - new JObject( - new JProperty("setting1", true), - new JProperty("setting2", "Hello") - ) - ); + //client.Workspace.DidChangeConfiguration( + // new JObject( + // new JProperty("setting1", true), + // new JProperty("setting2", "Hello") + // ) + //); + + client.TextDocument.DidOpen(@"D:\Development\go\src\github.com\sourcegraph\go-langserver\main.go", "go"); // Invoke our custom handler. - await client.SendRequest("dummy", new DummyParams - { - Message = "Hello, world!" - }); + //await client.SendRequest("dummy", new DummyParams + //{ + // Message = "Hello, world!" + //}); + + Hover hover = await client.TextDocument.Hover( + new Uri("file:" + @"D:\Development\go\src\github.com\sourcegraph\go-langserver\main.go".Replace('\\', '/')), + line: 63, + column: 19 + ); + if (hover != null) + Log.Information("Got hover: {@Hover}", hover); + else + Log.Information("No hover provided."); Log.Information("Stopping language server..."); await client.Shutdown(); diff --git a/src/LSP.Client/LanguageClient.cs b/src/LSP.Client/LanguageClient.cs index c5f614d..ba5977e 100644 --- a/src/LSP.Client/LanguageClient.cs +++ b/src/LSP.Client/LanguageClient.cs @@ -201,7 +201,8 @@ public Task HasShutdown InitializeParams initializeParams = new InitializeParams { - RootPath = workspaceRoot, + //RootPath = workspaceRoot, + RootUri = new Uri("file:" + workspaceRoot.Replace('\\', '/')), Capabilities = ClientCapabilities, ProcessId = Process.GetCurrentProcess().Id };