Skip to content

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

Merged
merged 11 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion LSP.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.7
Expand Down Expand Up @@ -32,10 +32,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleServer", "sample\Samp
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{A316FCEC-81AD-45FB-93EE-C62CA09300DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "src\Client\Client.csproj", "{417E95B2-5AB9-49D5-B7CD-12255472E2E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client.Tests", "test\Client.Tests\Client.Tests.csproj", "{97437BE1-2EC3-4F6B-AC75-C3E099040A07}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -58,6 +66,30 @@ Global
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Release|Any CPU.Build.0 = Release|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x64.ActiveCfg = Debug|x64
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x64.Build.0 = Debug|x64
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x86.ActiveCfg = Debug|x86
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x86.Build.0 = Debug|x86
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|Any CPU.Build.0 = Release|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x64.ActiveCfg = Release|x64
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x64.Build.0 = Release|x64
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x86.ActiveCfg = Release|x86
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x86.Build.0 = Release|x86
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x64.ActiveCfg = Debug|x64
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x64.Build.0 = Debug|x64
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x86.ActiveCfg = Debug|x86
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x86.Build.0 = Debug|x86
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|Any CPU.Build.0 = Release|Any CPU
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x64.ActiveCfg = Release|x64
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x64.Build.0 = Release|x64
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x86.ActiveCfg = Release|x86
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -68,5 +100,7 @@ Global
{35F9B883-36D0-4F3B-A191-9BBD05B798A7} = {2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}
{482B180B-FD5C-4705-BBE1-094C905F1E1F} = {2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}
{F2067F5F-FA4E-4990-B301-E7898FC4C45F} = {A316FCEC-81AD-45FB-93EE-C62CA09300DC}
{417E95B2-5AB9-49D5-B7CD-12255472E2E7} = {D764E024-3D3F-4112-B932-2DB722A1BACC}
{97437BE1-2EC3-4F6B-AC75-C3E099040A07} = {2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions src/Client/Client.csproj
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" />
Copy link
Member

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.

Copy link
Collaborator Author

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 different ILogger<TComponent> to child components).

<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>
64 changes: 64 additions & 0 deletions src/Client/Clients/TextDocumentClient.Completions.cs
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Not a huge fan of nested usings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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);
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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))
Copy link
Member

Choose a reason for hiding this comment

The 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 filePath into this method. That would ensure that the string is a proper Uri.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good catch :)

{
return PositionalRequest<CompletionList>("textDocument/completion", documentUri, line, column, cancellationToken);
}
}
}
47 changes: 47 additions & 0 deletions src/Client/Clients/TextDocumentClient.Diagnostics.cs
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);
});
}
}
}
62 changes: 62 additions & 0 deletions src/Client/Clients/TextDocumentClient.Hover.cs
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);
}
}
}
Loading