Skip to content

Minor updates. #509

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

Merged
merged 2 commits into from
Jan 30, 2021
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
4 changes: 2 additions & 2 deletions src/Dap.Client/DebugAdapterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ await DebugAdapterEventingHelper.Run(
_connection.Open();
var serverParams = await this.RequestDebugAdapterInitialize(ClientSettings, token).ConfigureAwait(false);

_receiver.Initialized();

ServerSettings = serverParams;

await DebugAdapterEventingHelper.Run(
Expand All @@ -146,8 +148,6 @@ await DebugAdapterEventingHelper.Run(
token
).ConfigureAwait(false);

_receiver.Initialized();

await _initializedComplete.ToTask(token);

await DebugAdapterEventingHelper.Run(
Expand Down
33 changes: 33 additions & 0 deletions src/Dap.Protocol/Models/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@

namespace OmniSharp.Extensions.DebugAdapter.Protocol.Models
{
public static class Container
{
[return: NotNullIfNotNull("items")]
public static Container<T>? From<T>(IEnumerable<T>? items) => items switch {
not null => new Container<T>(items),
_ => null
};

[return: NotNullIfNotNull("items")]
public static Container<T>? From<T>(params T[] items) => items switch {
not null => new Container<T>(items),
_ => null
};

[return: NotNullIfNotNull("items")]
public static Container<T>? From<T>(List<T>? items) => items switch {
not null => new Container<T>(items),
_ => null
};

[return: NotNullIfNotNull("items")]
public static Container<T>? From<T>(in ImmutableArray<T>? items) => items switch {
not null => new Container<T>(items),
_ => null
};

[return: NotNullIfNotNull("items")]
public static Container<T>? From<T>(ImmutableList<T>? items) => items switch {
not null => new Container<T>(items),
_ => null
};
}

public class Container<T> : ContainerBase<T>
{
public Container() : this(Enumerable.Empty<T>())
Expand Down
33 changes: 33 additions & 0 deletions src/Protocol/Models/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@

namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
public static class Container
{
[return: NotNullIfNotNull("items")]
public static Container<T>? From<T>(IEnumerable<T>? items) => items switch {
not null => new Container<T>(items),
_ => null
};

[return: NotNullIfNotNull("items")]
public static Container<T>? From<T>(params T[] items) => items switch {
not null => new Container<T>(items),
_ => null
};

[return: NotNullIfNotNull("items")]
public static Container<T>? From<T>(List<T>? items) => items switch {
not null => new Container<T>(items),
_ => null
};

[return: NotNullIfNotNull("items")]
public static Container<T>? From<T>(in ImmutableArray<T>? items) => items switch {
not null => new Container<T>(items),
_ => null
};

[return: NotNullIfNotNull("items")]
public static Container<T>? From<T>(ImmutableList<T>? items) => items switch {
not null => new Container<T>(items),
_ => null
};
}

public class Container<T> : ContainerBase<T>
{
public Container() : this(Enumerable.Empty<T>())
Expand Down
6 changes: 3 additions & 3 deletions src/Protocol/Models/StringOrMarkupContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
[JsonConverter(typeof(StringOrMarkupContentConverter))]
[JsonConverter(typeof( StringOrMarkupContentConverter))]
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public record StringOrMarkupContent
{
Expand All @@ -17,9 +17,9 @@ public record StringOrMarkupContent
public MarkupContent? MarkupContent { get; }
public bool HasMarkupContent => String == null;

public static implicit operator StringOrMarkupContent(string value) => new StringOrMarkupContent(value);
public static implicit operator StringOrMarkupContent?(string? value) => value is null ? null : new StringOrMarkupContent(value);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have NotNullIfNotNull

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@david-driscoll doesn't look like this was addressed.


public static implicit operator StringOrMarkupContent(MarkupContent markupContent) => new StringOrMarkupContent(markupContent);
public static implicit operator StringOrMarkupContent?(MarkupContent? markupContent) => markupContent is null ? null : new StringOrMarkupContent(markupContent);

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

Expand Down
39 changes: 33 additions & 6 deletions src/Server/Pipelines/ResolveCommandPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ResolveCommandPipeline<TRequest, TResponse> : IPipelineBehavior<TRe
public ResolveCommandPipeline(IRequestContext context, ILogger<ResolveCommandPipeline<TRequest, TResponse>> logger)
{
_logger = logger;
_descriptor = (context.Descriptor as ILspHandlerDescriptor)!;
_descriptor = ( context.Descriptor as ILspHandlerDescriptor )!;
}

public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
Expand All @@ -40,15 +40,42 @@ public async Task<TResponse> Handle(TRequest request, CancellationToken cancella
);
foreach (var item in canBeResolvedItems)
{
item.SetRawData(item.Data ?? new JObject());
if (item.Data is JObject o)
{
o[Constants.PrivateHandlerId] = id;
}
UpdatePrivateHandlerId(item, id);
}
}

// Only pin the handler type, if we know the source handler (codelens) is also the resolver.
if (response is ICanBeResolved canBeResolvedItem)
{
var id = _descriptor.Handler is ICanBeIdentifiedHandler resolved ? resolved.Id : Guid.Empty;
_logger.LogTrace(
"Updating Resolve items with wrapped data for {Method}:{Handler}",
_descriptor.Method,
_descriptor.ImplementationType.FullName
);
UpdatePrivateHandlerId(canBeResolvedItem, id);
}

return response;

void UpdatePrivateHandlerId(ICanBeResolved item, Guid id)
{
item.SetRawData(item.Data ?? new JObject());
if (item.Data is JObject o)
{
if (id == Guid.Empty)
{
if (o.ContainsKey(Constants.PrivateHandlerId))
{
o.Remove(Constants.PrivateHandlerId);
}

return;
}

o[Constants.PrivateHandlerId] = id;
}
}
}
}
}
1 change: 1 addition & 0 deletions test/Lsp.Tests/CompletionItemKindTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions;
using Lsp.Tests.Integration.Fixtures;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
Expand Down
16 changes: 8 additions & 8 deletions test/Lsp.Tests/Matchers/ResolveCommandMatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Lsp.Tests.Matchers
public class ResolveCommandMatcherTests : AutoTestBase
{
private readonly Guid _trueId = Guid.NewGuid();
private readonly Guid _falseId = Guid.NewGuid();
private readonly Guid _falseId = Guid.Empty;

public ResolveCommandMatcherTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
Expand Down Expand Up @@ -247,7 +247,7 @@ public async Task Should_Update_CompletionItems_With_HandlerType()
0,
TextDocumentNames.Completion,
"Key",
(resolveHandler as IJsonRpcHandler)!,
( resolveHandler as IJsonRpcHandler )!,
resolveHandler.GetType(),
typeof(CompletionParams),
null,
Expand Down Expand Up @@ -298,7 +298,7 @@ public async Task Should_Update_CodeLensContainer_With_HandlerType()
0,
TextDocumentNames.CodeLens,
"Key",
(resolveHandler as IJsonRpcHandler)!,
( resolveHandler as IJsonRpcHandler )!,
resolveHandler.GetType(),
typeof(CodeLensParams),
null,
Expand Down Expand Up @@ -344,12 +344,12 @@ public async Task Should_Update_CodeLens_Removing_HandlerType()
typeof(ICanBeIdentifiedHandler)
}, new object[0]
);
( resolveHandler as ICanBeIdentifiedHandler )?.Id.Returns(_trueId);
( resolveHandler as ICanBeIdentifiedHandler )?.Id.Returns(_falseId);
var descriptor = new LspHandlerDescriptor(
0,
TextDocumentNames.CodeLensResolve,
"Key",
(resolveHandler as IJsonRpcHandler)!,
( resolveHandler as IJsonRpcHandler )!,
resolveHandler.GetType(),
typeof(CodeLens),
null,
Expand All @@ -368,15 +368,15 @@ public async Task Should_Update_CodeLens_Removing_HandlerType()
var item = new CodeLens {
Data = JObject.FromObject(new { hello = "world" })
};
item.Data[Constants.PrivateHandlerId] = Guid.Empty;

// When
var response = await handlerMatcher.Handle(item, CancellationToken.None, () => Task.FromResult(item));

// Then
response.Should().BeEquivalentTo(item, x => x.UsingStructuralRecordEquality());
item.Data?[Constants.PrivateHandlerId].Value<Guid>().Should().BeEmpty();
item.Data?["hello"].Value<string>().Should().Be("world");
var data = item.Data.Should().BeOfType<JObject>().Subject;
data.Should().NotContainKey(Constants.PrivateHandlerId);
data["hello"].Value<string>().Should().Be("world");
}
}
}