Skip to content

Commit 1686249

Browse files
drop down to v2 of the Microsoft.Extenisons.* (#342)
1 parent 2f4ac07 commit 1686249

26 files changed

+735
-36
lines changed

Directory.Build.targets

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414
<PackageReference Update="Rocket.Surgery.Nuke" Version="0.14.0-beta.9" />
1515
</ItemGroup>
1616
<ItemGroup>
17-
<PackageReference Update="Microsoft.Extensions.Logging" Version="3.1.0" />
18-
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="3.1.0" />
19-
<PackageReference Update="Microsoft.Extensions.Logging.Debug" Version="3.1.0" />
20-
<PackageReference Update="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.0" />
21-
<PackageReference Update="Microsoft.Extensions.Configuration" Version="3.1.0" />
22-
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
23-
<PackageReference Update="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.0" />
17+
<PackageReference Update="Microsoft.Extensions.Logging" Version="2.0.0" />
18+
<PackageReference Update="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
19+
<PackageReference Update="Microsoft.Extensions.Configuration" Version="2.0.0" />
20+
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
2421
<PackageReference Update="Newtonsoft.Json" Version="11.0.2" />
2522
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.7.1" />
2623
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.3" />
@@ -48,4 +45,4 @@
4845
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.4.0" />
4946
<PackageReference Update="DryIoc.Internal" Version="4.3.3" />
5047
</ItemGroup>
51-
</Project>
48+
</Project>

src/Client/Client.csproj

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
<PackageDescription>You can use this package to interact with a Language Server using the language server protocol</PackageDescription>
99
</PropertyGroup>
1010

11-
<ItemGroup>
12-
<PackageReference Include="System.Reactive" />
13-
</ItemGroup>
14-
1511
<ItemGroup>
1612
<ProjectReference Include="..\JsonRpc\JsonRpc.csproj" />
1713
<ProjectReference Include="..\Protocol\Protocol.csproj" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.using System;
3+
4+
using System;
5+
using Microsoft.Extensions.Configuration;
6+
7+
namespace OmniSharp.Extensions.LanguageServer.Client.Configuration
8+
{
9+
/// <summary>
10+
/// Extension methods for adding <see cref="IConfiguration"/> to an <see cref="IConfigurationBuilder"/>.
11+
/// </summary>
12+
internal static class ChainedBuilderExtensions
13+
{
14+
/// <summary>
15+
/// Adds an existing configuration to <paramref name="configurationBuilder"/>.
16+
/// </summary>
17+
/// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
18+
/// <param name="config">The <see cref="IConfiguration"/> to add.</param>
19+
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
20+
public static IConfigurationBuilder CustomAddConfiguration(this IConfigurationBuilder configurationBuilder, IConfiguration config)
21+
=> CustomAddConfiguration(configurationBuilder, config, shouldDisposeConfiguration: false);
22+
23+
/// <summary>
24+
/// Adds an existing configuration to <paramref name="configurationBuilder"/>.
25+
/// </summary>
26+
/// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
27+
/// <param name="config">The <see cref="IConfiguration"/> to add.</param>
28+
/// <param name="shouldDisposeConfiguration">Whether the configuration should get disposed when the configuration provider is disposed.</param>
29+
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
30+
public static IConfigurationBuilder CustomAddConfiguration(this IConfigurationBuilder configurationBuilder, IConfiguration config, bool shouldDisposeConfiguration)
31+
{
32+
if (configurationBuilder == null)
33+
{
34+
throw new ArgumentNullException(nameof(configurationBuilder));
35+
}
36+
if (config == null)
37+
{
38+
throw new ArgumentNullException(nameof(config));
39+
}
40+
41+
configurationBuilder.Add(new ChainedConfigurationSource
42+
{
43+
Configuration = config,
44+
ShouldDisposeConfiguration = shouldDisposeConfiguration,
45+
});
46+
return configurationBuilder;
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.using System;
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.Primitives;
9+
10+
namespace OmniSharp.Extensions.LanguageServer.Client.Configuration
11+
{
12+
/// <summary>
13+
/// Chained implementation of <see cref="IConfigurationProvider"/>
14+
/// </summary>
15+
internal class ChainedConfigurationProvider : IConfigurationProvider, IDisposable
16+
{
17+
private readonly IConfiguration _config;
18+
private readonly bool _shouldDisposeConfig;
19+
20+
/// <summary>
21+
/// Initialize a new instance from the source configuration.
22+
/// </summary>
23+
/// <param name="source">The source configuration.</param>
24+
public ChainedConfigurationProvider(ChainedConfigurationSource source)
25+
{
26+
if (source == null)
27+
{
28+
throw new ArgumentNullException(nameof(source));
29+
}
30+
31+
_config = source.Configuration ?? throw new ArgumentException(nameof(source));
32+
_shouldDisposeConfig = source.ShouldDisposeConfiguration;
33+
}
34+
35+
/// <summary>
36+
/// Tries to get a configuration value for the specified key.
37+
/// </summary>
38+
/// <param name="key">The key.</param>
39+
/// <param name="value">The value.</param>
40+
/// <returns><c>True</c> if a value for the specified key was found, otherwise <c>false</c>.</returns>
41+
public bool TryGet(string key, out string value)
42+
{
43+
value = _config[key];
44+
return !string.IsNullOrEmpty(value);
45+
}
46+
47+
/// <summary>
48+
/// Sets a configuration value for the specified key.
49+
/// </summary>
50+
/// <param name="key">The key.</param>
51+
/// <param name="value">The value.</param>
52+
public void Set(string key, string value) => _config[key] = value;
53+
54+
/// <summary>
55+
/// Returns a change token if this provider supports change tracking, null otherwise.
56+
/// </summary>
57+
/// <returns>The change token.</returns>
58+
public IChangeToken GetReloadToken() => _config.GetReloadToken();
59+
60+
/// <summary>
61+
/// Loads configuration values from the source represented by this <see cref="IConfigurationProvider"/>.
62+
/// </summary>
63+
public void Load() { }
64+
65+
/// <summary>
66+
/// Returns the immediate descendant configuration keys for a given parent path based on this
67+
/// <see cref="IConfigurationProvider"/>s data and the set of keys returned by all the preceding
68+
/// <see cref="IConfigurationProvider"/>s.
69+
/// </summary>
70+
/// <param name="earlierKeys">The child keys returned by the preceding providers for the same parent path.</param>
71+
/// <param name="parentPath">The parent path.</param>
72+
/// <returns>The child keys.</returns>
73+
public IEnumerable<string> GetChildKeys(
74+
IEnumerable<string> earlierKeys,
75+
string parentPath)
76+
{
77+
IConfiguration section = parentPath == null ? _config : _config.GetSection(parentPath);
78+
var children = section.GetChildren();
79+
var keys = new List<string>();
80+
keys.AddRange(children.Select(c => c.Key));
81+
return keys.Concat(earlierKeys)
82+
.OrderBy(k => k, ConfigurationKeyComparer.Instance);
83+
}
84+
85+
/// <inheritdoc />
86+
public void Dispose()
87+
{
88+
if (_shouldDisposeConfig)
89+
{
90+
(_config as IDisposable)?.Dispose();
91+
}
92+
}
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.using System;
3+
4+
using Microsoft.Extensions.Configuration;
5+
6+
namespace OmniSharp.Extensions.LanguageServer.Client.Configuration
7+
{
8+
/// <summary>
9+
/// Represents a chained <see cref="IConfiguration"/> as an <see cref="IConfigurationSource"/>.
10+
/// </summary>
11+
internal class ChainedConfigurationSource : IConfigurationSource
12+
{
13+
/// <summary>
14+
/// The chained configuration.
15+
/// </summary>
16+
public IConfiguration Configuration { get; set; }
17+
18+
/// <summary>
19+
/// Whether the chained configuration should be disposed when the
20+
/// configuration provider gets disposed.
21+
/// </summary>
22+
public bool ShouldDisposeConfiguration { get; set; }
23+
24+
/// <summary>
25+
/// Builds the <see cref="ChainedConfigurationProvider"/> for this source.
26+
/// </summary>
27+
/// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param>
28+
/// <returns>A <see cref="ChainedConfigurationProvider"/></returns>
29+
public IConfigurationProvider Build(IConfigurationBuilder builder)
30+
=> new ChainedConfigurationProvider(this);
31+
}
32+
}

src/Client/LanguageClientServiceCollectionExtensions.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Reflection;
45
using DryIoc;
56
using Microsoft.Extensions.Configuration;
67
using Microsoft.Extensions.DependencyInjection;
78
using Microsoft.Extensions.DependencyInjection.Extensions;
89
using Microsoft.Extensions.Options;
10+
using Microsoft.Extensions.Primitives;
911
using OmniSharp.Extensions.JsonRpc;
12+
using OmniSharp.Extensions.LanguageServer.Client.Configuration;
1013
using OmniSharp.Extensions.LanguageServer.Protocol.Client;
1114
using OmniSharp.Extensions.LanguageServer.Protocol.Client.WorkDone;
1215
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
@@ -69,12 +72,12 @@ internal static IContainer AddLanguageClientInternals(this IContainer container,
6972
var outerConfiguration = outerServiceProvider?.GetService<IConfiguration>();
7073
if (outerConfiguration != null)
7174
{
72-
builder.AddConfiguration(outerConfiguration, false);
75+
builder.CustomAddConfiguration(outerConfiguration, false);
7376
}
7477

7578
if (providedConfiguration != null)
7679
{
77-
builder.AddConfiguration(providedConfiguration.ImplementationInstance as IConfiguration);
80+
builder.CustomAddConfiguration(providedConfiguration.ImplementationInstance as IConfiguration);
7881
}
7982

8083
//var didChangeConfigurationProvider = _.GetRequiredService<DidChangeConfigurationProvider>();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.using System;
3+
4+
using System;
5+
using Microsoft.Extensions.Configuration;
6+
7+
namespace OmniSharp.Extensions.DebugAdapter.Client.Configuration
8+
{
9+
/// <summary>
10+
/// Extension methods for adding <see cref="IConfiguration"/> to an <see cref="IConfigurationBuilder"/>.
11+
/// </summary>
12+
internal static class ChainedBuilderExtensions
13+
{
14+
/// <summary>
15+
/// Adds an existing configuration to <paramref name="configurationBuilder"/>.
16+
/// </summary>
17+
/// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
18+
/// <param name="config">The <see cref="IConfiguration"/> to add.</param>
19+
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
20+
public static IConfigurationBuilder CustomAddConfiguration(this IConfigurationBuilder configurationBuilder, IConfiguration config)
21+
=> CustomAddConfiguration(configurationBuilder, config, shouldDisposeConfiguration: false);
22+
23+
/// <summary>
24+
/// Adds an existing configuration to <paramref name="configurationBuilder"/>.
25+
/// </summary>
26+
/// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
27+
/// <param name="config">The <see cref="IConfiguration"/> to add.</param>
28+
/// <param name="shouldDisposeConfiguration">Whether the configuration should get disposed when the configuration provider is disposed.</param>
29+
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
30+
public static IConfigurationBuilder CustomAddConfiguration(this IConfigurationBuilder configurationBuilder, IConfiguration config, bool shouldDisposeConfiguration)
31+
{
32+
if (configurationBuilder == null)
33+
{
34+
throw new ArgumentNullException(nameof(configurationBuilder));
35+
}
36+
if (config == null)
37+
{
38+
throw new ArgumentNullException(nameof(config));
39+
}
40+
41+
configurationBuilder.Add(new ChainedConfigurationSource
42+
{
43+
Configuration = config,
44+
ShouldDisposeConfiguration = shouldDisposeConfiguration,
45+
});
46+
return configurationBuilder;
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.using System;
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.Primitives;
9+
10+
namespace OmniSharp.Extensions.DebugAdapter.Client.Configuration
11+
{
12+
/// <summary>
13+
/// Chained implementation of <see cref="IConfigurationProvider"/>
14+
/// </summary>
15+
internal class ChainedConfigurationProvider : IConfigurationProvider, IDisposable
16+
{
17+
private readonly IConfiguration _config;
18+
private readonly bool _shouldDisposeConfig;
19+
20+
/// <summary>
21+
/// Initialize a new instance from the source configuration.
22+
/// </summary>
23+
/// <param name="source">The source configuration.</param>
24+
public ChainedConfigurationProvider(ChainedConfigurationSource source)
25+
{
26+
if (source == null)
27+
{
28+
throw new ArgumentNullException(nameof(source));
29+
}
30+
31+
_config = source.Configuration ?? throw new ArgumentException(nameof(source));
32+
_shouldDisposeConfig = source.ShouldDisposeConfiguration;
33+
}
34+
35+
/// <summary>
36+
/// Tries to get a configuration value for the specified key.
37+
/// </summary>
38+
/// <param name="key">The key.</param>
39+
/// <param name="value">The value.</param>
40+
/// <returns><c>True</c> if a value for the specified key was found, otherwise <c>false</c>.</returns>
41+
public bool TryGet(string key, out string value)
42+
{
43+
value = _config[key];
44+
return !string.IsNullOrEmpty(value);
45+
}
46+
47+
/// <summary>
48+
/// Sets a configuration value for the specified key.
49+
/// </summary>
50+
/// <param name="key">The key.</param>
51+
/// <param name="value">The value.</param>
52+
public void Set(string key, string value) => _config[key] = value;
53+
54+
/// <summary>
55+
/// Returns a change token if this provider supports change tracking, null otherwise.
56+
/// </summary>
57+
/// <returns>The change token.</returns>
58+
public IChangeToken GetReloadToken() => _config.GetReloadToken();
59+
60+
/// <summary>
61+
/// Loads configuration values from the source represented by this <see cref="IConfigurationProvider"/>.
62+
/// </summary>
63+
public void Load() { }
64+
65+
/// <summary>
66+
/// Returns the immediate descendant configuration keys for a given parent path based on this
67+
/// <see cref="IConfigurationProvider"/>s data and the set of keys returned by all the preceding
68+
/// <see cref="IConfigurationProvider"/>s.
69+
/// </summary>
70+
/// <param name="earlierKeys">The child keys returned by the preceding providers for the same parent path.</param>
71+
/// <param name="parentPath">The parent path.</param>
72+
/// <returns>The child keys.</returns>
73+
public IEnumerable<string> GetChildKeys(
74+
IEnumerable<string> earlierKeys,
75+
string parentPath)
76+
{
77+
IConfiguration section = parentPath == null ? _config : _config.GetSection(parentPath);
78+
var children = section.GetChildren();
79+
var keys = new List<string>();
80+
keys.AddRange(children.Select(c => c.Key));
81+
return keys.Concat(earlierKeys)
82+
.OrderBy(k => k, ConfigurationKeyComparer.Instance);
83+
}
84+
85+
/// <inheritdoc />
86+
public void Dispose()
87+
{
88+
if (_shouldDisposeConfig)
89+
{
90+
(_config as IDisposable)?.Dispose();
91+
}
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)