Skip to content

Commit 561a96d

Browse files
Merge pull request #26 from OmniSharp/latest-lsp
Reacting to latest changes for LSP
2 parents f76a391 + 6be75f3 commit 561a96d

22 files changed

+509
-40
lines changed

src/Lsp/HandlerCollection.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public IDisposable Add(IEnumerable<IJsonRpcHandler> handlers)
3737
.ImplementedInterfaces
3838
.Where(x => !string.IsNullOrWhiteSpace(LspHelper.GetMethodName(x))))
3939
{
40-
var @interface = GetHandlerInterface(implementedInterface);
40+
var @interface = HandlerTypeHelpers.GetHandlerInterface(implementedInterface);
4141
var registration = UnwrapGenericType(typeof(IRegistration<>), implementedInterface);
4242
var capability = UnwrapGenericType(typeof(ICapability<>), implementedInterface);
4343

@@ -72,24 +72,6 @@ public IDisposable Add(IEnumerable<IJsonRpcHandler> handlers)
7272
return new ImutableDisposable(descriptors);
7373
}
7474

75-
private static readonly Type[] HandlerTypes = { typeof(INotificationHandler), typeof(INotificationHandler<>), typeof(IRequestHandler<>), typeof(IRequestHandler<,>), };
76-
77-
private bool IsValidInterface(Type type)
78-
{
79-
if (type.GetTypeInfo().IsGenericType)
80-
{
81-
return HandlerTypes.Contains(type.GetGenericTypeDefinition());
82-
}
83-
return HandlerTypes.Contains(type);
84-
}
85-
86-
private Type GetHandlerInterface(Type type)
87-
{
88-
return type?.GetTypeInfo()
89-
.ImplementedInterfaces
90-
.First(IsValidInterface);
91-
}
92-
9375
private Type UnwrapGenericType(Type genericType, Type type)
9476
{
9577
return type?.GetTypeInfo()

src/Lsp/HandlerDescriptor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public HandlerDescriptor(string method, string key, IJsonRpcHandler handler, Typ
3636

3737
public Registration Registration
3838
{
39-
get {
39+
get
40+
{
4041
if (!HasRegistration) return null;
4142
if (_registration != null) return _registration;
4243

@@ -47,7 +48,8 @@ public Registration Registration
4748
.MakeGenericMethod(RegistrationType)
4849
.Invoke(this, new object[] { Handler });
4950

50-
return _registration = new Registration() {
51+
return _registration = new Registration()
52+
{
5153
Id = Guid.NewGuid().ToString(),
5254
Method = Method,
5355
RegisterOptions = options

src/Lsp/HandlerTypeHelpers.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
using OmniSharp.Extensions.JsonRpc;
5+
6+
namespace OmniSharp.Extensions.LanguageServer
7+
{
8+
public static class HandlerTypeHelpers
9+
{
10+
private static readonly Type[] HandlerTypes = { typeof(INotificationHandler), typeof(INotificationHandler<>), typeof(IRequestHandler<>), typeof(IRequestHandler<,>), };
11+
12+
private static bool IsValidInterface(Type type)
13+
{
14+
if (type.GetTypeInfo().IsGenericType)
15+
{
16+
return HandlerTypes.Contains(type.GetGenericTypeDefinition());
17+
}
18+
return HandlerTypes.Contains(type);
19+
}
20+
21+
public static Type GetHandlerInterface(Type type)
22+
{
23+
return type?.GetTypeInfo()
24+
.ImplementedInterfaces
25+
.First(IsValidInterface);
26+
}
27+
}
28+
}

src/Lsp/LanguageServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public Task Handle()
196196

197197
private bool HasHandler<T>()
198198
{
199-
return _collection.Any(z => z.HandlerType == typeof(T));
199+
return _collection.Any(z => z.Handler is T);
200200
}
201201

202202
private T GetOptions<O, T>(Func<O, T> action)

src/Lsp/Models/CompletionItem.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public class CompletionItem
7272
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
7373
public TextEditContainer AdditionalTextEdits { get; set; }
7474
/// <summary>
75+
/// An optional set of characters that when pressed while this completion is active will accept it first and
76+
/// then type that character. *Note* that all commit characters should have `length=1` and that superfluous
77+
/// characters will be ignored.
78+
/// </summary>
79+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
80+
public Container<string> CommitCharacters { get; set; }
81+
/// <summary>
7582
/// An optional command that is executed/// after* inserting this completion./// Note* that
7683
/// additional modifications to the current document should be described with the
7784
/// additionalTextEdits-property.
@@ -85,4 +92,4 @@ public class CompletionItem
8592
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
8693
public object Data { get; set; }
8794
}
88-
}
95+
}

src/Lsp/Models/TextDocumentEdit.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Serialization;
3+
4+
namespace OmniSharp.Extensions.LanguageServer.Models
5+
{
6+
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
7+
public class TextDocumentEdit
8+
{
9+
/// <summary>
10+
/// The text document to change.
11+
/// </summary>
12+
public VersionedTextDocumentIdentifier TextDocument { get; set; }
13+
14+
/// <summary>
15+
/// The edits to be applied.
16+
/// </summary>
17+
public Container<TextEdit> Edits { get; set; }
18+
}
19+
}

src/Lsp/Models/WorkspaceEdit.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ public class WorkspaceEdit
1111
/// <summary>
1212
/// Holds changes to existing resources.
1313
/// </summary>
14-
public IDictionary<Uri, IEnumerable<TextEdit>> Changes { get; set; } = new Dictionary<Uri, IEnumerable<TextEdit>>();
14+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
15+
public IDictionary<Uri, IEnumerable<TextEdit>> Changes { get; set; }
16+
/// <summary>
17+
/// An array of `TextDocumentEdit`s to express changes to n different text documents
18+
/// where each text document edit addresses a specific version of a text document.
19+
/// Whether a client supports versioned document edits is expressed via
20+
/// `WorkspaceClientCapabilities.workspaceEdit.documentChanges`.
21+
/// </summary>
22+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
23+
public Container<TextDocumentEdit> DocumentChanges { get; set; }
1524
}
16-
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using OmniSharp.Extensions.LanguageServer.Models;
2+
3+
// ReSharper disable CheckNamespace
4+
5+
namespace OmniSharp.Extensions.LanguageServer.Protocol
6+
{
7+
public static class CancelRequestExtensions
8+
{
9+
public static void CancelRequest(this ILanguageServer mediator, CancelParams @params)
10+
{
11+
mediator.SendNotification<CancelParams>("$/cancelRequest", @params);
12+
}
13+
14+
public static void CancelRequest(this ILanguageServer mediator, string id)
15+
{
16+
mediator.SendNotification<CancelParams>("$/cancelRequest", new CancelParams() { Id = id });
17+
}
18+
19+
public static void CancelRequest(this ILanguageServer mediator, long id)
20+
{
21+
mediator.SendNotification<CancelParams>("$/cancelRequest", new CancelParams() { Id = id });
22+
}
23+
}
24+
}

src/Lsp/Protocol/General/ICancelRequestHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol
77
{
88
[Method("$/cancelRequest")]
99
public interface ICancelRequestHandler : INotificationHandler<CancelParams> { }
10-
}
10+
}

src/Lsp/Protocol/Window/LogMessageExtensions.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,30 @@ public static void LogMessage(this ILanguageServer mediator, LogMessageParams @p
1111
{
1212
mediator.SendNotification("window/logMessage", @params);
1313
}
14+
15+
public static void Log(this ILanguageServer mediator, LogMessageParams @params)
16+
{
17+
mediator.LogMessage(@params);
18+
}
19+
20+
public static void LogError(this ILanguageServer mediator, string message)
21+
{
22+
mediator.LogMessage(new LogMessageParams() { Type = MessageType.Error, Message = message });
23+
}
24+
25+
public static void Log(this ILanguageServer mediator, string message)
26+
{
27+
mediator.LogMessage(new LogMessageParams() { Type = MessageType.Log, Message = message });
28+
}
29+
30+
public static void LogWarning(this ILanguageServer mediator, string message)
31+
{
32+
mediator.LogMessage(new LogMessageParams() { Type = MessageType.Warning, Message = message });
33+
}
34+
35+
public static void LogInfo(this ILanguageServer mediator, string message)
36+
{
37+
mediator.LogMessage(new LogMessageParams() { Type = MessageType.Info, Message = message });
38+
}
1439
}
15-
}
40+
}

0 commit comments

Comments
 (0)