Skip to content

Commit

Permalink
(GH-121) Refactoring implementation
Browse files Browse the repository at this point in the history
- Added new interface to provide up to date Configuration
- Changed Rule registrations.  Use container, rather than reflection
- This will mean that each rule has to be registered with container
  • Loading branch information
gep13 committed Mar 2, 2019
1 parent 122b1f1 commit 36f6f3b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
16 changes: 5 additions & 11 deletions src/Chocolatey.Language.Server/DiagnosticsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@ public class DiagnosticsHandler
private readonly BufferManager _bufferManager;
private IList<INuspecRule> _rules = new List<INuspecRule>();

public DiagnosticsHandler(ILanguageServer router, BufferManager bufferManager)
private IConfigurationProvider _configurationProvider;

public DiagnosticsHandler(ILanguageServer router, BufferManager bufferManager, IEnumerable<INuSpecRule> rules, IConfigurationProvider configurationProvider)
{
_router = router;
_bufferManager = bufferManager;

var typeLocator = new TypeLocator();
foreach (var nuspecRule in typeLocator.GetTypesThatInheritOrImplement<INuspecRule>().OrEmptyListIfNull())
{
var rule = Activator.CreateInstance(nuspecRule) as INuspecRule;
if (rule != null)
{
_rules.Add(rule);
}
}
_rules = new List<INuSpecRule>(rules);
_configurationProvider = configurationProvider;
}

public void PublishDiagnostics(Uri uri, Buffer buffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Chocolatey.Language.Server.Handlers
/// Language Server message handler that tracks configuration.
/// </summary>
public sealed class ConfigurationHandler
: IDidChangeConfigurationSettingsHandler
: IDidChangeConfigurationSettingsHandler, IConfigurationProvider
{
/// <summary>
/// The JSON serialiser used to read settings from LSP notifications.
Expand Down
7 changes: 7 additions & 0 deletions src/Chocolatey.Language.Server/IConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Chocolatey.Language.Server
{
public interface IConfigurationProvider
{
Configuration Configuration { get; }
}
}
7 changes: 7 additions & 0 deletions src/Chocolatey.Language.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Chocolatey.Language.Server.Handlers;
using Chocolatey.Language.Server.Validations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Server;

namespace Chocolatey.Language.Server
Expand Down Expand Up @@ -42,6 +45,10 @@ static void ConfigureServices(IServiceCollection services)
services.AddSingleton<BufferManager>();
services.AddSingleton<DiagnosticsHandler>();
services.AddSingleton<Configuration>();
services.AddSingleton<INuSpecRule, UrlValidValidation>();
services.AddSingleton<INuSpecRule, DescriptionLengthValidation>();
services.AddSingleton<INuSpecRule, DoesNotContainTemplatedValues>();
services.AddTransient<IConfigurationProvider>(config => config.GetServices<IJsonRpcHandler>().OfType<ConfigurationHandler>().FirstOrDefault());
}
}
}

0 comments on commit 36f6f3b

Please sign in to comment.