-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implement ConfigurationHandler
- Loading branch information
Showing
30 changed files
with
1,008 additions
and
174 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
31 changes: 31 additions & 0 deletions
31
src/Chocolatey.Language.Server/CustomProtocol/DidChangeConfigurationSettings.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,31 @@ | ||
using OmniSharp.Extensions.JsonRpc; | ||
using OmniSharp.Extensions.LanguageServer; | ||
using OmniSharp.Extensions.LanguageServer.Protocol; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using OmniSharp.Extensions.Embedded.MediatR; | ||
|
||
namespace Chocolatey.Language.Server.CustomProtocol | ||
{ | ||
/// <summary> | ||
/// Custom handler for "workspace/didChangeConfiguration" with the configuration as a <see cref="JObject"/>. | ||
/// </summary> | ||
[Method("workspace/didChangeConfiguration")] | ||
public interface IDidChangeConfigurationSettingsHandler | ||
: IJsonRpcNotificationHandler<DidChangeConfigurationObjectParams>, IJsonRpcHandler, IRegistration<object>, ICapability<DidChangeConfigurationCapability> | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Notification parameters for "workspace/didChangeConfiguration". | ||
/// </summary> | ||
public class DidChangeConfigurationObjectParams : IRequest | ||
{ | ||
/// <summary> | ||
/// The current settings. | ||
/// </summary> | ||
[JsonProperty("settings")] | ||
public JToken Settings; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Chocolatey.Language.Server.Engine | ||
{ | ||
public sealed class Configuration | ||
{ | ||
/// <summary> | ||
/// The name of the configuration section as passed in messages such as <see cref="CustomProtocol.DidChangeConfigurationObjectParams"/>. | ||
/// </summary> | ||
public static readonly string SectionName = "chocolatey"; | ||
|
||
/// <summary> | ||
/// The Chocolatey language service's main configuration. | ||
/// </summary> | ||
[JsonProperty("language", ObjectCreationHandling = ObjectCreationHandling.Reuse)] | ||
public LanguageConfiguration Language { get; } = new LanguageConfiguration(); | ||
|
||
/// <summary> | ||
/// The Chocolatey Command Configuration | ||
/// </summary> | ||
[JsonProperty("commands", ObjectCreationHandling = ObjectCreationHandling.Reuse)] | ||
public CommandsConfiguration Commands { get ; } = new CommandsConfiguration(); | ||
|
||
|
||
[JsonProperty("templates", ObjectCreationHandling = ObjectCreationHandling.Reuse)] | ||
public TemplatesConfiguration Templates { get; } = new TemplatesConfiguration(); | ||
} | ||
|
||
public class TemplatesConfiguration | ||
{ | ||
public TemplatesConfiguration() | ||
{ | ||
} | ||
|
||
[JsonProperty("names", ObjectCreationHandling = ObjectCreationHandling.Reuse)] | ||
public HashSet<string> Names { get; } = new HashSet<string>(); | ||
|
||
[JsonProperty("source", ObjectCreationHandling = ObjectCreationHandling.Reuse)] | ||
public string Source { get; } = ""; | ||
} | ||
public class CommandsConfiguration | ||
{ | ||
public CommandsConfiguration() | ||
{ | ||
} | ||
|
||
[JsonProperty("new", ObjectCreationHandling = ObjectCreationHandling.Reuse)] | ||
public NewCommandConfiguration NewCommand { get; } = new NewCommandConfiguration(); | ||
} | ||
|
||
public class NewCommandConfiguration | ||
{ | ||
public NewCommandConfiguration() | ||
{ | ||
} | ||
|
||
[JsonProperty("properties", ObjectCreationHandling = ObjectCreationHandling.Reuse)] | ||
public Dictionary<string, string> Properties { get; } = new Dictionary<string, string>(); | ||
} | ||
|
||
/// <summary> | ||
/// The main settings for the Chocolatey language service. | ||
/// </summary> | ||
public class LanguageConfiguration | ||
{ | ||
/// <summary> | ||
/// Create a new <see cref="LanguageConfiguration"/>. | ||
/// </summary> | ||
public LanguageConfiguration() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Allow suppressing of requirements | ||
/// </summary> | ||
[JsonProperty("allowSuppressionOfRequirements")] | ||
public bool AllowSuppressionOfRequirements { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Disable the language service? | ||
/// </summary> | ||
[JsonProperty("disableLanguageService")] | ||
public bool DisableLanguageService { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Types of object from the current project to include when offering completions. | ||
/// </summary> | ||
[JsonProperty("suppressedRules", ObjectCreationHandling = ObjectCreationHandling.Reuse)] | ||
public HashSet<string> SuppressedRules { get; } = new HashSet<string>(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Chocolatey.Language.Server/Engine/IConfigurationProvider.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,7 @@ | ||
namespace Chocolatey.Language.Server.Engine | ||
{ | ||
public interface IConfigurationProvider | ||
{ | ||
Configuration Configuration { get; } | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
....Language.Server/IEnumerableExtensions.cs → ...erver/Extensions/IEnumerableExtensions.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
117 changes: 117 additions & 0 deletions
117
src/Chocolatey.Language.Server/Extensions/ProtocolExtensions.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,117 @@ | ||
using Chocolatey.Language.Server.Engine; | ||
using Chocolatey.Language.Server.CustomProtocol; | ||
using OmniSharp.Extensions.LanguageServer; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
using OmniSharp.Extensions.LanguageServer.Server; | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System.Linq; | ||
|
||
namespace Chocolatey.Language.Server.Extensions | ||
{ | ||
/// <summary> | ||
/// Custom Language Server Protocol extensions. | ||
/// </summary> | ||
public static class ProtocolExtensions | ||
{ | ||
/// <summary> | ||
/// Update the configuration from the specified configuration-change notification. | ||
/// </summary> | ||
/// <param name="configuration"> | ||
/// The <see cref="Configuration"/> to update. | ||
/// </param> | ||
/// <param name="request"> | ||
/// The configuration-change notification. | ||
/// </param> | ||
public static void UpdateFrom(this Configuration configuration, DidChangeConfigurationObjectParams request) | ||
{ | ||
if (configuration == null) | ||
{ | ||
throw new ArgumentNullException(nameof(configuration)); | ||
} | ||
|
||
if (request == null) | ||
{ | ||
throw new ArgumentNullException(nameof(request)); | ||
} | ||
|
||
JObject json = request.Settings?.SelectToken(Configuration.SectionName) as JObject; | ||
|
||
if (json == null) | ||
{ | ||
return; | ||
} | ||
|
||
configuration.UpdateFrom(json); | ||
} | ||
|
||
/// <summary> | ||
/// Update the configuration from the specified initialisation request. | ||
/// </summary> | ||
/// <param name="configuration"> | ||
/// The <see cref="Configuration"/> to update. | ||
/// </param> | ||
/// <param name="request"> | ||
/// The initialisation request. | ||
/// </param> | ||
public static void UpdateFrom(this Configuration configuration, InitializeParams request) | ||
{ | ||
if (configuration == null) | ||
{ | ||
throw new ArgumentNullException(nameof(configuration)); | ||
} | ||
|
||
if (request == null) | ||
{ | ||
throw new ArgumentNullException(nameof(request)); | ||
} | ||
|
||
JToken initializationParameters = request.InitializationOptions as JToken; | ||
|
||
if (initializationParameters == null) | ||
{ | ||
return; | ||
} | ||
|
||
JObject json = initializationParameters.SelectToken(Configuration.SectionName) as JObject; | ||
|
||
if (json == null) | ||
{ | ||
return; | ||
} | ||
|
||
configuration.UpdateFrom(json); | ||
} | ||
|
||
/// <summary> | ||
/// Update the configuration from the specified JSON. | ||
/// </summary> | ||
/// <param name="configuration"> | ||
/// The <see cref="Configuration"/> to update. | ||
/// </param> | ||
/// <param name="settingsJson"> | ||
/// A <see cref="JObject"/> representing the flattened settings JSON from VS Code. | ||
/// </param> | ||
public static void UpdateFrom(this Configuration configuration, JObject settingsJson) | ||
{ | ||
if (configuration == null) | ||
{ | ||
throw new ArgumentNullException(nameof(configuration)); | ||
} | ||
|
||
if (settingsJson == null) | ||
{ | ||
throw new ArgumentNullException(nameof(settingsJson)); | ||
} | ||
|
||
// Temporary workaround - JsonSerializer.Populate reuses existing HashSet. | ||
configuration.Language.SuppressedRules.Clear(); | ||
|
||
using (JsonReader reader = settingsJson.CreateReader()) | ||
{ | ||
new JsonSerializer().Populate(reader, configuration); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.