Skip to content

Commit fc6c943

Browse files
Worked on updating generation to fix a few problems
1 parent 39c31a0 commit fc6c943

File tree

7 files changed

+881
-6
lines changed

7 files changed

+881
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ coverage.info
4646
/codealike.json
4747
.tmp/
4848
.nuke/temp/
49+
**/*.received.cs

src/Protocol/Models/StringOrMarkupContent.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics;
2+
using System.Diagnostics.CodeAnalysis;
23
using Newtonsoft.Json;
34
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization.Converters;
45

@@ -17,8 +18,10 @@ public record StringOrMarkupContent
1718
public MarkupContent? MarkupContent { get; }
1819
public bool HasMarkupContent => String == null;
1920

21+
[return: NotNullIfNotNull("value")]
2022
public static implicit operator StringOrMarkupContent?(string? value) => value is null ? null : new StringOrMarkupContent(value);
2123

24+
[return: NotNullIfNotNull("markupContent")]
2225
public static implicit operator StringOrMarkupContent?(MarkupContent? markupContent) => markupContent is null ? null : new StringOrMarkupContent(markupContent);
2326

2427
private string DebuggerDisplay => $"{( HasString ? String : HasMarkupContent ? MarkupContent!.ToString() : string.Empty )}";

test/Generation.Tests/LspFeatureTests.cs

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,168 @@ public partial class Registration
124124

125125
await Verify(GenerationHelpers.GenerateAll(source));
126126
}
127+
128+
[Fact]
129+
public async Task Supports_Nullable_Params_With_Typed_Data()
130+
{
131+
var source = @"
132+
using System.Diagnostics;
133+
using System.Linq;
134+
using MediatR;
135+
using Newtonsoft.Json.Linq;
136+
using OmniSharp.Extensions.JsonRpc;
137+
using OmniSharp.Extensions.JsonRpc.Generation;
138+
using OmniSharp.Extensions.LanguageServer.Protocol.Client;
139+
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
140+
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
141+
using OmniSharp.Extensions.LanguageServer.Protocol.Generation;
142+
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
143+
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
144+
using OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities;
145+
using OmniSharp.Extensions.LanguageServer.Protocol;
146+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
147+
148+
// ReSharper disable once CheckNamespace
149+
namespace OmniSharp.Extensions.LanguageServer.Protocol.Test
150+
{
151+
namespace Models
152+
{
153+
[Parallel]
154+
[Method(TextDocumentNames.CodeLens, Direction.ClientToServer)]
155+
[GenerateHandler(""OmniSharp.Extensions.LanguageServer.Protocol.Document.Test"")]
156+
[GenerateHandlerMethods]
157+
[GenerateRequestMethods(typeof(ITextDocumentLanguageClient), typeof(ILanguageClient))]
158+
[RegistrationOptions(typeof(SubLensRegistrationOptions))]
159+
[Capability(typeof(SubLensCapability))]
160+
[Resolver(typeof(SubLens))]
161+
public partial record SubLensParams : ITextDocumentIdentifierParams, IWorkDoneProgressParams, IPartialItemsRequest<SubLensContainer?, SubLens>
162+
{
163+
/// <summary>
164+
/// The document to request code lens for.
165+
/// </summary>
166+
public TextDocumentIdentifier TextDocument { get; init; } = null!;
167+
}
168+
169+
public partial class SubLensContainer {}
170+
171+
/// <summary>
172+
/// A code lens represents a command that should be shown along with
173+
/// source text, like the number of references, a way to run tests, etc.
174+
///
175+
/// A code lens is _unresolved_ when no command is associated to it. For performance
176+
/// reasons the creation of a code lens and resolving should be done in two stages.
177+
/// </summary>
178+
[DebuggerDisplay(""{"" + nameof(DebuggerDisplay) + "",nq}"")]
179+
[Parallel]
180+
[Method(TextDocumentNames.CodeLensResolve, Direction.ClientToServer)]
181+
[GenerateHandler(""OmniSharp.Extensions.LanguageServer.Protocol.Document.Test"", Name = ""SubLensResolve"")]
182+
[GenerateHandlerMethods]
183+
[GenerateRequestMethods(typeof(ITextDocumentLanguageClient), typeof(ILanguageClient))]
184+
[GenerateTypedData]
185+
[GenerateContainer]
186+
[Capability(typeof(SubLensCapability))]
187+
public partial record SubLens : IRequest<SubLens>, ICanBeResolved, IDoesNotParticipateInRegistration
188+
{
189+
/// <summary>
190+
/// The range in which this code lens is valid. Should only span a single line.
191+
/// </summary>
192+
public Range Range { get; init; } = null!;
193+
194+
/// <summary>
195+
/// The command this code lens represents.
196+
/// </summary>
197+
[Optional]
198+
public Command? Command { get; init; }
199+
200+
/// <summary>
201+
/// A data entry field that is preserved on a code lens item between
202+
/// a code lens and a code lens resolve request.
203+
/// </summary>
204+
[Optional]
205+
public JToken? Data { get; init; }
206+
207+
private string DebuggerDisplay => $""{Range}{( Command != null ? $"" {Command}"" : """" )}"";
208+
209+
/// <inheritdoc />
210+
public override string ToString()
211+
{
212+
return DebuggerDisplay;
213+
}
214+
}
215+
216+
[GenerateRegistrationOptions(nameof(ServerCapabilities.SubLensProvider))]
217+
[RegistrationOptionsConverter(typeof(SubLensRegistrationOptionsConverter))]
218+
[RegistrationName(TextDocumentNames.CodeLens)]
219+
public partial class SubLensRegistrationOptions : IWorkDoneProgressOptions, ITextDocumentRegistrationOptions
220+
{
221+
/// <summary>
222+
/// Code lens has a resolve provider as well.
223+
/// </summary>
224+
[Optional]
225+
public bool ResolveProvider { get; set; }
226+
227+
private class SubLensRegistrationOptionsConverter : RegistrationOptionsConverterBase<SubLensRegistrationOptions, StaticOptions>
228+
{
229+
private readonly IHandlersManager _handlersManager;
230+
231+
public SubLensRegistrationOptionsConverter(IHandlersManager handlersManager)
232+
{
233+
_handlersManager = handlersManager;
234+
}
235+
236+
public override StaticOptions Convert(SubLensRegistrationOptions source)
237+
{
238+
return new()
239+
{
240+
ResolveProvider = source.ResolveProvider || _handlersManager.Descriptors.Any(z => z.HandlerType == typeof(ISubLensResolveHandler)),
241+
WorkDoneProgress = source.WorkDoneProgress
242+
};
243+
}
244+
}
245+
}
246+
247+
[Parallel]
248+
[Method(WorkspaceNames.CodeLensRefresh, Direction.ServerToClient)]
249+
[GenerateHandler(""OmniSharp.Extensions.LanguageServer.Protocol.Workspace.Test"")]
250+
[GenerateHandlerMethods]
251+
[GenerateRequestMethods(typeof(IWorkspaceLanguageServer), typeof(ILanguageServer))]
252+
[Capability(typeof(SubLensWorkspaceClientCapabilities))]
253+
public partial record SubLensRefreshParams : IRequest;
254+
}
255+
256+
namespace Client.Capabilities
257+
{
258+
[CapabilityKey(nameof(ClientCapabilities.TextDocument), nameof(TextDocumentClientCapabilities.CodeLens))]
259+
public partial class SubLensCapability : DynamicCapability
260+
{
261+
}
262+
263+
/// <summary>
264+
/// Capabilities specific to the code lens requests scoped to the
265+
/// workspace.
266+
///
267+
/// @since 3.16.0.
268+
/// </summary>
269+
[CapabilityKey(nameof(ClientCapabilities.Workspace), nameof(WorkspaceClientCapabilities.CodeLens))]
270+
public class SubLensWorkspaceClientCapabilities : ICapability
271+
{
272+
/// <summary>
273+
/// Whether the client implementation supports a refresh request send from the server
274+
/// to the client. This is useful if a server detects a change which requires a
275+
/// re-calculation of all code lenses.
276+
/// </summary>
277+
[Optional]
278+
public bool RefreshSupport { get; set; }
279+
}
280+
}
281+
282+
namespace Document
283+
{
284+
}
285+
}
286+
";
287+
288+
await Verify(GenerationHelpers.GenerateAll(source));
289+
}
127290
}
128291
}

test/Lsp.Integration.Tests/TypedCodeLensTests.cs renamed to test/Lsp.Integration.Tests/TypedCodeLensTests.cs.disable

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task Should_Aggregate_With_All_Related_Handlers()
3939
options.OnCodeLens(
4040
codeLensParams =>
4141
{
42-
return Task.FromResult(
42+
return Task.FromResult<CodeLensContainer?>(
4343
new CodeLensContainer<Data>(
4444
new CodeLens<Data>
4545
{
@@ -71,7 +71,7 @@ public async Task Should_Aggregate_With_All_Related_Handlers()
7171
options.OnCodeLens(
7272
codeLensParams =>
7373
{
74-
return Task.FromResult(
74+
return Task.FromResult<CodeLensContainer?>(
7575
new CodeLensContainer<Nested>(
7676
new CodeLens<Nested>
7777
{
@@ -98,7 +98,7 @@ public async Task Should_Aggregate_With_All_Related_Handlers()
9898
options.OnCodeLens(
9999
codeLensParams =>
100100
{
101-
return Task.FromResult(
101+
return Task.FromResult<CodeLensContainer?>(
102102
new CodeLensContainer(
103103
new CodeLens
104104
{
@@ -121,7 +121,7 @@ public async Task Should_Aggregate_With_All_Related_Handlers()
121121
options.OnCodeLens(
122122
codeLensParams =>
123123
{
124-
return Task.FromResult(
124+
return Task.FromResult<CodeLensContainer?>(
125125
new CodeLensContainer(
126126
new CodeLens
127127
{
@@ -167,7 +167,7 @@ public async Task Should_Resolve_With_Data_Capability()
167167
options.OnCodeLens(
168168
(codeLensParams, capability, token) =>
169169
{
170-
return Task.FromResult(
170+
return Task.FromResult<CodeLensContainer?>(
171171
new CodeLensContainer<Data>(
172172
new CodeLens<Data>
173173
{
@@ -270,7 +270,7 @@ public async Task Should_Resolve_With_Data_CancellationToken()
270270
options.OnCodeLens(
271271
(codeLensParams, token) =>
272272
{
273-
return Task.FromResult(
273+
return Task.FromResult<CodeLensContainer<Data>>(
274274
new CodeLensContainer<Data>(
275275
new CodeLens<Data>
276276
{

0 commit comments

Comments
 (0)