Skip to content

Commit fcc412f

Browse files
Initial commit. Work to do: Identify and update protocols for handling repsonses. Add interface to send notifications / request. Implement mapping between lsp protocols and such
0 parents  commit fcc412f

File tree

398 files changed

+10030
-0
lines changed

Some content is hidden

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

398 files changed

+10030
-0
lines changed

.editorconfig

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[*]
2+
end_of_line = crlf
3+
charset = utf-8
4+
indent_style = space
5+
indent_size = 4
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
9+
[*.xml]
10+
indent_style = space
11+
12+
[*.{cs,vb}]
13+
# Sort using and Import directives with System.* appearing first
14+
dotnet_sort_system_directives_first = true
15+
# Avoid "this." and "Me." if not necessary
16+
dotnet_style_qualification_for_event = false:warning
17+
dotnet_style_qualification_for_field = false:warning
18+
dotnet_style_qualification_for_method = false:warning
19+
dotnet_style_qualification_for_property = false:warning
20+
# Use language keywords instead of framework type names for type references
21+
dotnet_style_predefined_type_for_locals_parameters_members = true:error
22+
dotnet_style_predefined_type_for_member_access = true:error
23+
# Suggest more modern language features when available
24+
dotnet_style_coalesce_expression = true:error
25+
dotnet_style_collection_initializer = true:suggestion
26+
dotnet_style_explicit_tuple_names = true:error
27+
dotnet_style_null_propagation = true:warning
28+
dotnet_style_object_initializer = true:warning
29+
30+
# Naming Conventions:
31+
# Pascal Casing
32+
#dotnet_naming_symbols.method_and_property_symbols.applicable_kinds= method,property,enum
33+
#dotnet_naming_symbols.method_and_property_symbols.applicable_accessibilities = *
34+
#dotnet_naming_style.pascal_case_style.capitalization = pascal_case
35+
36+
[*.cs]
37+
csharp_style_conditional_delegate_call = true:suggestion
38+
csharp_style_expression_bodied_accessors = true:suggestion
39+
csharp_style_expression_bodied_constructors = true:none
40+
csharp_style_expression_bodied_indexers = true:none
41+
csharp_style_expression_bodied_methods = true:none
42+
csharp_style_expression_bodied_operators = true:none
43+
csharp_style_expression_bodied_properties = true:suggestion
44+
csharp_style_inlined_variable_declaration = true:error
45+
csharp_style_pattern_matching_over_as_with_null_check = true:error
46+
csharp_style_pattern_matching_over_is_with_cast_check = true:error
47+
csharp_style_throw_expression = true:suggestion
48+
csharp_style_var_elsewhere = true:warning
49+
csharp_style_var_for_built_in_types = true:warning
50+
csharp_style_var_when_type_is_apparent = true:error
51+
csharp_new_line_before_catch = true
52+
csharp_new_line_before_else = true
53+
csharp_new_line_before_finally = true
54+
csharp_new_line_before_members_in_anonymous_types = true
55+
csharp_new_line_before_open_brace = types,methods,properties,indexers,events,event_accessors,control_blocks,anonymous_types,object_collections,array_initializers,local_functions

.gitattributes

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
*.doc diff=astextplain
2+
*.DOC diff=astextplain
3+
*.docx diff=astextplain
4+
*.DOCX diff=astextplain
5+
*.dot diff=astextplain
6+
*.DOT diff=astextplain
7+
*.pdf diff=astextplain
8+
*.PDF diff=astextplain
9+
*.rtf diff=astextplain
10+
*.RTF diff=astextplain
11+
12+
*.jpg binary
13+
*.png binary
14+
*.gif binary
15+
16+
*.cs text=auto diff=csharp
17+
*.vb text=auto
18+
*.resx text=auto
19+
*.c text=auto
20+
*.cpp text=auto
21+
*.cxx text=auto
22+
*.h text=auto
23+
*.hxx text=auto
24+
*.py text=auto
25+
*.rb text=auto
26+
*.java text=auto
27+
*.html text=auto
28+
*.htm text=auto
29+
*.css text=auto
30+
*.scss text=auto
31+
*.sass text=auto
32+
*.less text=auto
33+
*.js text=auto
34+
*.lisp text=auto
35+
*.clj text=auto
36+
*.sql text=auto
37+
*.php text=auto
38+
*.lua text=auto
39+
*.m text=auto
40+
*.asm text=auto
41+
*.erl text=auto
42+
*.fs text=auto
43+
*.fsx text=auto
44+
*.hs text=auto
45+
46+
*.csproj text=auto
47+
*.vbproj text=auto
48+
*.fsproj text=auto
49+
*.dbproj text=auto
50+
*.xproj text=auto
51+
*.sln text=auto eol=crlf

.gitignore

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[Oo]bj/
2+
[Bb]in/
3+
TestResults/
4+
.nuget/
5+
*.sln.ide/
6+
_ReSharper.*/
7+
packages/**/
8+
artifacts/
9+
PublishProfiles/
10+
*.user
11+
*.suo
12+
*.cache
13+
*.docstates
14+
_ReSharper.*
15+
nuget.exe
16+
*net45.csproj
17+
*net451.csproj
18+
*k10.csproj
19+
*.psess
20+
*.vsp
21+
*.pidb
22+
*.userprefs
23+
*DS_Store
24+
*.ncrunchsolution
25+
*.*sdf
26+
*.ipch
27+
*.sln.ide
28+
debugSettings.json
29+
buildlog
30+
/.vs
31+
*.lock.json
32+
/omnisharp*.tar.gz
33+
scripts/Omnisharp*
34+
.msbuild-*/
35+
36+
# NuGet
37+
*.nuget.targets
38+
39+
# Build folder
40+
.tools/
41+
.dotnet/
42+
43+
# VS Code
44+
/.vscode/settings.json
45+
/.vscode/launch.json

LSP.sln

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26228.4
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D764E024-3D3F-4112-B932-2DB722A1BACC}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".config", ".config", "{AE4D7807-6F78-428C-A0D9-914BA583A104}"
11+
ProjectSection(SolutionItems) = preProject
12+
.editorconfig = .editorconfig
13+
EndProjectSection
14+
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonRpc", "src\JsonRpc\JsonRpc.csproj", "{EE777A17-24B6-499B-8E80-4F6D2750B4E4}"
16+
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lsp", "src\Lsp\Lsp.csproj", "{FDCFF5B0-D3BF-4E3C-B146-98CEE61DF55D}"
18+
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonRpc.Tests", "test\JsonRpc.Tests\JsonRpc.Tests.csproj", "{2E3DF5C2-8A38-4A03-86D7-8D463C917E47}"
20+
EndProject
21+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lsp.Tests", "test\Lsp.Tests\Lsp.Tests.csproj", "{54CDF265-B534-4493-BA8B-38AA8374A579}"
22+
EndProject
23+
Global
24+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
25+
Debug|Any CPU = Debug|Any CPU
26+
Release|Any CPU = Release|Any CPU
27+
EndGlobalSection
28+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
29+
{EE777A17-24B6-499B-8E80-4F6D2750B4E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{EE777A17-24B6-499B-8E80-4F6D2750B4E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{EE777A17-24B6-499B-8E80-4F6D2750B4E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{EE777A17-24B6-499B-8E80-4F6D2750B4E4}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{FDCFF5B0-D3BF-4E3C-B146-98CEE61DF55D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{FDCFF5B0-D3BF-4E3C-B146-98CEE61DF55D}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{FDCFF5B0-D3BF-4E3C-B146-98CEE61DF55D}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{FDCFF5B0-D3BF-4E3C-B146-98CEE61DF55D}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{2E3DF5C2-8A38-4A03-86D7-8D463C917E47}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{54CDF265-B534-4493-BA8B-38AA8374A579}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{54CDF265-B534-4493-BA8B-38AA8374A579}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{54CDF265-B534-4493-BA8B-38AA8374A579}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{54CDF265-B534-4493-BA8B-38AA8374A579}.Release|Any CPU.Build.0 = Release|Any CPU
45+
EndGlobalSection
46+
GlobalSection(SolutionProperties) = preSolution
47+
HideSolutionNode = FALSE
48+
EndGlobalSection
49+
GlobalSection(NestedProjects) = preSolution
50+
{EE777A17-24B6-499B-8E80-4F6D2750B4E4} = {D764E024-3D3F-4112-B932-2DB722A1BACC}
51+
{FDCFF5B0-D3BF-4E3C-B146-98CEE61DF55D} = {D764E024-3D3F-4112-B932-2DB722A1BACC}
52+
{2E3DF5C2-8A38-4A03-86D7-8D463C917E47} = {2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}
53+
{54CDF265-B534-4493-BA8B-38AA8374A579} = {2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}
54+
EndGlobalSection
55+
EndGlobal

src/JsonRpc/Client/Request.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
using Newtonsoft.Json.Serialization;
4+
5+
namespace JsonRPC.Client
6+
{
7+
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
8+
public class Request
9+
{
10+
public object Id { get; set; }
11+
12+
public string ProtocolVersion { get; set; } = "2.0";
13+
14+
public string Method { get; set; }
15+
16+
public object Params { get; set; }
17+
}
18+
}

src/JsonRpc/Connection.cs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using JsonRPC.Server;
6+
using Newtonsoft.Json;
7+
using Newtonsoft.Json.Linq;
8+
9+
namespace JsonRPC
10+
{
11+
public class Connection : IDisposable
12+
{
13+
private readonly TextReader _input;
14+
15+
private readonly TextWriter _output;
16+
17+
private readonly Reciever _reciever;
18+
private readonly Responder _responder;
19+
private InputHandler _inputHandler;
20+
private Mediater _mediater;
21+
22+
public Connection(TextReader input, TextWriter output)
23+
{
24+
_input = input;
25+
_output = output;
26+
_reciever = new Reciever();
27+
_responder = new Responder();
28+
_mediater = new Mediater();
29+
}
30+
31+
private async Task HandleRequest(JToken payload)
32+
{
33+
if (!_reciever.IsValid(payload))
34+
{
35+
_responder.Respond(new InvalidRequest());
36+
return;
37+
}
38+
39+
var requests = _reciever.GetRequests(payload);
40+
await _mediater.RespondTo(requests);
41+
}
42+
43+
public void Open()
44+
{
45+
_inputHandler = new InputHandler(_input, async (payload) => await HandleRequest(payload));
46+
}
47+
48+
public void Dispose()
49+
{
50+
_inputHandler?.Dispose();
51+
}
52+
}
53+
}

src/JsonRpc/INotificationHandler.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Threading.Tasks;
2+
3+
namespace JsonRPC
4+
{
5+
public interface INotificationHandler<TNotification>
6+
{
7+
Task Handle(TNotification notification);
8+
}
9+
}

src/JsonRpc/IRequestHandler.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Threading.Tasks;
2+
3+
namespace JsonRPC
4+
{
5+
public interface IRequestHandler<TRequest, TResponse>
6+
{
7+
Task<TResponse> Handle(TRequest request);
8+
}
9+
}

src/JsonRpc/InputHandler.cs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Newtonsoft.Json.Linq;
7+
8+
namespace JsonRPC
9+
{
10+
public class InputHandler : IDisposable
11+
{
12+
public const char CR = '\r';
13+
public const char LF = '\n';
14+
public static char[] CRLF = { CR, LF };
15+
public static char[] HeaderKeys = { CR, LF, ':' };
16+
public const short MinBuffer = 21; // Minimum size of the buffer "Content-Length: X\r\n\r\n"
17+
18+
private readonly TextReader _input;
19+
private readonly Action<JToken> _inputHandler;
20+
private readonly Thread _thread;
21+
22+
public InputHandler(TextReader input, Action<JToken> inputHandler)
23+
{
24+
_input = input;
25+
_inputHandler = inputHandler;
26+
27+
_thread = new Thread(async () => await Loop()) {
28+
IsBackground = true,
29+
Priority = ThreadPriority.AboveNormal
30+
};
31+
_thread.Start();
32+
}
33+
34+
private async Task Loop()
35+
{
36+
while (true)
37+
{
38+
var buffer = new char[200];
39+
var current = await _input.ReadBlockAsync(buffer, 0, MinBuffer);
40+
while (current < MinBuffer || buffer[current - 4] != CR || buffer[current - 3] != LF ||
41+
buffer[current - 2] != CR || buffer[current - 1] != LF)
42+
{
43+
current += await _input.ReadBlockAsync(buffer, 0, 1);
44+
}
45+
46+
var headersContent = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(buffer, 0, current));
47+
var headers = headersContent.Split(HeaderKeys, StringSplitOptions.RemoveEmptyEntries);
48+
long length = 0;
49+
for (var i = 0; i < headers.Length; i += 2)
50+
{
51+
var header = headers[0];
52+
var value = headers[i + 1].Trim();
53+
if (header.Equals("Content-Length", StringComparison.OrdinalIgnoreCase))
54+
{
55+
length = long.Parse(value);
56+
}
57+
}
58+
59+
var requestBuffer = new char[length];
60+
61+
await _input.ReadBlockAsync(requestBuffer, 0, requestBuffer.Length);
62+
63+
var request = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(requestBuffer));
64+
var payload = JToken.Parse(request);
65+
_inputHandler(payload);
66+
}
67+
}
68+
69+
public void Dispose()
70+
{
71+
_thread.Abort();
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)