Skip to content

Commit

Permalink
Merge pull request #43 from tintoy/feature/language-client
Browse files Browse the repository at this point in the history
Initial port of LSP client from tintoy/dotnet-language-client.
  • Loading branch information
david-driscoll authored Nov 15, 2017
2 parents 772397d + c87fd85 commit fe0a81a
Show file tree
Hide file tree
Showing 48 changed files with 5,307 additions and 3 deletions.
82 changes: 79 additions & 3 deletions LSP.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.7
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D764E024-3D3F-4112-B932-2DB722A1BACC}"
EndProject
Expand All @@ -28,36 +27,108 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonRpc.Tests", "test\JsonR
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lsp.Tests", "test\Lsp.Tests\Lsp.Tests.csproj", "{482B180B-FD5C-4705-BBE1-094C905F1E1F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleServer", "sample\SampleServer\SampleServer.csproj", "{F2067F5F-FA4E-4990-B301-E7898FC4C45F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleServer", "sample\SampleServer\SampleServer.csproj", "{F2067F5F-FA4E-4990-B301-E7898FC4C45F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{A316FCEC-81AD-45FB-93EE-C62CA09300DC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "src\Client\Client.csproj", "{417E95B2-5AB9-49D5-B7CD-12255472E2E7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client.Tests", "test\Client.Tests\Client.Tests.csproj", "{97437BE1-2EC3-4F6B-AC75-C3E099040A07}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Debug|x64.ActiveCfg = Debug|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Debug|x64.Build.0 = Debug|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Debug|x86.ActiveCfg = Debug|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Debug|x86.Build.0 = Debug|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Release|Any CPU.Build.0 = Release|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Release|x64.ActiveCfg = Release|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Release|x64.Build.0 = Release|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Release|x86.ActiveCfg = Release|Any CPU
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Release|x86.Build.0 = Release|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Debug|x64.ActiveCfg = Debug|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Debug|x64.Build.0 = Debug|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Debug|x86.ActiveCfg = Debug|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Debug|x86.Build.0 = Debug|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Release|Any CPU.Build.0 = Release|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Release|x64.ActiveCfg = Release|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Release|x64.Build.0 = Release|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Release|x86.ActiveCfg = Release|Any CPU
{50EA648A-67D3-4127-9517-EC7C1426E2E7}.Release|x86.Build.0 = Release|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Debug|x64.ActiveCfg = Debug|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Debug|x64.Build.0 = Debug|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Debug|x86.ActiveCfg = Debug|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Debug|x86.Build.0 = Debug|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Release|Any CPU.Build.0 = Release|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Release|x64.ActiveCfg = Release|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Release|x64.Build.0 = Release|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Release|x86.ActiveCfg = Release|Any CPU
{35F9B883-36D0-4F3B-A191-9BBD05B798A7}.Release|x86.Build.0 = Release|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Debug|x64.ActiveCfg = Debug|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Debug|x64.Build.0 = Debug|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Debug|x86.ActiveCfg = Debug|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Debug|x86.Build.0 = Debug|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Release|Any CPU.Build.0 = Release|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Release|x64.ActiveCfg = Release|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Release|x64.Build.0 = Release|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Release|x86.ActiveCfg = Release|Any CPU
{482B180B-FD5C-4705-BBE1-094C905F1E1F}.Release|x86.Build.0 = Release|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Debug|x64.ActiveCfg = Debug|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Debug|x64.Build.0 = Debug|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Debug|x86.ActiveCfg = Debug|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Debug|x86.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
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Release|x64.ActiveCfg = Release|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Release|x64.Build.0 = Release|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Release|x86.ActiveCfg = Release|Any CPU
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Release|x86.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|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x64.Build.0 = Debug|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x86.ActiveCfg = Debug|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x86.Build.0 = Debug|Any CPU
{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|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x64.Build.0 = Release|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x86.ActiveCfg = Release|Any CPU
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x86.Build.0 = Release|Any CPU
{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|Any CPU
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x64.Build.0 = Debug|Any CPU
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x86.ActiveCfg = Debug|Any CPU
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x86.Build.0 = Debug|Any CPU
{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|Any CPU
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x64.Build.0 = Release|Any CPU
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x86.ActiveCfg = Release|Any CPU
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -68,5 +139,10 @@ 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
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D38DD0EC-D095-4BCD-B8AF-2D788AF3B9AE}
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="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>
65 changes: 65 additions & 0 deletions src/Client/Clients/TextDocumentClient.Completions.cs
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);
}
}
}
45 changes: 45 additions & 0 deletions src/Client/Clients/TextDocumentClient.Diagnostics.cs
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);
});
}
}
}
66 changes: 66 additions & 0 deletions src/Client/Clients/TextDocumentClient.Hover.cs
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);
}
}
}
Loading

0 comments on commit fe0a81a

Please sign in to comment.