Skip to content

Commit eb2ff5d

Browse files
Added const names and refactored all code I could find to use them where appropriate
1 parent 2fde885 commit eb2ff5d

File tree

77 files changed

+401
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+401
-131
lines changed

sample/SampleServer/TextDocumentHandler.cs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using OmniSharp.Extensions.LanguageServer;
44
using OmniSharp.Extensions.LanguageServer.Protocol;
55
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
6-
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
76
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
87
using OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities;
98
using OmniSharp.Extensions.LanguageServer.Server;

src/Client/Clients/TextDocumentClient.Completions.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44
using OmniSharp.Extensions.LanguageServer.Client.Utilities;
5+
using OmniSharp.Extensions.LanguageServer.Protocol;
56
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
67

78
namespace OmniSharp.Extensions.LanguageServer.Client.Clients
@@ -59,7 +60,7 @@ public partial class TextDocumentClient
5960
/// </returns>
6061
public Task<CompletionList> Completions(Uri documentUri, int line, int column, CancellationToken cancellationToken = default(CancellationToken))
6162
{
62-
return PositionalRequest<CompletionList>("textDocument/completion", documentUri, line, column, cancellationToken);
63+
return PositionalRequest<CompletionList>(DocumentNames.Completion, documentUri, line, column, cancellationToken);
6364
}
6465
}
6566
}

src/Client/Clients/TextDocumentClient.Diagnostics.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using OmniSharp.Extensions.LanguageServer.Protocol;
34
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
45

56
namespace OmniSharp.Extensions.LanguageServer.Client.Clients
@@ -26,8 +27,9 @@ public IDisposable OnPublishDiagnostics(PublishDiagnosticsHandler handler)
2627
if (handler == null)
2728
throw new ArgumentNullException(nameof(handler));
2829

29-
return Client.HandleNotification<PublishDiagnosticsParams>("textDocument/publishDiagnostics", notification =>
30+
return Client.HandleNotification<PublishDiagnosticsParams>(DocumentNames.PublishDiagnostics, notification =>
3031
{
32+
if (notification.Diagnostics == null)
3133
if (notification.Diagnostics == null)
3234
return; // Invalid notification.
3335

src/Client/Clients/TextDocumentClient.Hover.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44
using OmniSharp.Extensions.LanguageServer.Client.Utilities;
5+
using OmniSharp.Extensions.LanguageServer.Protocol;
56
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
67

78
namespace OmniSharp.Extensions.LanguageServer.Client.Clients
@@ -59,7 +60,7 @@ public partial class TextDocumentClient
5960
/// </returns>
6061
public Task<Hover> Hover(Uri documentUri, int line, int column, CancellationToken cancellationToken = default(CancellationToken))
6162
{
62-
return PositionalRequest<Hover>("textDocument/hover", documentUri, line, column, cancellationToken);
63+
return PositionalRequest<Hover>(DocumentNames.Hover, documentUri, line, column, cancellationToken);
6364
}
6465
}
6566
}

src/Client/Clients/TextDocumentClient.Sync.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using OmniSharp.Extensions.LanguageServer.Client.Utilities;
4+
using OmniSharp.Extensions.LanguageServer.Protocol;
45
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
56

67
namespace OmniSharp.Extensions.LanguageServer.Client.Clients
@@ -87,7 +88,7 @@ public void DidOpen(Uri documentUri, string languageId, string text, int version
8788
if (documentUri == null)
8889
throw new ArgumentNullException(nameof(documentUri));
8990

90-
Client.SendNotification("textDocument/didOpen", new DidOpenTextDocumentParams
91+
Client.SendNotification(DocumentNames.DidOpen, new DidOpenTextDocumentParams
9192
{
9293
TextDocument = new TextDocumentItem
9394
{
@@ -184,7 +185,7 @@ public void DidChange(Uri documentUri, string languageId, string text, int versi
184185
if (documentUri == null)
185186
throw new ArgumentNullException(nameof(documentUri));
186187

187-
Client.SendNotification("textDocument/didChange", new DidChangeTextDocumentParams
188+
Client.SendNotification(DocumentNames.DidChange, new DidChangeTextDocumentParams
188189
{
189190
TextDocument = new VersionedTextDocumentIdentifier
190191
{
@@ -228,7 +229,7 @@ public void DidClose(Uri documentUri)
228229
if (documentUri == null)
229230
throw new ArgumentNullException(nameof(documentUri));
230231

231-
Client.SendNotification("textDocument/didClose", new DidCloseTextDocumentParams
232+
Client.SendNotification(DocumentNames.DidClose, new DidCloseTextDocumentParams
232233
{
233234
TextDocument = new TextDocumentItem
234235
{
@@ -264,7 +265,7 @@ public void DidSave(Uri documentUri)
264265
if (documentUri == null)
265266
throw new ArgumentNullException(nameof(documentUri));
266267

267-
Client.SendNotification("textDocument/didSave", new DidSaveTextDocumentParams
268+
Client.SendNotification(DocumentNames.DidSave, new DidSaveTextDocumentParams
268269
{
269270
TextDocument = new TextDocumentItem
270271
{

src/Client/Clients/WindowClient.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using OmniSharp.Extensions.LanguageServer.Protocol;
23
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
34

45
namespace OmniSharp.Extensions.LanguageServer.Client.Clients
@@ -41,7 +42,7 @@ public IDisposable OnLogMessage(LogMessageHandler handler)
4142
if (handler == null)
4243
throw new ArgumentNullException(nameof(handler));
4344

44-
return Client.HandleNotification<LogMessageParams>("window/logMessage",
45+
return Client.HandleNotification<LogMessageParams>(WindowNames.LogMessage,
4546
notification => handler(notification.Message, notification.Type)
4647
);
4748
}

src/Client/Clients/WorkspaceClient.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Newtonsoft.Json.Linq;
3+
using OmniSharp.Extensions.LanguageServer.Protocol;
34

45
namespace OmniSharp.Extensions.LanguageServer.Client.Clients
56
{
@@ -38,7 +39,7 @@ public void DidChangeConfiguration(JObject configuration)
3839
if (configuration == null)
3940
throw new ArgumentNullException(nameof(configuration));
4041

41-
Client.SendNotification("workspace/didChangeConfiguration", new JObject(
42+
Client.SendNotification(WorkspaceNames.DidChangeConfiguration, new JObject(
4243
new JProperty("settings", configuration)
4344
));
4445
}

src/Client/Dispatcher/LspDispatcher.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public IDisposable RegisterHandler(IHandler handler)
6060
/// </returns>
6161
public async Task<bool> TryHandleEmptyNotification(string method)
6262
{
63-
if (String.IsNullOrWhiteSpace(method))
63+
if (string.IsNullOrWhiteSpace(method))
6464
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
6565

6666
if (_handlers.TryGetValue(method, out IHandler handler) && handler is IInvokeEmptyNotificationHandler emptyNotificationHandler)
@@ -87,7 +87,7 @@ public async Task<bool> TryHandleEmptyNotification(string method)
8787
/// </returns>
8888
public async Task<bool> TryHandleNotification(string method, JObject notification)
8989
{
90-
if (String.IsNullOrWhiteSpace(method))
90+
if (string.IsNullOrWhiteSpace(method))
9191
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
9292

9393
if (_handlers.TryGetValue(method, out IHandler handler) && handler is IInvokeNotificationHandler notificationHandler)
@@ -117,7 +117,7 @@ public async Task<bool> TryHandleNotification(string method, JObject notificatio
117117
/// </returns>
118118
public Task<object> TryHandleRequest(string method, JObject request, CancellationToken cancellationToken)
119119
{
120-
if (String.IsNullOrWhiteSpace(method))
120+
if (string.IsNullOrWhiteSpace(method))
121121
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
122122

123123
if (_handlers.TryGetValue(method, out IHandler handler) && handler is IInvokeRequestHandler requestHandler)

src/Client/Dispatcher/LspDispatcherExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static IDisposable HandleEmptyNotification(this LspDispatcher clientDispa
2828
if (clientDispatcher == null)
2929
throw new ArgumentNullException(nameof(clientDispatcher));
3030

31-
if (String.IsNullOrWhiteSpace(method))
31+
if (string.IsNullOrWhiteSpace(method))
3232
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
3333

3434
if (handler == null)
@@ -62,7 +62,7 @@ public static IDisposable HandleNotification<TNotification>(this LspDispatcher c
6262
if (clientDispatcher == null)
6363
throw new ArgumentNullException(nameof(clientDispatcher));
6464

65-
if (String.IsNullOrWhiteSpace(method))
65+
if (string.IsNullOrWhiteSpace(method))
6666
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
6767

6868
if (handler == null)
@@ -96,7 +96,7 @@ public static IDisposable HandleRequest<TRequest>(this LspDispatcher clientDispa
9696
if (clientDispatcher == null)
9797
throw new ArgumentNullException(nameof(clientDispatcher));
9898

99-
if (String.IsNullOrWhiteSpace(method))
99+
if (string.IsNullOrWhiteSpace(method))
100100
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
101101

102102
if (handler == null)
@@ -133,7 +133,7 @@ public static IDisposable HandleRequest<TRequest, TResponse>(this LspDispatcher
133133
if (clientDispatcher == null)
134134
throw new ArgumentNullException(nameof(clientDispatcher));
135135

136-
if (String.IsNullOrWhiteSpace(method))
136+
if (string.IsNullOrWhiteSpace(method))
137137
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
138138

139139
if (handler == null)

src/Client/Exceptions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public LspRequestException(string message, string requestId)
9191
public LspRequestException(string message, string requestId, int errorCode)
9292
: base(message)
9393
{
94-
RequestId = !String.IsNullOrWhiteSpace(requestId) ? requestId : UnknownRequestId;
94+
RequestId = !string.IsNullOrWhiteSpace(requestId) ? requestId : UnknownRequestId;
9595
ErrorCode = errorCode;
9696
}
9797

@@ -130,7 +130,7 @@ public LspRequestException(string message, string requestId, Exception inner)
130130
public LspRequestException(string message, string requestId, int errorCode, Exception inner)
131131
: base(message, inner)
132132
{
133-
RequestId = !String.IsNullOrWhiteSpace(requestId) ? requestId : UnknownRequestId;
133+
RequestId = !string.IsNullOrWhiteSpace(requestId) ? requestId : UnknownRequestId;
134134
ErrorCode = errorCode;
135135
}
136136

@@ -202,7 +202,7 @@ public class LspMethodNotSupportedException
202202
public LspMethodNotSupportedException(string method, string requestId)
203203
: base($"Method not found: '{method}'.", requestId, LspErrorCodes.MethodNotSupported)
204204
{
205-
Method = !String.IsNullOrWhiteSpace(method) ? method : "(unknown)";
205+
Method = !string.IsNullOrWhiteSpace(method) ? method : "(unknown)";
206206
}
207207

208208
/// <summary>

src/Client/Handlers/DelegateHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public abstract class DelegateHandler
1616
/// </param>
1717
protected DelegateHandler(string method)
1818
{
19-
if (String.IsNullOrWhiteSpace(method))
19+
if (string.IsNullOrWhiteSpace(method))
2020
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
2121

2222
Method = method;

src/Client/Handlers/JsonRpcHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class JsonRpcHandler
1717
/// </param>
1818
protected JsonRpcHandler(string method)
1919
{
20-
if (String.IsNullOrWhiteSpace(method))
20+
if (string.IsNullOrWhiteSpace(method))
2121
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
2222

2323
Method = method;

src/Client/LanguageClientRegistration.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static IDisposable HandleNotification(this LanguageClient languageClient,
2929
if (languageClient == null)
3030
throw new ArgumentNullException(nameof(languageClient));
3131

32-
if (String.IsNullOrWhiteSpace(method))
32+
if (string.IsNullOrWhiteSpace(method))
3333
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
3434

3535
if (handler == null)
@@ -60,7 +60,7 @@ public static IDisposable HandleNotification(this LanguageClient languageClient,
6060
if (languageClient == null)
6161
throw new ArgumentNullException(nameof(languageClient));
6262

63-
if (String.IsNullOrWhiteSpace(method))
63+
if (string.IsNullOrWhiteSpace(method))
6464
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
6565

6666
if (handler == null)
@@ -95,7 +95,7 @@ public static IDisposable HandleNotification<TNotification>(this LanguageClient
9595
if (languageClient == null)
9696
throw new ArgumentNullException(nameof(languageClient));
9797

98-
if (String.IsNullOrWhiteSpace(method))
98+
if (string.IsNullOrWhiteSpace(method))
9999
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
100100

101101
if (handler == null)
@@ -129,7 +129,7 @@ public static IDisposable HandleNotification<TNotification>(this LanguageClient
129129
if (languageClient == null)
130130
throw new ArgumentNullException(nameof(languageClient));
131131

132-
if (String.IsNullOrWhiteSpace(method))
132+
if (string.IsNullOrWhiteSpace(method))
133133
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
134134

135135
if (handler == null)
@@ -163,7 +163,7 @@ public static IDisposable HandleRequest<TRequest>(this LanguageClient languageCl
163163
if (languageClient == null)
164164
throw new ArgumentNullException(nameof(languageClient));
165165

166-
if (String.IsNullOrWhiteSpace(method))
166+
if (string.IsNullOrWhiteSpace(method))
167167
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
168168

169169
if (handler == null)
@@ -200,7 +200,7 @@ public static IDisposable HandleRequest<TRequest, TResponse>(this LanguageClient
200200
if (languageClient == null)
201201
throw new ArgumentNullException(nameof(languageClient));
202202

203-
if (String.IsNullOrWhiteSpace(method))
203+
if (string.IsNullOrWhiteSpace(method))
204204
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
205205

206206
if (handler == null)

src/Client/Protocol/LspConnection.cs

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Diagnostics;
@@ -13,6 +13,7 @@
1313
using OmniSharp.Extensions.LanguageServer.Client.Dispatcher;
1414
using OmniSharp.Extensions.LanguageServer.Client.Handlers;
1515
using OmniSharp.Extensions.LanguageServer.Client.Logging;
16+
using OmniSharp.Extensions.LanguageServer.Protocol;
1617
using JsonRpcMessages = OmniSharp.Extensions.JsonRpc.Server.Messages;
1718

1819
namespace OmniSharp.Extensions.LanguageServer.Client.Protocol
@@ -293,7 +294,7 @@ public void Disconnect(bool flushOutgoing = false)
293294
/// </param>
294295
public void SendEmptyNotification(string method)
295296
{
296-
if (String.IsNullOrWhiteSpace(method))
297+
if (string.IsNullOrWhiteSpace(method))
297298
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
298299

299300
if (!IsOpen)
@@ -317,7 +318,7 @@ public void SendEmptyNotification(string method)
317318
/// </param>
318319
public void SendNotification(string method, object notification)
319320
{
320-
if (String.IsNullOrWhiteSpace(method))
321+
if (string.IsNullOrWhiteSpace(method))
321322
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
322323

323324
if (notification == null)
@@ -351,7 +352,7 @@ public void SendNotification(string method, object notification)
351352
/// </returns>
352353
public async Task SendRequest(string method, object request, CancellationToken cancellationToken = default(CancellationToken))
353354
{
354-
if (String.IsNullOrWhiteSpace(method))
355+
if (string.IsNullOrWhiteSpace(method))
355356
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
356357

357358
if (request == null)
@@ -374,7 +375,7 @@ public void SendNotification(string method, object notification)
374375
{
375376
_outgoing.TryAdd(new ClientMessage
376377
{
377-
Method = "$/cancelRequest",
378+
Method = GeneralNames.CancelRequest,
378379
Params = new JObject(
379380
new JProperty("id", requestId)
380381
)
@@ -414,7 +415,7 @@ public void SendNotification(string method, object notification)
414415
/// </returns>
415416
public async Task<TResponse> SendRequest<TResponse>(string method, object request, CancellationToken cancellationToken = default(CancellationToken))
416417
{
417-
if (String.IsNullOrWhiteSpace(method))
418+
if (string.IsNullOrWhiteSpace(method))
418419
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(method)}.", nameof(method));
419420

420421
if (request == null)
@@ -437,7 +438,7 @@ public void SendNotification(string method, object notification)
437438
{
438439
_outgoing.TryAdd(new ClientMessage
439440
{
440-
Method = "$/cancelRequest",
441+
Method = GeneralNames.CancelRequest,
441442
Params = new JObject(
442443
new JProperty("id", requestId)
443444
)
@@ -713,7 +714,7 @@ async Task<ServerMessage> ReceiveMessage()
713714
string headers = HeaderEncoding.GetString(headerBuffer, 0, bytesRead);
714715
Log.LogDebug("Got raw headers: {Headers}", headers);
715716

716-
if (String.IsNullOrWhiteSpace(headers))
717+
if (string.IsNullOrWhiteSpace(headers))
717718
return null; // Stream closed.
718719

719720
Log.LogDebug("Read response headers {Headers}.", headers);
@@ -806,7 +807,7 @@ async Task DispatchLoop()
806807
if (message.Id != null)
807808
{
808809
// Request.
809-
if (message.Method == "$/cancelRequest")
810+
if (message.Method == GeneralNames.CancelRequest)
810811
CancelRequest(message);
811812
else
812813
DispatchRequest(message);

0 commit comments

Comments
 (0)