Skip to content

Commit

Permalink
Quick-and-dirty hack to call go-langserver.
Browse files Browse the repository at this point in the history
Doesn't work on Windows, though - their path-handling is all over the place (sourcegraph/go-langserver#113).
Will try again when things have stabilised.
  • Loading branch information
tintoy committed Sep 22, 2017
1 parent d921c9f commit 8e021f9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
65 changes: 46 additions & 19 deletions samples/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Common;
using Lsp.Capabilities.Client;
using Lsp.Models;
using LSP.Client;
using Newtonsoft.Json.Linq;
using Serilog;
Expand Down Expand Up @@ -63,16 +64,30 @@ static void Main()
/// </returns>
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...");
LanguageClient client = new LanguageClient(serverStartInfo)
{
ClientCapabilities =
{
TextDocument = new TextDocumentClientCapabilities
{
Hover = new HoverCapability
{
DynamicRegistration = false
},
Synchronization = new SynchronizationCapability
{
DidSave = true,
WillSave = false,
WillSaveWaitUntil = false,
DynamicRegistration = false
}
},
Workspace =
{
DidChangeConfiguration = new DidChangeConfigurationCapability
Expand All @@ -91,30 +106,42 @@ static async Task AsyncMain()
});

// Listen for our custom notification from the language server.
client.HandleNotification<DummyParams>("dummy/notify", notification =>
{
Log.Information("Received dummy notification from language server: {Message}",
notification.Message
);
});
//client.HandleNotification<DummyParams>("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();
Expand Down
3 changes: 2 additions & 1 deletion src/LSP.Client/LanguageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down

0 comments on commit 8e021f9

Please sign in to comment.