Skip to content

Commit 1c1117d

Browse files
Added new FileOperations and updated to work with latest annotations (#470)
* Added new FileOperations and updated to work with latest annotations * updated sha reference * prevent send from throwing * Change how partial results are handled (ForkJoin vs Amb). this should help with the race condition where the request 'finishes' first but was handled partially, and therefore returns no results
1 parent 9cadf26 commit 1c1117d

File tree

76 files changed

+1336
-433
lines changed

Some content is hidden

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

76 files changed

+1336
-433
lines changed

language-server-protocol.sha.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-- This is the last commit we caught up with https://github.com/Microsoft/language-server-protocol/commits/gh-pages
2-
lastSha: c485961250d0eb41e53b148b55262ec180b63273
2+
lastSha: bdcc0f2
33

4-
https://github.com/Microsoft/language-server-protocol/compare/c485961250d0eb41e53b148b55262ec180b63273..gh-pages
4+
https://github.com/Microsoft/language-server-protocol/compare/bdcc0f2..gh-pages

src/Client/LanguageClientRegistrationManager.cs

+6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ private Registration Register(Registration registration)
143143
if (registrationType == null)
144144
{
145145
// vscode client throws if given an unknown registration type
146+
_logger.LogError("Unknown Registration Type {Method} {@Registration}", registration.Method, registration);
146147
throw new NotSupportedException($"Unknown Registration Type '{registration.Method}'");
147148
}
148149

@@ -154,6 +155,11 @@ private Registration Register(Registration registration)
154155
: registration.RegisterOptions
155156
};
156157

158+
if (_logger.IsEnabled(LogLevel.Trace))
159+
{
160+
_logger.LogTrace("Registered handler for {Method} {@Registration}", deserializedRegistration.Method, deserializedRegistration.RegisterOptions );
161+
}
162+
157163
return deserializedRegistration;
158164
}
159165

src/Dap.Protocol/Dap.Protocol.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<ItemGroup>
1616
<ProjectReference Include="..\JsonRpc\JsonRpc.csproj" />
17-
<ProjectReference Include="..\JsonRpc.Generators\JsonRpc.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
17+
<ProjectReference Include="..\JsonRpc.Generators\JsonRpc.Generators.csproj" IncludeAssets="analyzers" ExcludeAssets="compile;runtime;native" PrivateAssets="contentfiles;build;buildMultitargeting;buildTransitive" OutputItemType="Analyzer" />
1818
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
1919
<_Parameter1>OmniSharp.Extensions.DebugAdapter.Server, PublicKey=0024000004800000940000000602000000240000525341310004000001000100391db875e68eb4bfef49ce14313b9e13f2cd3cc89eb273bbe6c11a55044c7d4f566cf092e1c77ef9e7c75b1496ae7f95d925938f5a01793dd8d9f99ae0a7595779b71b971287d7d7b5960d052078d14f5ce1a85ea5c9fb2f59ac735ff7bc215cab469b7c3486006860bad6f4c3b5204ea2f28dd4e1d05e2cca462cfd593b9f9f</_Parameter1>
2020
</AssemblyAttribute>

src/JsonRpc.Generators/AssemblyCapabilityKeyAttributeGenerator.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ ReportCacheDiagnostic<TypeDeclarationSyntax> cacheDiagnostic
3636
SyntaxFactory.IdentifierName("AssemblyCapabilityKey"), SyntaxFactory.AttributeArgumentList(
3737
SyntaxFactory.SeparatedList(
3838
new[] {
39-
SyntaxFactory.AttributeArgument(SyntaxFactory.TypeOfExpression(SyntaxFactory.ParseName(typeSymbol.ToDisplayString()))),
39+
SyntaxFactory.AttributeArgument(
40+
SyntaxFactory.TypeOfExpression(SyntaxFactory.ParseName(typeSymbol.ToDisplayString()))
41+
),
4042
}.Concat(options.AttributeLists.GetAttribute("CapabilityKey")!.ArgumentList!.Arguments)
4143
)
4244
)
@@ -48,7 +50,11 @@ ReportCacheDiagnostic<TypeDeclarationSyntax> cacheDiagnostic
4850
{
4951
var cu = SyntaxFactory.CompilationUnit()
5052
.WithUsings(SyntaxFactory.List(namespaces.OrderBy(z => z).Select(z => SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(z)))))
51-
.AddAttributeLists(SyntaxFactory.AttributeList(target: SyntaxFactory.AttributeTargetSpecifier(SyntaxFactory.Token(SyntaxKind.AssemblyKeyword)), SyntaxFactory.SeparatedList(types)))
53+
.AddAttributeLists(
54+
SyntaxFactory.AttributeList(
55+
target: SyntaxFactory.AttributeTargetSpecifier(SyntaxFactory.Token(SyntaxKind.AssemblyKeyword)), SyntaxFactory.SeparatedList(types)
56+
)
57+
)
5258
.WithLeadingTrivia(SyntaxFactory.Comment(Preamble.GeneratedByATool))
5359
.WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed);
5460

@@ -91,8 +97,8 @@ public override void OnVisitNode(TypeDeclarationSyntax syntaxNode)
9197
&& syntaxNode.AttributeLists.ContainsAttribute("CapabilityKey")
9298
&& syntaxNode.BaseList is { } bl && bl.Types.Any(
9399
z => z.Type switch {
94-
SimpleNameSyntax { Identifier: { Text: "ICapability" }, Arity: 0 } => true,
95-
_ => false
100+
SimpleNameSyntax { Identifier: { Text: "ICapability" or "DynamicCapability" or "IDynamicCapability" or "LinkSupportCapability" }, Arity: 0 } => true,
101+
_ => false
96102
}
97103
))
98104
{

src/JsonRpc.Generators/AssemblyJsonRpcHandlersAttributeGenerator.cs

+13-7
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,19 @@ ReportCacheDiagnostic<TypeDeclarationSyntax> cacheDiagnostic
3636
{
3737
var cu = CompilationUnit()
3838
.WithUsings(List(namespaces.OrderBy(z => z).Select(z => UsingDirective(ParseName(z)))))
39-
.AddAttributeLists(
40-
AttributeList(
41-
target: AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword)),
42-
SingletonSeparatedList(Attribute(IdentifierName("AssemblyJsonRpcHandlers"), AttributeArgumentList(SeparatedList(types))))
43-
)
44-
)
4539
.WithLeadingTrivia(Comment(Preamble.GeneratedByATool))
4640
.WithTrailingTrivia(CarriageReturnLineFeed);
47-
41+
while (types.Length > 0)
42+
{
43+
var innerTypes = types.Take(10).ToArray();
44+
types = types.Skip(10).ToArray();
45+
cu = cu.AddAttributeLists(
46+
AttributeList(
47+
target: AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword)),
48+
SingletonSeparatedList(Attribute(IdentifierName("AssemblyJsonRpcHandlers"), AttributeArgumentList(SeparatedList(innerTypes))))
49+
)
50+
);
51+
}
4852
context.AddSource("AssemblyJsonRpcHandlers.cs", cu.NormalizeWhitespace().GetText(Encoding.UTF8));
4953
}
5054
}
@@ -84,6 +88,7 @@ public override void OnVisitNode(TypeDeclarationSyntax syntaxNode)
8488
&& syntaxNode.BaseList is { } bl && bl.Types.Any(
8589
z => z.Type switch {
8690
SimpleNameSyntax { Identifier: { Text: "IJsonRpcNotificationHandler" }, Arity: 0 or 1 } => true,
91+
SimpleNameSyntax { Identifier: { Text: "ICanBeResolvedHandler" }, Arity: 1 } => true,
8792
SimpleNameSyntax { Identifier: { Text: "IJsonRpcRequestHandler" }, Arity: 1 or 2 } => true,
8893
SimpleNameSyntax { Identifier: { Text: "IJsonRpcHandler" }, Arity: 0 } => true,
8994
_ => false
@@ -99,6 +104,7 @@ public override void OnVisitNode(TypeDeclarationSyntax syntaxNode)
99104
&& syntaxNode.BaseList is { } bl2 && bl2.Types.Any(
100105
z => z.Type switch {
101106
SimpleNameSyntax { Identifier: { Text: "IJsonRpcNotificationHandler" }, Arity: 0 or 1 } => true,
107+
SimpleNameSyntax { Identifier: { Text: "ICanBeResolvedHandler" }, Arity: 1 } => true,
102108
SimpleNameSyntax { Identifier: { Text: "IJsonRpcRequestHandler" }, Arity: 1 or 2 } => true,
103109
SimpleNameSyntax { Identifier: { Text: "IJsonRpcHandler" }, Arity: 0 } => true,
104110
_ => false

src/JsonRpc.Generators/Contexts/RegistrationOptionAttributes.cs

+50-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
13
using System.Linq;
24
using Microsoft.CodeAnalysis;
5+
using Microsoft.CodeAnalysis.CSharp;
36
using Microsoft.CodeAnalysis.CSharp.Syntax;
47

58
namespace OmniSharp.Extensions.JsonRpc.Generators.Contexts
69
{
710
record RegistrationOptionAttributes(
811
SyntaxAttributeData? GenerateRegistrationOptions,
912
string? Key,
10-
ExpressionSyntax? KeyExpression,
13+
ExpressionSyntax[]? KeyExpression,
1114
bool SupportsWorkDoneProgress,
1215
bool SupportsDocumentSelector,
1316
bool SupportsStaticRegistrationOptions,
@@ -19,13 +22,16 @@ bool ImplementsStaticRegistrationOptions
1922
{
2023
public static RegistrationOptionAttributes? Parse(GeneratorExecutionContext context, TypeDeclarationSyntax syntax, INamedTypeSymbol symbol)
2124
{
22-
var registrationOptionsAttributeSymbol = context.Compilation.GetTypeByMetadataName($"OmniSharp.Extensions.LanguageServer.Protocol.Generation.GenerateRegistrationOptionsAttribute");
23-
var registrationOptionsConverterAttributeSymbol = context.Compilation.GetTypeByMetadataName($"OmniSharp.Extensions.LanguageServer.Protocol.RegistrationOptionsConverterAttribute");
25+
var registrationOptionsAttributeSymbol =
26+
context.Compilation.GetTypeByMetadataName($"OmniSharp.Extensions.LanguageServer.Protocol.Generation.GenerateRegistrationOptionsAttribute");
27+
var registrationOptionsConverterAttributeSymbol =
28+
context.Compilation.GetTypeByMetadataName($"OmniSharp.Extensions.LanguageServer.Protocol.RegistrationOptionsConverterAttribute");
2429
// var registrationOptionsInterfaceSymbol = context.Compilation.GetTypeByMetadataName("OmniSharp.Extensions.LanguageServer.Protocol.IRegistrationOptions");
2530
var textDocumentRegistrationOptionsInterfaceSymbol =
2631
context.Compilation.GetTypeByMetadataName("OmniSharp.Extensions.LanguageServer.Protocol.Models.ITextDocumentRegistrationOptions");
2732
var workDoneProgressOptionsInterfaceSymbol = context.Compilation.GetTypeByMetadataName("OmniSharp.Extensions.LanguageServer.Protocol.Models.IWorkDoneProgressOptions");
28-
var staticRegistrationOptionsInterfaceSymbol = context.Compilation.GetTypeByMetadataName("OmniSharp.Extensions.LanguageServer.Protocol.Models.IStaticRegistrationOptions");
33+
var staticRegistrationOptionsInterfaceSymbol =
34+
context.Compilation.GetTypeByMetadataName("OmniSharp.Extensions.LanguageServer.Protocol.Models.IStaticRegistrationOptions");
2935

3036
if (!( symbol.GetAttribute(registrationOptionsAttributeSymbol) is { } data )) return null;
3137
if (!( data.ApplicationSyntaxReference?.GetSyntax() is AttributeSyntax attributeSyntax )) return null;
@@ -34,12 +40,12 @@ bool ImplementsStaticRegistrationOptions
3440
ITypeSymbol? converter = null;
3541

3642
var supportsDocumentSelector = data.NamedArguments.Any(z => z is { Key: nameof(SupportsDocumentSelector), Value: { Value: true } })
37-
|| symbol.AllInterfaces.Length > 0 && symbol.AllInterfaces.Any(
38-
z => SymbolEqualityComparer.Default.Equals(z, textDocumentRegistrationOptionsInterfaceSymbol)
39-
)
40-
|| textDocumentRegistrationOptionsInterfaceSymbol is { } && syntax.BaseList?.Types.Any(
41-
type => type.Type.GetSyntaxName()?.Contains(textDocumentRegistrationOptionsInterfaceSymbol.Name) == true
42-
) == true;
43+
|| symbol.AllInterfaces.Length > 0 && symbol.AllInterfaces.Any(
44+
z => SymbolEqualityComparer.Default.Equals(z, textDocumentRegistrationOptionsInterfaceSymbol)
45+
)
46+
|| textDocumentRegistrationOptionsInterfaceSymbol is { } && syntax.BaseList?.Types.Any(
47+
type => type.Type.GetSyntaxName()?.Contains(textDocumentRegistrationOptionsInterfaceSymbol.Name) == true
48+
) == true;
4349
var supportsWorkDoneProgress = data.NamedArguments.Any(z => z is { Key: nameof(SupportsWorkDoneProgress), Value: { Value: true } })
4450
|| symbol.AllInterfaces.Length > 0 && symbol.AllInterfaces.Any(
4551
z => SymbolEqualityComparer.Default.Equals(z, workDoneProgressOptionsInterfaceSymbol)
@@ -82,17 +88,47 @@ bool ImplementsStaticRegistrationOptions
8288
}
8389

8490
string? value = null;
85-
ExpressionSyntax? valueSyntax = null;
91+
ExpressionSyntax[]? valueExpressionSyntaxes = null;
8692
if (data is { ConstructorArguments: { Length: > 0 } arguments } && arguments[0].Kind is TypedConstantKind.Primitive && arguments[0].Value is string)
8793
{
88-
value = arguments[0].Value as string;
89-
valueSyntax = attributeSyntax.ArgumentList!.Arguments[0].Expression;
94+
static IEnumerable<string> getStringValue(TypedConstant constant)
95+
{
96+
if (constant.Kind is TypedConstantKind.Primitive && constant.Value is string s)
97+
{
98+
yield return s;
99+
}
100+
101+
if (constant.Kind is TypedConstantKind.Array)
102+
{
103+
foreach (var i in constant.Values.SelectMany(getStringValue))
104+
{
105+
yield return i;
106+
}
107+
}
108+
}
109+
110+
static IEnumerable<ExpressionSyntax> getStringExpressionSyntaxes(AttributeArgumentSyntax syntax)
111+
{
112+
switch (syntax.Expression)
113+
{
114+
case LiteralExpressionSyntax literalExpressionSyntax when literalExpressionSyntax.Token.IsKind(SyntaxKind.StringLiteralToken):
115+
yield return literalExpressionSyntax;
116+
break;
117+
case InvocationExpressionSyntax
118+
{ Expression: IdentifierNameSyntax { Identifier: { Text: "nameof" } } }:
119+
yield return syntax.Expression;
120+
break;
121+
}
122+
}
123+
124+
value = string.Join(".", arguments.SelectMany(getStringValue));
125+
valueExpressionSyntaxes = attributeSyntax.ArgumentList!.Arguments.SelectMany(getStringExpressionSyntaxes).ToArray();
90126
}
91127

92128
return new RegistrationOptionAttributes(
93129
new SyntaxAttributeData(attributeSyntax, data),
94130
value,
95-
valueSyntax,
131+
valueExpressionSyntaxes,
96132
supportsWorkDoneProgress,
97133
supportsDocumentSelector,
98134
supportsStaticRegistrationOptions,

src/JsonRpc.Generators/GenerateHandlerMethodsGenerator.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,22 @@ ReportCacheDiagnostic<TypeDeclarationSyntax> cacheDiagnostic
144144
var namespaces = new HashSet<string>() { "OmniSharp.Extensions.JsonRpc" };
145145
if (handlers.Any())
146146
{
147+
var types = handlers.ToArray();
147148
var cu = CompilationUnit()
148149
.WithUsings(List(namespaces.OrderBy(z => z).Select(z => UsingDirective(ParseName(z)))))
149-
.AddAttributeLists(
150-
AttributeList(
151-
target: AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword)),
152-
SingletonSeparatedList(Attribute(IdentifierName("AssemblyJsonRpcHandlers"), AttributeArgumentList(SeparatedList(handlers))))
153-
)
154-
)
155150
.WithLeadingTrivia(Comment(Preamble.GeneratedByATool))
156151
.WithTrailingTrivia(CarriageReturnLineFeed);
152+
while (types.Length > 0)
153+
{
154+
var innerTypes = types.Take(10).ToArray();
155+
types = types.Skip(10).ToArray();
156+
cu = cu.AddAttributeLists(
157+
AttributeList(
158+
target: AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword)),
159+
SingletonSeparatedList(Attribute(IdentifierName("AssemblyJsonRpcHandlers"), AttributeArgumentList(SeparatedList(innerTypes))))
160+
)
161+
);
162+
}
157163

158164
context.AddSource("GeneratedAssemblyJsonRpcHandlers.cs", cu.NormalizeWhitespace().GetText(Encoding.UTF8));
159165
}

src/JsonRpc.Generators/RegistrationOptionsGenerator.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,9 @@ ReportCacheDiagnostic<TypeDeclarationSyntax> cacheDiagnostic
8686
AttributeList(
8787
SingletonSeparatedList(
8888
Attribute(
89-
IdentifierName("RegistrationOptionsKey"), AttributeArgumentList(
90-
SingletonSeparatedList(
91-
AttributeArgument(
92-
data.KeyExpression
93-
)
94-
)
89+
IdentifierName("RegistrationOptionsKey"),
90+
AttributeArgumentList(
91+
SeparatedList(data.KeyExpression.Select(AttributeArgument))
9592
)
9693
)
9794
)

src/JsonRpc/JsonRpc.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<PackageReference Include="System.IO.Pipelines" />
1717
<PackageReference Include="Nerdbank.Streams" />
1818
<PackageReference Include="DryIoc.Internal" PrivateAssets="All" />
19-
<ProjectReference Include="..\JsonRpc.Generators\JsonRpc.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
19+
<ProjectReference Include="..\JsonRpc.Generators\JsonRpc.Generators.csproj" IncludeAssets="analyzers" ExcludeAssets="compile;runtime;native" PrivateAssets="contentfiles;build;buildMultitargeting;buildTransitive" OutputItemType="Analyzer" />
2020
</ItemGroup>
2121
<ItemGroup>
2222
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">

src/JsonRpc/JsonRpcServerOptionsBase.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public ILoggerFactory LoggerFactory
3030
}
3131

3232
public IEnumerable<Assembly> Assemblies { get; set; } = Enumerable.Empty<Assembly>();
33-
public bool UseAssemblyAttributeScanning { get; set; } = true;
33+
/// <summary>
34+
/// Experimental support for using assembly attributes
35+
/// </summary>
36+
public bool UseAssemblyAttributeScanning { get; set; } = false;
3437
public IRequestProcessIdentifier? RequestProcessIdentifier { get; set; }
3538
public int? Concurrency { get; set; }
3639
public IScheduler InputScheduler { get; set; } = TaskPoolScheduler.Default;

0 commit comments

Comments
 (0)