-
Notifications
You must be signed in to change notification settings - Fork 105
Initial port of LSP client from tintoy/dotnet-language-client. #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
db0ee47
b8defce
5f4a15b
8b7de8c
e400183
1496e90
50f4e87
cd0c4e6
f16396f
52070bf
c87fd85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<AssemblyName>OmniSharp.Extensions.LanguageClient</AssemblyName> | ||
<RootNamespace>OmniSharp.Extensions.LanguageServerProtocol.Client</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> | ||
<PackageReference Include="Serilog" Version="2.5.0" /> | ||
<PackageReference Include="System.Reactive" Version="3.1.1" /> | ||
<PackageReference Include="System.ValueTuple" Version="4.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\JsonRpc\JsonRpc.csproj" /> | ||
<ProjectReference Include="..\Lsp\Lsp.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using OmniSharp.Extensions.LanguageServer.Models; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OmniSharp.Extensions.LanguageServerProtocol.Client.Clients | ||
{ | ||
using Utilities; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Not a huge fan of nested usings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem; I tend to use it as a reminder of which namespaces are from "my" code vs external code, but I'm happy to change this over. My rule is usually "match the style already used by the project" :) |
||
|
||
/// <summary> | ||
/// Client for the LSP Text Document API. | ||
/// </summary> | ||
public partial class TextDocumentClient | ||
{ | ||
/// <summary> | ||
/// Request completions at the specified document position. | ||
/// </summary> | ||
/// <param name="filePath"> | ||
/// The full file-system path of the text document. | ||
/// </param> | ||
/// <param name="line"> | ||
/// The target line (0-based). | ||
/// </param> | ||
/// <param name="column"> | ||
/// The target column (0-based). | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task{TResult}"/> that resolves to the completions or <c>null</c> if no completions are available at the specified position. | ||
/// </returns> | ||
public Task<CompletionList> Completions(string filePath, int line, int column, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
if (String.IsNullOrWhiteSpace(filePath)) | ||
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(filePath)}.", nameof(filePath)); | ||
|
||
return PositionalRequest<CompletionList>("textDocument/completion", filePath, line, column, cancellationToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. future: Now that the strings are showing up in more places we should probably add a static constants class somewhere. I'll add an issue for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I probably should have done this in the first place (even when my project was stand-alone) but haven't got around to it. |
||
} | ||
|
||
/// <summary> | ||
/// Request completions at the specified document position. | ||
/// </summary> | ||
/// <param name="documentUri"> | ||
/// The document URI. | ||
/// </param> | ||
/// <param name="line"> | ||
/// The target line (0-based). | ||
/// </param> | ||
/// <param name="column"> | ||
/// The target column (0-based). | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task{TResult}"/> that resolves to the completions or <c>null</c> if no completions are available at the specified position. | ||
/// </returns> | ||
public Task<CompletionList> Completions(Uri documentUri, int line, int column, CancellationToken cancellationToken = default(CancellationToken)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably make this a wrapper for the other method, and just pass documentUri as a string or better yet reverse it so that we pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, good catch :) |
||
{ | ||
return PositionalRequest<CompletionList>("textDocument/completion", documentUri, line, column, cancellationToken); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using OmniSharp.Extensions.LanguageServer.Models; | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OmniSharp.Extensions.LanguageServerProtocol.Client.Clients | ||
{ | ||
using System.Collections.Generic; | ||
using Utilities; | ||
|
||
/// <summary> | ||
/// Client for the LSP Text Document API. | ||
/// </summary> | ||
public partial class TextDocumentClient | ||
{ | ||
/// <summary> | ||
/// Register a handler for diagnostics published by the language server. | ||
/// </summary> | ||
/// <param name="handler"> | ||
/// A <see cref="PublishDiagnosticsHandler"/> that is called to publish the diagnostics. | ||
/// </param> | ||
/// <returns> | ||
/// An <see cref="IDisposable"/> representing the registration. | ||
/// </returns> | ||
/// <remarks> | ||
/// The diagnostics should replace any previously published diagnostics for the specified document. | ||
/// </remarks> | ||
public IDisposable OnPublishDiagnostics(PublishDiagnosticsHandler handler) | ||
{ | ||
if (handler == null) | ||
throw new ArgumentNullException(nameof(handler)); | ||
|
||
return Client.HandleNotification<PublishDiagnosticsParams>("textDocument/publishDiagnostics", notification => | ||
{ | ||
if (notification.Diagnostics == null) | ||
return; // Invalid notification. | ||
|
||
List<Diagnostic> diagnostics = new List<Diagnostic>(); | ||
if (notification.Diagnostics != null) | ||
diagnostics.AddRange(notification.Diagnostics); | ||
|
||
handler(notification.Uri, diagnostics); | ||
}); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using OmniSharp.Extensions.LanguageServer.Models; | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OmniSharp.Extensions.LanguageServerProtocol.Client.Clients | ||
{ | ||
using Utilities; | ||
|
||
/// <summary> | ||
/// Client for the LSP Text Document API. | ||
/// </summary> | ||
public partial class TextDocumentClient | ||
{ | ||
/// <summary> | ||
/// Request hover information at the specified document position. | ||
/// </summary> | ||
/// <param name="filePath"> | ||
/// The full file-system path of the text document. | ||
/// </param> | ||
/// <param name="line"> | ||
/// The target line (0-based). | ||
/// </param> | ||
/// <param name="column"> | ||
/// The target column (0-based). | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task{TResult}"/> that resolves to the hover information or <c>null</c> if no hover information is available at the specified position. | ||
/// </returns> | ||
public Task<Hover> Hover(string filePath, int line, int column, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
return PositionalRequest<Hover>("textDocument/hover", filePath, line, column, cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Request hover information at the specified document position. | ||
/// </summary> | ||
/// <param name="documentUri"> | ||
/// The document URI. | ||
/// </param> | ||
/// <param name="line"> | ||
/// The target line (0-based). | ||
/// </param> | ||
/// <param name="column"> | ||
/// The target column (0-based). | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task{TResult}"/> that resolves to the hover information or <c>null</c> if no hover information is available at the specified position. | ||
/// </returns> | ||
public Task<Hover> Hover(Uri documentUri, int line, int column, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
return PositionalRequest<Hover>("textDocument/hover", documentUri, line, column, cancellationToken); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hesitant to depend on
Serilog
by itself here, as I would generally prefer to not prescribe logging frameworks for consumers.However Serilog is a great logger, so I'm okay with it for now, and perhaps refactor it away (for MS.Extensions) in a future (breaking) change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reminder - I'm fine with changing over to MEL for logging, I just forgot about it :)
I'll modify them to take an
ILogger
/ILoggerFactory
instead (some components need to pass a differentILogger<TComponent>
to child components).