-
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.
(GH-121) Refactoring of ConfigurationHandler
- Based on the work in this repository: https://github.com/tintoy/msbuild-project-tools-server - Needed updated due to changes in most recent version of Omnisharp
- Loading branch information
Showing
10 changed files
with
398 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/Chocolatey.Language.Server.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}", | ||
"console": "internalConsole", | ||
"stopAtEntry": false, | ||
"internalConsoleOptions": "openOnSessionStart" | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach", | ||
"processId": "${command:pickProcess}" | ||
} | ||
] | ||
} |
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,15 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/Chocolatey.Language.Server.csproj" | ||
], | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
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,45 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Chocolatey.Language.Server | ||
{ | ||
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 = "chocoLanguageServer"; | ||
|
||
/// <summary> | ||
/// The MSBuild language service's main configuration. | ||
/// </summary> | ||
[JsonProperty("language", ObjectCreationHandling = ObjectCreationHandling.Reuse)] | ||
public LanguageConfiguration Language { get; } = new LanguageConfiguration(); | ||
} | ||
|
||
/// <summary> | ||
/// The main settings for the MSBuild language service. | ||
/// </summary> | ||
public class LanguageConfiguration | ||
{ | ||
/// <summary> | ||
/// Create a new <see cref="LanguageConfiguration"/>. | ||
/// </summary> | ||
public LanguageConfiguration() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Disable the language service? | ||
/// </summary> | ||
[JsonProperty("useClassicProvider")] | ||
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>(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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; | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/Chocolatey.Language.Server/CustomProtocol/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,115 @@ | ||
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.CustomProtocol | ||
{ | ||
/// <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.