-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix up implementation for parameterless requests. (#68077)
- Loading branch information
Showing
14 changed files
with
441 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...r/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/Mocks/TestHandlerProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
|
||
namespace Microsoft.CommonLanguageServerProtocol.Framework.UnitTests; | ||
|
||
internal class TestHandlerProvider : IHandlerProvider | ||
{ | ||
private readonly IEnumerable<(RequestHandlerMetadata metadata, IMethodHandler provider)> _providers; | ||
|
||
public TestHandlerProvider(IEnumerable<(RequestHandlerMetadata metadata, IMethodHandler provider)> providers) | ||
=> _providers = providers; | ||
|
||
public IMethodHandler GetMethodHandler(string method, Type? requestType, Type? responseType) | ||
=> _providers.Single(p => p.metadata.MethodName == method).provider; | ||
|
||
public ImmutableArray<RequestHandlerMetadata> GetRegisteredMethods() | ||
=> _providers.Select(p => p.metadata).ToImmutableArray(); | ||
} |
41 changes: 41 additions & 0 deletions
41
...erver/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/Mocks/TestLspServices.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
|
||
namespace Microsoft.CommonLanguageServerProtocol.Framework.UnitTests; | ||
|
||
internal class TestLspServices : ILspServices | ||
{ | ||
private readonly bool _supportsGetRegisteredServices; | ||
private readonly IEnumerable<(Type type, object instance)> _services; | ||
|
||
public TestLspServices(IEnumerable<(Type type, object instance)> services, bool supportsGetRegisteredServices) | ||
{ | ||
_services = services; | ||
_supportsGetRegisteredServices = supportsGetRegisteredServices; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
public ImmutableArray<Type> GetRegisteredServices() | ||
=> _services.Select(s => s.instance.GetType()).ToImmutableArray(); | ||
|
||
public T GetRequiredService<T>() where T : notnull | ||
=> (T?)TryGetService(typeof(T)) ?? throw new InvalidOperationException($"{typeof(T).Name} did not have a service"); | ||
|
||
public IEnumerable<T> GetRequiredServices<T>() | ||
=> _supportsGetRegisteredServices ? Array.Empty<T>() : _services.Where(s => s.instance is T).Select(s => (T)s.instance); | ||
|
||
public bool SupportsGetRegisteredServices() | ||
=> _supportsGetRegisteredServices; | ||
|
||
public object? TryGetService(Type type) | ||
=> _services.FirstOrDefault(s => (_supportsGetRegisteredServices ? s.instance.GetType() : s.type) == type).instance; | ||
} |
Oops, something went wrong.