mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Exposing the DisplayBitAsNumber setting (#248)
* Exposing the DisplayBitAsNumber setting * Properly wiring up the settings for query execution service * Fixing broken unit test
This commit is contained in:
@@ -37,12 +37,14 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
{
|
{
|
||||||
ConnectionService = ConnectionService.Instance;
|
ConnectionService = ConnectionService.Instance;
|
||||||
WorkspaceService = WorkspaceService<SqlToolsSettings>.Instance;
|
WorkspaceService = WorkspaceService<SqlToolsSettings>.Instance;
|
||||||
|
Settings = new SqlToolsSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal QueryExecutionService(ConnectionService connService, WorkspaceService<SqlToolsSettings> workspaceService)
|
internal QueryExecutionService(ConnectionService connService, WorkspaceService<SqlToolsSettings> workspaceService)
|
||||||
{
|
{
|
||||||
ConnectionService = connService;
|
ConnectionService = connService;
|
||||||
WorkspaceService = workspaceService;
|
WorkspaceService = workspaceService;
|
||||||
|
Settings = new SqlToolsSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -105,7 +107,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
private readonly Lazy<ConcurrentDictionary<string, Query>> queries =
|
private readonly Lazy<ConcurrentDictionary<string, Query>> queries =
|
||||||
new Lazy<ConcurrentDictionary<string, Query>>(() => new ConcurrentDictionary<string, Query>());
|
new Lazy<ConcurrentDictionary<string, Query>>(() => new ConcurrentDictionary<string, Query>());
|
||||||
|
|
||||||
private SqlToolsSettings Settings => WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings;
|
/// <summary>
|
||||||
|
/// Settings that will be used to execute queries. Internal for unit testing
|
||||||
|
/// </summary>
|
||||||
|
internal SqlToolsSettings Settings { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -134,11 +139,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Register a handler for when the configuration changes
|
// Register a handler for when the configuration changes
|
||||||
WorkspaceService.RegisterConfigChangeCallback((oldSettings, newSettings, eventContext) =>
|
WorkspaceService.RegisterConfigChangeCallback(UpdateSettings);
|
||||||
{
|
|
||||||
Settings.QueryExecutionSettings.Update(newSettings.QueryExecutionSettings);
|
|
||||||
return Task.FromResult(0);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Request Handlers
|
#region Request Handlers
|
||||||
@@ -410,13 +411,13 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the current settings for executing the query with
|
// Retrieve the current settings for executing the query with
|
||||||
QueryExecutionSettings settings = WorkspaceService.CurrentSettings.QueryExecutionSettings;
|
QueryExecutionSettings querySettings = Settings.QueryExecutionSettings;
|
||||||
|
|
||||||
// Apply execution parameter settings
|
// Apply execution parameter settings
|
||||||
settings.ExecutionPlanOptions = executeParams.ExecutionPlanOptions;
|
querySettings.ExecutionPlanOptions = executeParams.ExecutionPlanOptions;
|
||||||
|
|
||||||
// If we can't add the query now, it's assumed the query is in progress
|
// If we can't add the query now, it's assumed the query is in progress
|
||||||
Query newQuery = new Query(GetSqlText(executeParams), connectionInfo, settings, BufferFileFactory);
|
Query newQuery = new Query(GetSqlText(executeParams), connectionInfo, querySettings, BufferFileFactory);
|
||||||
if (!ActiveQueries.TryAdd(executeParams.OwnerUri, newQuery))
|
if (!ActiveQueries.TryAdd(executeParams.OwnerUri, newQuery))
|
||||||
{
|
{
|
||||||
await failureAction(SR.QueryServiceQueryInProgress);
|
await failureAction(SR.QueryServiceQueryInProgress);
|
||||||
@@ -591,6 +592,13 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
throw new InvalidCastException("Invalid request type");
|
throw new InvalidCastException("Invalid request type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Internal for testing purposes
|
||||||
|
internal Task UpdateSettings(SqlToolsSettings newSettings, SqlToolsSettings oldSettings, EventContext eventContext)
|
||||||
|
{
|
||||||
|
Settings.QueryExecutionSettings.Update(newSettings.QueryExecutionSettings);
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IDisposable Implementation
|
#region IDisposable Implementation
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the query execution settings
|
/// Gets or sets the query execution settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[JsonProperty("query")]
|
||||||
public QueryExecutionSettings QueryExecutionSettings { get; set; }
|
public QueryExecutionSettings QueryExecutionSettings { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||||
|
{
|
||||||
|
public class SettingsTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void ValidateQueryExecuteDefaults()
|
||||||
|
{
|
||||||
|
// If: I create a new settings object
|
||||||
|
var sqlToolsSettings = new SqlToolsSettings();
|
||||||
|
|
||||||
|
// Then: The default values should be as expected
|
||||||
|
Assert.Equal("GO", sqlToolsSettings.QueryExecutionSettings.BatchSeparator);
|
||||||
|
Assert.Equal(ushort.MaxValue, sqlToolsSettings.QueryExecutionSettings.MaxCharsToStore);
|
||||||
|
Assert.Equal(2*1024*1024, sqlToolsSettings.QueryExecutionSettings.MaxXmlCharsToStore);
|
||||||
|
Assert.False(sqlToolsSettings.QueryExecutionSettings.ExecutionPlanOptions.IncludeActualExecutionPlanXml);
|
||||||
|
Assert.False(sqlToolsSettings.QueryExecutionSettings.ExecutionPlanOptions.IncludeEstimatedExecutionPlanXml);
|
||||||
|
Assert.True(sqlToolsSettings.QueryExecutionSettings.DisplayBitAsNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ValidateSettingsParsedFromJson()
|
||||||
|
{
|
||||||
|
// NOTE: Only testing displayBitAsNumber for now because it is the only one piped through
|
||||||
|
const string settingsJson = @"{"
|
||||||
|
+ @"""params"": {"
|
||||||
|
+ @"""mssql"": {"
|
||||||
|
+ @"""query"": {"
|
||||||
|
+ @"displayBitAsNumber: false"
|
||||||
|
+ @"}"
|
||||||
|
+ @"}"
|
||||||
|
+ @"}"
|
||||||
|
+ @"}";
|
||||||
|
|
||||||
|
// If: I parse the settings JSON object
|
||||||
|
JObject message = JObject.Parse(settingsJson);
|
||||||
|
JToken messageParams;
|
||||||
|
Assert.True(message.TryGetValue("params", out messageParams));
|
||||||
|
SqlToolsSettings sqlToolsSettings = messageParams.ToObject<SqlToolsSettings>();
|
||||||
|
|
||||||
|
// Then: The values defined in the JSON should propagate to the setting object
|
||||||
|
Assert.False(sqlToolsSettings.QueryExecutionSettings.DisplayBitAsNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ValidateSettingsObjectUpdates()
|
||||||
|
{
|
||||||
|
// If: I update a settings object with a new settings object
|
||||||
|
var qes = new QueryExecutionService(null, null);
|
||||||
|
SqlToolsSettings settings = new SqlToolsSettings()
|
||||||
|
{
|
||||||
|
SqlTools = new SqlToolsSettingsValues
|
||||||
|
{
|
||||||
|
QueryExecutionSettings = new QueryExecutionSettings
|
||||||
|
{
|
||||||
|
DisplayBitAsNumber = false,
|
||||||
|
MaxXmlCharsToStore = 1,
|
||||||
|
MaxCharsToStore = 1,
|
||||||
|
ExecutionPlanOptions = new ExecutionPlanOptions
|
||||||
|
{
|
||||||
|
IncludeActualExecutionPlanXml = true,
|
||||||
|
IncludeEstimatedExecutionPlanXml = true
|
||||||
|
},
|
||||||
|
BatchSeparator = "YO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
qes.UpdateSettings(settings, null, new EventContext());
|
||||||
|
|
||||||
|
// Then: The settings object should match what it was updated to
|
||||||
|
Assert.False(qes.Settings.QueryExecutionSettings.DisplayBitAsNumber);
|
||||||
|
Assert.True(qes.Settings.QueryExecutionSettings.ExecutionPlanOptions.IncludeActualExecutionPlanXml);
|
||||||
|
Assert.True(qes.Settings.QueryExecutionSettings.ExecutionPlanOptions.IncludeEstimatedExecutionPlanXml);
|
||||||
|
Assert.Equal(1, qes.Settings.QueryExecutionSettings.MaxCharsToStore);
|
||||||
|
Assert.Equal(1, qes.Settings.QueryExecutionSettings.MaxXmlCharsToStore);
|
||||||
|
Assert.Equal("YO", qes.Settings.QueryExecutionSettings.BatchSeparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user