Skip to content

Commit

Permalink
All fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Oct 19, 2023
1 parent 4ffb8d4 commit f727242
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Draco.LanguageServer/Capabilities/DidDeleteFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal partial class DracoLanguageServer : IDidDeleteFiles
}
};

public async Task DidDeleteFilesAsync(DeleteFilesParams param, CancellationToken cancellationToken)
public async Task DidDeleteFilesAsync(DeleteFilesParams param)
{
foreach (var file in param.Files)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Draco.LanguageServer/Capabilities/TextDocumentSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ namespace Draco.LanguageServer;

internal sealed partial class DracoLanguageServer : ITextDocumentSync
{
public async Task TextDocumentDidOpenAsync(DidOpenTextDocumentParams param, CancellationToken cancellationToken)
public async Task TextDocumentDidOpenAsync(DidOpenTextDocumentParams param)
{
await this.PublishDiagnosticsAsync(param.TextDocument.Uri);
}

public Task TextDocumentDidCloseAsync(DidCloseTextDocumentParams param, CancellationToken cancellationToken) =>
public Task TextDocumentDidCloseAsync(DidCloseTextDocumentParams param) =>
Task.CompletedTask;

public async Task TextDocumentDidChangeAsync(DidChangeTextDocumentParams param, CancellationToken cancellationToken)
public async Task TextDocumentDidChangeAsync(DidChangeTextDocumentParams param)
{
var uri = param.TextDocument.Uri;
var change = param.ContentChanges.First();
Expand Down
2 changes: 0 additions & 2 deletions src/Draco.LanguageServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ internal static async Task Main(string[] args)

internal static async Task RunServerAsync(bool stdioFlag)
{
await Task.Delay(10000);

var transportKind = GetTransportKind(stdioFlag);
var transportStream = BuildTransportStream(transportKind);

Expand Down
33 changes: 26 additions & 7 deletions src/Draco.Lsp/Server/LanguageClientProxy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -41,11 +42,32 @@ internal class LanguageClientProxy : DispatchProxy
private object? ProxyRpc(MethodInfo method, object?[] arguments)
{
var handler = this.handlers.GetOrAdd(method, m => new(m, this));
var args = handler.SupportsCancellation ? arguments[..^1] : arguments;

if (handler.IsRequest)
{
// It's a request
// Build up args
var args = new List<object?>();
// Method name
args.Add(handler.MethodName);
// Parameter
if (handler.AcceptsParams)
{
args.Add(arguments[0]);
}
else
{
args.Add(null);
}
// CT
if (handler.SupportsCancellation)
{
args.Add(arguments[1]!);
}
else
{
args.Add(CancellationToken.None);
}

// Extract return type
var returnType = method.ReturnType;

Expand All @@ -54,17 +76,14 @@ internal class LanguageClientProxy : DispatchProxy
returnType = returnType.GetGenericArguments()[0];
}

// TODO: cancellation token
var ct = CancellationToken.None;

return SendRequestMethod
.MakeGenericMethod(returnType)
.Invoke(this.Connection, new[] { handler.MethodName, args.SingleOrDefault(), ct });
.Invoke(this.Connection, args.ToArray());
}
else
{
// It's a notification
return this.Connection.SendNotificationAsync(handler.MethodName, args.SingleOrDefault());
return this.Connection.SendNotificationAsync(handler.MethodName, arguments.SingleOrDefault());
}
}
}
9 changes: 7 additions & 2 deletions src/Draco.Lsp/Server/LanguageServerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ private LspMessageAdapter()
Id = id,
Params = @params,
};
public static LspMessage CreateCancelRequest(int id) => throw new NotImplementedException();
public static LspMessage CreateCancelRequest(int id) => CreateNotification(
"$/cancelRequest",
JsonSerializer.SerializeToElement(new CancelParams
{
Id = id,
}));
public static LspMessage CreateOkResponse(object id, JsonElement okResult) => new ResponseMessage
{
Jsonrpc = "2.0",
Expand All @@ -43,7 +48,7 @@ private LspMessageAdapter()
{
Jsonrpc = "2.0",
Id = ToId(id),
Error = (ResponseError)errorResult,
Error = errorResult,
};
public static LspMessage CreateNotification(string method, JsonElement @params) => new NotificationMessage
{
Expand Down
13 changes: 2 additions & 11 deletions src/Draco.Lsp/Server/LanguageServerMethodHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,12 @@ public LanguageServerMethodHandler(MethodInfo handlerMethod, object? target)
this.DeclaredReturnType = returnType;
}

public Task InvokeNotification(object?[] args)
{
Debug.WriteLine($"InvokeNotification {this.MethodName} START");
var result = (Task)this.handlerMethod.Invoke(this.target, args.ToArray())!;
Debug.WriteLine($"InvokeNotification {this.MethodName} END");
return result;
}
public Task InvokeNotification(object?[] args) =>
(Task)this.handlerMethod.Invoke(this.target, args.ToArray())!;

public async Task<object?> InvokeRequest(object?[] args)
{
Debug.WriteLine($"InvokeRequest {this.MethodName} START");
var task = (Task)this.handlerMethod.Invoke(this.target, args.ToArray())!;
Debug.WriteLine($"InvokeRequest {this.MethodName} END");
await task;

if (this.DeclaredReturnType == typeof(Task))
Expand All @@ -124,9 +117,7 @@ public Task InvokeNotification(object?[] args)
}
else
{
Debug.WriteLine($"EEEE {this.MethodName} START");
var getResult = (MethodInfo)task.GetType().GetMemberWithSameMetadataDefinitionAs(taskGetResult);
Debug.WriteLine($"EEEE {this.MethodName} END");
return getResult.Invoke(task, null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface ITextDocumentDidChange
public TextDocumentChangeRegistrationOptions DidChangeRegistrationOptions { get; }

[Notification("textDocument/didChange", Mutating = true)]
public Task TextDocumentDidChangeAsync(DidChangeTextDocumentParams param, CancellationToken cancellationToken);
public Task TextDocumentDidChangeAsync(DidChangeTextDocumentParams param);
}
2 changes: 1 addition & 1 deletion src/Draco.Lsp/Server/TextDocument/ITextDocumentDidClose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface ITextDocumentDidClose
public TextDocumentRegistrationOptions DidCloseRegistrationOptions { get; }

[Notification("textDocument/didClose", Mutating = true)]
public Task TextDocumentDidCloseAsync(DidCloseTextDocumentParams param, CancellationToken cancellationToken);
public Task TextDocumentDidCloseAsync(DidCloseTextDocumentParams param);
}
2 changes: 1 addition & 1 deletion src/Draco.Lsp/Server/TextDocument/ITextDocumentDidOpen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface ITextDocumentDidOpen
public TextDocumentRegistrationOptions DidOpenRegistrationOptions { get; }

[Notification("textDocument/didOpen", Mutating = true)]
public Task TextDocumentDidOpenAsync(DidOpenTextDocumentParams param, CancellationToken cancellationToken);
public Task TextDocumentDidOpenAsync(DidOpenTextDocumentParams param);
}
4 changes: 2 additions & 2 deletions src/Draco.Lsp/Server/Workspace/IDidDeleteFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public interface IDidDeleteFiles
[RegistrationOptions("workspace/didDeleteFiles")]
public FileOperationRegistrationOptions DidDeleteFileRegistrationOptions { get; }

[Notification("workspace/didDeleteFiles")]
public Task DidDeleteFilesAsync(DeleteFilesParams param, CancellationToken cancellationToken);
[Notification("workspace/didDeleteFiles", Mutating = true)]
public Task DidDeleteFilesAsync(DeleteFilesParams param);
}

0 comments on commit f727242

Please sign in to comment.