Skip to content
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

Add response types and improve test suite #243

Merged
merged 8 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 24 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
version: 2
updates:
- package-ecosystem: "github-actions"
- package-ecosystem: 'github-actions'
directory: /
schedule:
interval: monthly
labels:
- "no-changelog"
- 'no-changelog'

- package-ecosystem: "pip"
- package-ecosystem: 'github-actions'
directory: .github/actions/lint
schedule:
interval: monthly
labels:
- 'no-changelog'

- package-ecosystem: 'github-actions'
directory: .github/actions/build-package
schedule:
interval: monthly
labels:
- 'no-changelog'

- package-ecosystem: 'pip'
directory: /generator
schedule:
interval: daily
labels:
- "no-changelog"
- 'no-changelog'

- package-ecosystem: "pip"
- package-ecosystem: 'pip'
directory: /tests
schedule:
interval: daily
labels:
- "no-changelog"
- 'no-changelog'

- package-ecosystem: "pip"
- package-ecosystem: 'pip'
directory: /
schedule:
interval: daily
labels:
- "debt"
- 'debt'
commit-message:
include: "scope"
prefix: "pip"
include: 'scope'
prefix: 'pip'
4 changes: 4 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ jobs:
- name: Generate C# Code
run: python -m generator --plugin dotnet

- name: Dotnet Build Tests
run: dotnet build tests/dotnet/lsprotocol_tests/lsprotocol_tests.csproj
shell: bash

- name: Dotnet Run Tests
run: dotnet test tests/dotnet/lsprotocol_tests/lsprotocol_tests.csproj
shell: bash
Expand Down
6 changes: 3 additions & 3 deletions generator/plugins/dotnet/custom/IResponse.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
public interface IResponse<TResponse> : IMessage
{

OrType<int, string> Id { get; }
OrType<string, int> Id { get; }

TResponse Result { get; }
TResponse? Result { get; }

IResponseError? Error { get; }
ResponseError? Error { get; }
}
9 changes: 0 additions & 9 deletions generator/plugins/dotnet/custom/IResponseError.cs

This file was deleted.

22 changes: 22 additions & 0 deletions generator/plugins/dotnet/custom/LSPRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

[AttributeUsage(AttributeTargets.Class)]
public class LSPRequestAttribute : Attribute
{
public LSPRequestAttribute(string method, Type response)
{
Method = method;
Response = response;
}

public LSPRequestAttribute(string method, Type response, Type partialResponse)
{
Method = method;
Response = response;
PartialResponse = partialResponse;
}

public string Method { get; }
public Type Response { get; }
public Type? PartialResponse { get; }
}
13 changes: 13 additions & 0 deletions generator/plugins/dotnet/custom/LSPResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

[AttributeUsage(AttributeTargets.Class)]
public class LSPResponseAttribute : Attribute
{
public LSPResponseAttribute(Type request)
{
Request = request;
}


public Type Request { get; }
}
44 changes: 23 additions & 21 deletions generator/plugins/dotnet/custom/OrTypeArrayConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@
using System;


public class OrTypeArrayConverter<T, U, V, W> : JsonConverter<OrType<T, U, V, W>[]>
public class OrTypeArrayConverter<T, U> : JsonConverter<OrType<T, U>[]>
{
private OrTypeConverter<T, U, V, W> _converter;
private OrTypeConverter<T, U> _converter;

public OrTypeArrayConverter()
{
_converter = new OrTypeConverter<T, U, V, W>();
_converter = new OrTypeConverter<T, U>();
}

public override OrType<T, U, V, W>[] ReadJson(JsonReader reader, Type objectType, OrType<T, U, V, W>[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
public override OrType<T, U>[] ReadJson(JsonReader reader, Type objectType, OrType<T, U>[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}

JArray array = JArray.Load(reader);
var result = new OrType<T, U, V, W>[array.Count];
var result = new OrType<T, U>[array.Count];

for (int i = 0; i < array.Count; i++)
{
result[i] = (OrType<T, U, V, W>)_converter.ReadJson(array[i].CreateReader(), typeof(OrType<T, U, V, W>), null, serializer);
result[i] = (OrType<T, U>)_converter.ReadJson(array[i].CreateReader(), typeof(OrType<T, U>), null, serializer);
}

return result;
}

public override void WriteJson(JsonWriter writer, OrType<T, U, V, W>[] value, JsonSerializer serializer)
public override void WriteJson(JsonWriter writer, OrType<T, U>[]? value, JsonSerializer serializer)
{
if (value is null)
{
Expand All @@ -49,34 +49,34 @@ public override void WriteJson(JsonWriter writer, OrType<T, U, V, W>[] value, Js
}
}
}
public class OrTypeArrayConverter<T, U> : JsonConverter<OrType<T, U>[]>
public class OrTypeArrayConverter<T, U, V> : JsonConverter<OrType<T, U, V>[]>
{
private OrTypeConverter<T, U> _converter;
private OrTypeConverter<T, U, V> _converter;

public OrTypeArrayConverter()
{
_converter = new OrTypeConverter<T, U>();
_converter = new OrTypeConverter<T, U, V>();
}

public override OrType<T, U>[] ReadJson(JsonReader reader, Type objectType, OrType<T, U>[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
public override OrType<T, U, V>[] ReadJson(JsonReader reader, Type objectType, OrType<T, U, V>[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}

JArray array = JArray.Load(reader);
var result = new OrType<T, U>[array.Count];
var result = new OrType<T, U, V>[array.Count];

for (int i = 0; i < array.Count; i++)
{
result[i] = (OrType<T, U>)_converter.ReadJson(array[i].CreateReader(), typeof(OrType<T, U>), null, serializer);
result[i] = (OrType<T, U, V>)_converter.ReadJson(array[i].CreateReader(), typeof(OrType<T, U, V>), null, serializer);
}

return result;
}

public override void WriteJson(JsonWriter writer, OrType<T, U>[] value, JsonSerializer serializer)
public override void WriteJson(JsonWriter writer, OrType<T, U, V>[]? value, JsonSerializer serializer)
{
if (value is null)
{
Expand All @@ -95,34 +95,36 @@ public override void WriteJson(JsonWriter writer, OrType<T, U>[] value, JsonSeri
}
}
}
public class OrTypeArrayConverter<T, U, V> : JsonConverter<OrType<T, U, V>[]>


public class OrTypeArrayConverter<T, U, V, W> : JsonConverter<OrType<T, U, V, W>[]>
{
private OrTypeConverter<T, U, V> _converter;
private OrTypeConverter<T, U, V, W> _converter;

public OrTypeArrayConverter()
{
_converter = new OrTypeConverter<T, U, V>();
_converter = new OrTypeConverter<T, U, V, W>();
}

public override OrType<T, U, V>[] ReadJson(JsonReader reader, Type objectType, OrType<T, U, V>[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
public override OrType<T, U, V, W>[] ReadJson(JsonReader reader, Type objectType, OrType<T, U, V, W>[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}

JArray array = JArray.Load(reader);
var result = new OrType<T, U, V>[array.Count];
var result = new OrType<T, U, V, W>[array.Count];

for (int i = 0; i < array.Count; i++)
{
result[i] = (OrType<T, U, V>)_converter.ReadJson(array[i].CreateReader(), typeof(OrType<T, U, V>), null, serializer);
result[i] = (OrType<T, U, V, W>)_converter.ReadJson(array[i].CreateReader(), typeof(OrType<T, U, V, W>), null, serializer);
}

return result;
}

public override void WriteJson(JsonWriter writer, OrType<T, U, V>[] value, JsonSerializer serializer)
public override void WriteJson(JsonWriter writer, OrType<T, U, V, W>[]? value, JsonSerializer serializer)
{
if (value is null)
{
Expand Down
Loading