-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from tintoy/feature/language-client
Initial port of LSP client from tintoy/dotnet-language-client.
- Loading branch information
Showing
48 changed files
with
5,307 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="Microsoft.Extensions.Logging.Abstractions" Version="1.0.2" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using OmniSharp.Extensions.LanguageServer.Models; | ||
using OmniSharp.Extensions.LanguageServerProtocol.Client.Utilities; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OmniSharp.Extensions.LanguageServerProtocol.Client.Clients | ||
{ | ||
/// <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)); | ||
|
||
Uri documentUri = DocumentUri.FromFileSystemPath(filePath); | ||
|
||
return Completions(documentUri, line, column, cancellationToken); | ||
} | ||
|
||
/// <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)) | ||
{ | ||
return PositionalRequest<CompletionList>("textDocument/completion", documentUri, line, column, cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using OmniSharp.Extensions.LanguageServer.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace OmniSharp.Extensions.LanguageServerProtocol.Client.Clients | ||
{ | ||
/// <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); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using OmniSharp.Extensions.LanguageServer.Models; | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OmniSharp.Extensions.LanguageServerProtocol.Client.Utilities; | ||
|
||
namespace OmniSharp.Extensions.LanguageServerProtocol.Client.Clients | ||
{ | ||
/// <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)) | ||
{ | ||
if (String.IsNullOrWhiteSpace(filePath)) | ||
throw new ArgumentException("Argument cannot be null, empty, or entirely composed of whitespace: 'filePath'.", nameof(filePath)); | ||
|
||
Uri documentUri = DocumentUri.FromFileSystemPath(filePath); | ||
|
||
return Hover(documentUri, 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); | ||
} | ||
} | ||
} |
Oops, something went wrong.