Skip to content

Commit 0b7b6b4

Browse files
Added key to IJsonRpcHandler to support hashing better; +semver: minor
1 parent 4df674a commit 0b7b6b4

File tree

8 files changed

+55
-14
lines changed

8 files changed

+55
-14
lines changed

sample/SampleServer/Program.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class TextDocumentHandler : ITextDocumentSyncHandler
3939
private readonly ILanguageServer _router;
4040

4141
private readonly DocumentSelector _documentSelector = new DocumentSelector(
42-
new DocumentFilter() {
42+
new DocumentFilter()
43+
{
4344
Pattern = "**/*.csproj",
4445
Language = "xml"
4546
}
@@ -52,19 +53,24 @@ public TextDocumentHandler(ILanguageServer router)
5253
_router = router;
5354
}
5455

55-
public TextDocumentSyncOptions Options { get; } = new TextDocumentSyncOptions() {
56+
public TextDocumentSyncOptions Options { get; } = new TextDocumentSyncOptions()
57+
{
5658
WillSaveWaitUntil = false,
5759
WillSave = true,
5860
Change = TextDocumentSyncKind.Full,
59-
Save = new SaveOptions() {
61+
Save = new SaveOptions()
62+
{
6063
IncludeText = true
6164
},
6265
OpenClose = true
6366
};
6467

68+
public string Key => (string)_documentSelector;
69+
6570
public Task Handle(DidChangeTextDocumentParams notification)
6671
{
67-
_router.LogMessage(new LogMessageParams() {
72+
_router.LogMessage(new LogMessageParams()
73+
{
6874
Type = MessageType.Log,
6975
Message = "Hello World!!!!"
7076
});
@@ -73,7 +79,8 @@ public Task Handle(DidChangeTextDocumentParams notification)
7379

7480
TextDocumentChangeRegistrationOptions IRegistration<TextDocumentChangeRegistrationOptions>.GetRegistrationOptions()
7581
{
76-
return new TextDocumentChangeRegistrationOptions() {
82+
return new TextDocumentChangeRegistrationOptions()
83+
{
7784
DocumentSelector = _documentSelector,
7885
SyncKind = Options.Change
7986
};
@@ -86,15 +93,17 @@ public void SetCapability(SynchronizationCapability capability)
8693

8794
public async Task Handle(DidOpenTextDocumentParams notification)
8895
{
89-
_router.LogMessage(new LogMessageParams() {
96+
_router.LogMessage(new LogMessageParams()
97+
{
9098
Type = MessageType.Log,
9199
Message = "Hello World!!!!"
92100
});
93101
}
94102

95103
TextDocumentRegistrationOptions IRegistration<TextDocumentRegistrationOptions>.GetRegistrationOptions()
96104
{
97-
return new TextDocumentRegistrationOptions() {
105+
return new TextDocumentRegistrationOptions()
106+
{
98107
DocumentSelector = _documentSelector,
99108
};
100109
}
@@ -111,7 +120,8 @@ public Task Handle(DidSaveTextDocumentParams notification)
111120

112121
TextDocumentSaveRegistrationOptions IRegistration<TextDocumentSaveRegistrationOptions>.GetRegistrationOptions()
113122
{
114-
return new TextDocumentSaveRegistrationOptions() {
123+
return new TextDocumentSaveRegistrationOptions()
124+
{
115125
DocumentSelector = _documentSelector,
116126
IncludeText = Options.Save.IncludeText
117127
};

src/JsonRpc/IJsonRpcHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
/// <summary>
44
/// A simple marker interface to use for storing handlings (which will be cast out later)
55
/// </summary>
6-
public interface IJsonRpcHandler { }
7-
}
6+
public interface IJsonRpcHandler { string Key { get; } }
7+
}

src/Lsp/Handlers/CancelRequestHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ internal CancelRequestHandler(LspRequestRouter requestRouter)
1313
_requestRouter = requestRouter;
1414
}
1515

16+
public string Key => nameof(ICancelRequestHandler);
17+
1618
public Task Handle(CancelParams notification)
1719
{
1820
_requestRouter.CancelRequest(notification.Id);

src/Lsp/Handlers/ExitHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public ExitHandler(ShutdownHandler shutdownHandler)
1212
_shutdownHandler = shutdownHandler;
1313
}
1414

15+
public string Key => nameof(IExitHandler);
16+
1517
public Task Handle()
1618
{
1719
Exit?.Invoke(_shutdownHandler.ShutdownRequested ? 0 : 1);

src/Lsp/Handlers/ShutdownHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace OmniSharp.Extensions.LanguageServer.Handlers
66
{
77
public class ShutdownHandler : IShutdownHandler, IAwaitableTermination
88
{
9+
public string Key => nameof(IShutdownHandler);
10+
911
public Task Handle()
1012
{
1113
ShutdownRequested = true;

src/Lsp/LanguageServer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ IRequestProcessIdentifier requestProcessIdentifier
6363
public InitializeParams Client { get; private set; }
6464
public InitializeResult Server { get; private set; }
6565

66+
public string Key => nameof(ILanguageServer);
67+
6668
public IDisposable AddHandler(IJsonRpcHandler handler)
6769
{
6870
var handlerDisposable = _collection.Add(handler);

src/Lsp/Models/DocumentFilter.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Minimatch;
1+
using System.Collections.Generic;
2+
using System.Text;
3+
using Minimatch;
24
using Newtonsoft.Json;
35
using Newtonsoft.Json.Serialization;
46
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
@@ -39,7 +41,8 @@ public class DocumentFilter
3941
public string Pattern
4042
{
4143
get => _pattern;
42-
set {
44+
set
45+
{
4346
_pattern = value;
4447
_minimatcher = new Minimatcher(value, new Options() { MatchBase = true });
4548
}
@@ -54,6 +57,21 @@ public string Pattern
5457
private string _pattern;
5558
private Minimatcher _minimatcher;
5659

60+
public static explicit operator string(DocumentFilter documentFilter)
61+
{
62+
var items = new List<string>();
63+
if (documentFilter.HasLanguage) {
64+
items.Add(documentFilter.Language);
65+
}
66+
if (documentFilter.HasScheme) {
67+
items.Add(documentFilter.Scheme);
68+
}
69+
if (documentFilter.HasPattern) {
70+
items.Add(documentFilter.Pattern);
71+
}
72+
return $"[{string.Join(", ", items)}]";
73+
}
74+
5775
public bool IsMatch(TextDocumentAttributes attributes)
5876
{
5977
if (HasLanguage && HasPattern && HasScheme)
@@ -88,4 +106,4 @@ public bool IsMatch(TextDocumentAttributes attributes)
88106
return false;
89107
}
90108
}
91-
}
109+
}

src/Lsp/Models/DocumentSelector.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ public static implicit operator DocumentSelector(List<DocumentFilter> items)
3838
return new DocumentSelector(items);
3939
}
4040

41+
public static explicit operator string(DocumentSelector documentSelector)
42+
{
43+
return string.Join(", ", documentSelector.Select(x => (string)x));
44+
}
45+
4146
public bool IsMatch(TextDocumentAttributes attributes)
4247
{
4348
return this.Any(z => z.IsMatch(attributes));
4449
}
4550
}
46-
}
51+
}

0 commit comments

Comments
 (0)