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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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>

0 commit comments

Comments
 (0)