Skip to content

Commit 04aa637

Browse files
Fixed failing tests, disabled new generators for the moment, they can be re-done in the future
1 parent 73efad8 commit 04aa637

File tree

7 files changed

+92
-459
lines changed

7 files changed

+92
-459
lines changed

sample/SampleServer/SampleServer.csproj

+5-11
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,17 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<IsPackable>false</IsPackable>
6-
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<TargetFramework>net6.0</TargetFramework>
77
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
88
<LangVersion>latest</LangVersion>
99
</PropertyGroup>
1010

1111
<ItemGroup>
1212
<ProjectReference Include="../../src/Server/Server.csproj" />
13-
<PackageReference Include="Microsoft.Extensions.Logging" VersionOverride="3.0.0" />
14-
<PackageReference Include="Serilog.Extensions.Logging" VersionOverride="3.1.0" />
15-
<PackageReference Include="Serilog.Sinks.File" VersionOverride="5.0.0" />
16-
<PackageReference Include="Serilog.Sinks.Debug" VersionOverride="2.0.0" />
17-
<PackageReference Include="System.IO.FileSystem.Primitives" VersionOverride="4.3.0" />
18-
<PackageReference Include="System.IO" VersionOverride="4.3.0" />
19-
<PackageReference Include="System.Runtime.Handles" VersionOverride="4.3.0" />
20-
<PackageReference Include="System.Text.Encoding" VersionOverride="4.3.0" />
21-
<PackageReference Include="System.Text.Encoding.Extensions" VersionOverride="4.3.0" />
22-
<PackageReference Include="System.Threading.Tasks" VersionOverride="4.3.0" />
13+
<PackageReference Include="Microsoft.Extensions.Logging" />
14+
<PackageReference Include="Serilog.Extensions.Logging" />
15+
<PackageReference Include="Serilog.Sinks.File" />
16+
<PackageReference Include="Serilog.Sinks.Debug" />
2317
<PackageReference Include="Nerdbank.Streams" />
2418
</ItemGroup>
2519

sample/SampleServer/TextDocumentHandler.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public MyWorkspaceSymbolsHandler(IServerWorkDoneManager serverWorkDoneManager, I
146146
_logger = logger;
147147
}
148148

149-
public async Task<Container<SymbolInformation>> Handle(
149+
public async Task<Container<WorkspaceSymbol>> Handle(
150150
WorkspaceSymbolParams request,
151151
CancellationToken cancellationToken
152152
)
@@ -190,9 +190,8 @@ CancellationToken cancellationToken
190190

191191
partialResults.OnNext(
192192
new[] {
193-
new SymbolInformation {
193+
new WorkspaceSymbol {
194194
ContainerName = "Partial Container",
195-
Deprecated = true,
196195
Kind = SymbolKind.Constant,
197196
Location = new Location {
198197
Range = new Range(
@@ -221,15 +220,14 @@ CancellationToken cancellationToken
221220
);
222221

223222
partialResults.OnCompleted();
224-
return new SymbolInformation[] { };
223+
return new WorkspaceSymbol[] { };
225224
}
226225

227226
try
228227
{
229228
return new[] {
230-
new SymbolInformation {
229+
new WorkspaceSymbol {
231230
ContainerName = "Container",
232-
Deprecated = true,
233231
Kind = SymbolKind.Constant,
234232
Location = new Location {
235233
Range = new Range(

src/JsonRpc.Generators/GenerateHandlerMethodsGenerator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ private static ImmutableArray<ICompilationUnitGeneratorStrategy> GetCompilationU
207207
new OnRequestTypedResolveMethodGeneratorWithRegistrationOptionsStrategy(),
208208
// new OnRequestTypedMethodGeneratorWithRegistrationOptionsStrategy(),
209209
new SendMethodNotificationStrategy(),
210-
new SendMethodRequestStrategy(),
211-
new SendMethodTypedResolveRequestStrategy()
210+
new SendMethodRequestStrategy()/*,
211+
new SendMethodTypedResolveRequestStrategy()*/
212212
);
213213
var actionStrategies = ImmutableArray.Create<IExtensionMethodGeneratorStrategy>(
214214
new EnsureNamespaceStrategy(),

src/JsonRpc.Generators/GeneratorDiagnostics.cs

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ internal static class GeneratorDiagnostics
1010
"JRPC0001", "Exception",
1111
"{0} - {1} {2}", "JRPC", DiagnosticSeverity.Error, true
1212
);
13+
public static DiagnosticDescriptor ExceptionWarning { get; } = new DiagnosticDescriptor(
14+
"JRPC0002", "Exception",
15+
"{0} - {1} {2}", "JRPC", DiagnosticSeverity.Warning, true
16+
);
1317

1418
public static DiagnosticDescriptor NoHandlerRegistryProvided { get; } = new DiagnosticDescriptor(
1519
"JRPC1000", "No Handler Registry Provided",

src/JsonRpc.Generators/StronglyTypedGenerator.cs

+24-74
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3030
var attributes = context.CompilationProvider
3131
.Select(
3232
(compilation, _) => new AttributeData(
33-
compilation.GetTypeByMetadataName(
34-
"OmniSharp.Extensions.LanguageServer.Protocol.Generation.GenerateTypedDataAttribute"
35-
)!,
36-
compilation.GetTypeByMetadataName(
37-
"OmniSharp.Extensions.LanguageServer.Protocol.Generation.GenerateContainerAttribute"
38-
)!
39-
)
33+
compilation.GetTypeByMetadataName(
34+
"OmniSharp.Extensions.LanguageServer.Protocol.Generation.GenerateTypedDataAttribute"
35+
)!,
36+
compilation.GetTypeByMetadataName(
37+
"OmniSharp.Extensions.LanguageServer.Protocol.Generation.GenerateContainerAttribute"
38+
)!
39+
)
4040
);
4141

4242
var createContainersSyntaxProvider = context.SyntaxProvider.CreateSyntaxProvider(
@@ -74,16 +74,22 @@ TypeDeclarationSyntax typeDeclarationSyntax and (ClassDeclarationSyntax or Recor
7474
&& typeDeclarationSyntax.Members.OfType<PropertyDeclarationSyntax>().Any(z => z.Identifier.Text == "Data")
7575
&& typeDeclarationSyntax.BaseList.Types.Any(z => z.Type.GetSyntaxName() == "ICanHaveData"), (syntaxContext, _) => syntaxContext
7676
);
77-
77+
7878
context.RegisterSourceOutput(createContainersSyntaxProvider.Combine(attributes), GenerateContainerClass);
79-
context.RegisterSourceOutput(typedParamsCandidatesSyntaxProvider
80-
.Combine(canBeResolvedSyntaxProvider.Select((z, _) => (TypeDeclarationSyntax)z.Node).Collect())
81-
.Combine(canHaveDataSyntaxProvider.Select((z, _) => (TypeDeclarationSyntax)z.Node).Collect())
82-
.Combine(createContainersSyntaxProvider.Select((z, _) => (TypeDeclarationSyntax)z.Node).Collect())
83-
.Select((tuple, token) => (candidate: tuple.Left.Left.Left, resolvedItems: tuple.Left.Left.Right.Concat(tuple.Left.Right).Concat(tuple.Right).ToImmutableArray())),
84-
GenerateTypedParams);
8579
context.RegisterSourceOutput(canBeResolvedSyntaxProvider.Combine(attributes), GenerateCanBeResolvedClass);
8680
context.RegisterSourceOutput(canHaveDataSyntaxProvider.Combine(attributes), GenerateCanHaveDataClass);
81+
// TODO: Add support for generating handler methods and interfaces that take in the strongly typed data.
82+
// context.RegisterSourceOutput(
83+
// typedParamsCandidatesSyntaxProvider
84+
// .Combine(canBeResolvedSyntaxProvider.Select((z, _) => (TypeDeclarationSyntax)z.Node).Collect())
85+
// .Combine(canHaveDataSyntaxProvider.Select((z, _) => (TypeDeclarationSyntax)z.Node).Collect())
86+
// .Combine(createContainersSyntaxProvider.Select((z, _) => (TypeDeclarationSyntax)z.Node).Collect())
87+
// .Select(
88+
// (tuple, token) => ( candidate: tuple.Left.Left.Left,
89+
// resolvedItems: tuple.Left.Left.Right.Concat(tuple.Left.Right).Concat(tuple.Right).ToImmutableArray() )
90+
// ),
91+
// GenerateTypedParams
92+
// );
8793
}
8894

8995
private void GenerateContainerClass(SourceProductionContext context, (GeneratorSyntaxContext syntaxContext, AttributeData attributeData) valueTuple)
@@ -135,63 +141,6 @@ private void GenerateContainerClass(SourceProductionContext context, (GeneratorS
135141
);
136142
}
137143

138-
private void GenerateTypedParams(SourceProductionContext context, (GeneratorSyntaxContext syntaxContext, ImmutableArray<TypeDeclarationSyntax> resolvedItems) valueTuple)
139-
{
140-
var (syntaxContext, resolvedItems) = valueTuple;
141-
var classToContain = (TypeDeclarationSyntax)syntaxContext.Node;
142-
var typeSymbol = syntaxContext.SemanticModel.GetDeclaredSymbol(classToContain);
143-
144-
if (typeSymbol == null) return;
145-
var handlerInterface = typeSymbol.AllInterfaces.FirstOrDefault(z => z.Name == "IRequest" && z.Arity == 1);
146-
if (handlerInterface is null) return;
147-
var responseSymbol = handlerInterface?.TypeArguments[0];
148-
149-
var isTyped = resolvedItems
150-
.Any(
151-
item =>
152-
{
153-
var symbol = syntaxContext.SemanticModel.GetDeclaredSymbol(item);
154-
return symbol is not null && SymbolEqualityComparer.Default.Equals(responseSymbol, symbol);
155-
}
156-
);
157-
158-
// TODO: Start here to finish creating strongly typed params
159-
var paramsType = CreateContainerClass(classToContain, containerName)
160-
.AddAttributeLists(
161-
AttributeList(
162-
SeparatedList(
163-
new[]
164-
{
165-
Attribute(ParseName("System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute")),
166-
Attribute(ParseName("System.Runtime.CompilerServices.CompilerGeneratedAttribute"))
167-
}
168-
)
169-
)
170-
);
171-
172-
var cu = CompilationUnit()
173-
.WithUsings(classToContain.SyntaxTree.GetCompilationUnitRoot().Usings)
174-
.AddMembers(
175-
NamespaceDeclaration(ParseName(typeSymbol.ContainingNamespace.ToDisplayString()))
176-
.AddMembers(container)
177-
.WithLeadingTrivia(TriviaList(Trivia(NullableDirectiveTrivia(Token(SyntaxKind.EnableKeyword), true))))
178-
.WithTrailingTrivia(TriviaList(Trivia(NullableDirectiveTrivia(Token(SyntaxKind.RestoreKeyword), true))))
179-
);
180-
181-
foreach (var ns in RequiredUsings)
182-
{
183-
if (cu.Usings.All(z => z.Name.ToFullString() != ns))
184-
{
185-
cu = cu.AddUsings(UsingDirective(ParseName(ns)));
186-
}
187-
}
188-
189-
context.AddSource(
190-
$"{containerName ?? classToContain.Identifier.Text + "Container"}.cs",
191-
cu.NormalizeWhitespace().GetText(Encoding.UTF8)
192-
);
193-
}
194-
195144
private void GenerateCanBeResolvedClass(SourceProductionContext context, (GeneratorSyntaxContext syntaxContext, AttributeData attributeData) valueTuple)
196145
{
197146
var (syntaxContext, attributeData) = valueTuple;
@@ -226,7 +175,7 @@ private static void CreateTypedClass(
226175
INamedTypeSymbol? generateTypedDataAttributeSymbol,
227176
INamedTypeSymbol? generateContainerAttributeSymbol,
228177
bool includeHandlerIdentity
229-
)
178+
)
230179
{
231180
var attribute = typeSymbol?.GetAttributes()
232181
.FirstOrDefault(z => SymbolEqualityComparer.Default.Equals(z.AttributeClass, generateTypedDataAttributeSymbol));
@@ -295,13 +244,14 @@ bool includeHandlerIdentity
295244
if (container is { })
296245
{
297246
var containerName = container is { ConstructorArguments: { Length: > 0 } arguments } ? arguments[0].Value as string : null;
298-
247+
299248
var typedContainer = CreateContainerClass(typedClass, containerName)
300249
.WithHandlerIdentityConstraint(includeHandlerIdentity);
301250

302251
var typedArgumentList = TypeArgumentList(SingletonSeparatedList<TypeSyntax>(IdentifierName("T")));
303252

304-
if (!(container is { NamedArguments: { Length: > 0 } namedArguments } && namedArguments.FirstOrDefault(z => z.Key == "GenerateImplicitConversion") is { Value.Value: false }))
253+
if (!( container is { NamedArguments: { Length: > 0 } namedArguments }
254+
&& namedArguments.FirstOrDefault(z => z.Key == "GenerateImplicitConversion") is { Value.Value: false } ))
305255
{
306256
typedContainer = typedContainer
307257
.AddMembers(

src/Protocol/Serialization/Converters/NumberEnumConverter.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ internal class NumberEnumConverter : JsonConverter
99
{
1010
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => new JValue(value).WriteTo(writer);
1111

12-
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => Enum.Parse(
13-
Nullable.GetUnderlyingType(objectType) ?? objectType, reader.Value.ToString()
14-
);
12+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
13+
{
14+
if (reader.TokenType == JsonToken.Null) return null;
15+
return Enum.Parse(
16+
Nullable.GetUnderlyingType(objectType) ?? objectType, reader.Value.ToString()
17+
);
18+
}
1519

1620
public override bool CanRead => true;
1721

0 commit comments

Comments
 (0)