Skip to content

Commit db0ee47

Browse files
committed
Initial port of LSP client from tintoy/dotnet-language-client.
1 parent 80e1b38 commit db0ee47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5244
-1
lines changed

LSP.sln

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.26403.7
@@ -32,10 +32,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleServer", "sample\Samp
3232
EndProject
3333
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{A316FCEC-81AD-45FB-93EE-C62CA09300DC}"
3434
EndProject
35+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "src\Client\Client.csproj", "{417E95B2-5AB9-49D5-B7CD-12255472E2E7}"
36+
EndProject
37+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client.Tests", "test\Client.Tests\Client.Tests.csproj", "{97437BE1-2EC3-4F6B-AC75-C3E099040A07}"
38+
EndProject
3539
Global
3640
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3741
Debug|Any CPU = Debug|Any CPU
3842
Release|Any CPU = Release|Any CPU
43+
Debug|x64 = Debug|x64
44+
Debug|x86 = Debug|x86
45+
Release|x64 = Release|x64
46+
Release|x86 = Release|x86
3947
EndGlobalSection
4048
GlobalSection(ProjectConfigurationPlatforms) = postSolution
4149
{9AF43FA2-EF35-435E-B59E-724877E44DDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -58,6 +66,30 @@ Global
5866
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Debug|Any CPU.Build.0 = Debug|Any CPU
5967
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Release|Any CPU.ActiveCfg = Release|Any CPU
6068
{F2067F5F-FA4E-4990-B301-E7898FC4C45F}.Release|Any CPU.Build.0 = Release|Any CPU
69+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
70+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
71+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x64.ActiveCfg = Debug|x64
72+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x64.Build.0 = Debug|x64
73+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x86.ActiveCfg = Debug|x86
74+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Debug|x86.Build.0 = Debug|x86
75+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
76+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|Any CPU.Build.0 = Release|Any CPU
77+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x64.ActiveCfg = Release|x64
78+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x64.Build.0 = Release|x64
79+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x86.ActiveCfg = Release|x86
80+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7}.Release|x86.Build.0 = Release|x86
81+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
82+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|Any CPU.Build.0 = Debug|Any CPU
83+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x64.ActiveCfg = Debug|x64
84+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x64.Build.0 = Debug|x64
85+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x86.ActiveCfg = Debug|x86
86+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Debug|x86.Build.0 = Debug|x86
87+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|Any CPU.ActiveCfg = Release|Any CPU
88+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|Any CPU.Build.0 = Release|Any CPU
89+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x64.ActiveCfg = Release|x64
90+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x64.Build.0 = Release|x64
91+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x86.ActiveCfg = Release|x86
92+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07}.Release|x86.Build.0 = Release|x86
6193
EndGlobalSection
6294
GlobalSection(SolutionProperties) = preSolution
6395
HideSolutionNode = FALSE
@@ -68,5 +100,7 @@ Global
68100
{35F9B883-36D0-4F3B-A191-9BBD05B798A7} = {2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}
69101
{482B180B-FD5C-4705-BBE1-094C905F1E1F} = {2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}
70102
{F2067F5F-FA4E-4990-B301-E7898FC4C45F} = {A316FCEC-81AD-45FB-93EE-C62CA09300DC}
103+
{417E95B2-5AB9-49D5-B7CD-12255472E2E7} = {D764E024-3D3F-4112-B932-2DB722A1BACC}
104+
{97437BE1-2EC3-4F6B-AC75-C3E099040A07} = {2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}
71105
EndGlobalSection
72106
EndGlobal

src/Client/Client.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
5+
<PlatformTarget>AnyCPU</PlatformTarget>
6+
<AssemblyName>OmniSharp.Extensions.LanguageClient</AssemblyName>
7+
<RootNamespace>OmniSharp.Extensions.LanguageClient</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
12+
<PackageReference Include="Serilog" Version="2.5.0" />
13+
<PackageReference Include="System.Reactive" Version="3.1.1" />
14+
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\JsonRpc\JsonRpc.csproj" />
19+
<ProjectReference Include="..\Lsp\Lsp.csproj" />
20+
</ItemGroup>
21+
</Project>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using OmniSharp.Extensions.LanguageServer.Models;
2+
using System;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
namespace OmniSharp.Extensions.LanguageServerProtocol.Client.Clients
7+
{
8+
using Utilities;
9+
10+
/// <summary>
11+
/// Client for the LSP Text Document API.
12+
/// </summary>
13+
public partial class TextDocumentClient
14+
{
15+
/// <summary>
16+
/// Request completions at the specified document position.
17+
/// </summary>
18+
/// <param name="filePath">
19+
/// The full file-system path of the text document.
20+
/// </param>
21+
/// <param name="line">
22+
/// The target line (0-based).
23+
/// </param>
24+
/// <param name="column">
25+
/// The target column (0-based).
26+
/// </param>
27+
/// <param name="cancellationToken">
28+
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
29+
/// </param>
30+
/// <returns>
31+
/// A <see cref="Task{TResult}"/> that resolves to the completions or <c>null</c> if no completions are available at the specified position.
32+
/// </returns>
33+
public Task<CompletionList> Completions(string filePath, int line, int column, CancellationToken cancellationToken = default(CancellationToken))
34+
{
35+
if (String.IsNullOrWhiteSpace(filePath))
36+
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(filePath)}.", nameof(filePath));
37+
38+
return PositionalRequest<CompletionList>("textDocument/completion", filePath, line, column, cancellationToken);
39+
}
40+
41+
/// <summary>
42+
/// Request completions at the specified document position.
43+
/// </summary>
44+
/// <param name="documentUri">
45+
/// The document URI.
46+
/// </param>
47+
/// <param name="line">
48+
/// The target line (0-based).
49+
/// </param>
50+
/// <param name="column">
51+
/// The target column (0-based).
52+
/// </param>
53+
/// <param name="cancellationToken">
54+
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
55+
/// </param>
56+
/// <returns>
57+
/// A <see cref="Task{TResult}"/> that resolves to the completions or <c>null</c> if no completions are available at the specified position.
58+
/// </returns>
59+
public Task<CompletionList> Completions(Uri documentUri, int line, int column, CancellationToken cancellationToken = default(CancellationToken))
60+
{
61+
return PositionalRequest<CompletionList>("textDocument/completion", documentUri, line, column, cancellationToken);
62+
}
63+
}
64+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using OmniSharp.Extensions.LanguageServer.Models;
2+
using System;
3+
using System.IO;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace OmniSharp.Extensions.LanguageServerProtocol.Client.Clients
8+
{
9+
using System.Collections.Generic;
10+
using Utilities;
11+
12+
/// <summary>
13+
/// Client for the LSP Text Document API.
14+
/// </summary>
15+
public partial class TextDocumentClient
16+
{
17+
/// <summary>
18+
/// Register a handler for diagnostics published by the language server.
19+
/// </summary>
20+
/// <param name="handler">
21+
/// A <see cref="PublishDiagnosticsHandler"/> that is called to publish the diagnostics.
22+
/// </param>
23+
/// <returns>
24+
/// An <see cref="IDisposable"/> representing the registration.
25+
/// </returns>
26+
/// <remarks>
27+
/// The diagnostics should replace any previously published diagnostics for the specified document.
28+
/// </remarks>
29+
public IDisposable OnPublishDiagnostics(PublishDiagnosticsHandler handler)
30+
{
31+
if (handler == null)
32+
throw new ArgumentNullException(nameof(handler));
33+
34+
return Client.HandleNotification<PublishDiagnosticsParams>("textDocument/publishDiagnostics", notification =>
35+
{
36+
if (notification.Diagnostics == null)
37+
return; // Invalid notification.
38+
39+
List<Diagnostic> diagnostics = new List<Diagnostic>();
40+
if (notification.Diagnostics != null)
41+
diagnostics.AddRange(notification.Diagnostics);
42+
43+
handler(notification.Uri, diagnostics);
44+
});
45+
}
46+
}
47+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using OmniSharp.Extensions.LanguageServer.Models;
2+
using System;
3+
using System.IO;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace OmniSharp.Extensions.LanguageServerProtocol.Client.Clients
8+
{
9+
using Utilities;
10+
11+
/// <summary>
12+
/// Client for the LSP Text Document API.
13+
/// </summary>
14+
public partial class TextDocumentClient
15+
{
16+
/// <summary>
17+
/// Request hover information at the specified document position.
18+
/// </summary>
19+
/// <param name="filePath">
20+
/// The full file-system path of the text document.
21+
/// </param>
22+
/// <param name="line">
23+
/// The target line (0-based).
24+
/// </param>
25+
/// <param name="column">
26+
/// The target column (0-based).
27+
/// </param>
28+
/// <param name="cancellationToken">
29+
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
30+
/// </param>
31+
/// <returns>
32+
/// 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.
33+
/// </returns>
34+
public Task<Hover> Hover(string filePath, int line, int column, CancellationToken cancellationToken = default(CancellationToken))
35+
{
36+
return PositionalRequest<Hover>("textDocument/hover", filePath, line, column, cancellationToken);
37+
}
38+
39+
/// <summary>
40+
/// Request hover information at the specified document position.
41+
/// </summary>
42+
/// <param name="documentUri">
43+
/// The document URI.
44+
/// </param>
45+
/// <param name="line">
46+
/// The target line (0-based).
47+
/// </param>
48+
/// <param name="column">
49+
/// The target column (0-based).
50+
/// </param>
51+
/// <param name="cancellationToken">
52+
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request.
53+
/// </param>
54+
/// <returns>
55+
/// 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.
56+
/// </returns>
57+
public Task<Hover> Hover(Uri documentUri, int line, int column, CancellationToken cancellationToken = default(CancellationToken))
58+
{
59+
return PositionalRequest<Hover>("textDocument/hover", documentUri, line, column, cancellationToken);
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)