Stubbing out query execution settings

Adding a setting for batch separator.
Very small refactor to WorkspaceService that will create the basic
settings upon construction of the object.
This commit is contained in:
benrr101
2016-08-17 18:24:20 -07:00
parent e9814435d8
commit dee490341d
4 changed files with 48 additions and 2 deletions

View File

@@ -10,6 +10,8 @@ using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.Workspace;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
{
@@ -60,6 +62,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
private readonly Lazy<ConcurrentDictionary<string, Query>> queries =
new Lazy<ConcurrentDictionary<string, Query>>(() => new ConcurrentDictionary<string, Query>());
private SqlToolsSettings Settings { get { return WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings; } }
#endregion
/// <summary>
@@ -81,6 +85,13 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
Dispose();
return Task.FromResult(0);
});
// Register a handler for when the configuration changes
WorkspaceService<SqlToolsSettings>.Instance.RegisterConfigChangeCallback((oldSettings, newSettings, eventContext) =>
{
Settings.QueryExecutionSettings.Update(newSettings.QueryExecutionSettings);
return Task.FromResult(0);
});
}
#region Request Handlers
@@ -281,8 +292,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
return;
}
// Retrieve the current settings for executing the query with
QueryExecutionSettings settings = WorkspaceService<SqlToolsSettings>.Instance.CurrentSettings.QueryExecutionSettings;
// Launch the query and respond with successfully launching it
Task executeTask = query.Execute();
Task executeTask = query.Execute(/*settings*/);
await requestContext.SendResult(new QueryExecuteResult
{
Messages = null

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.SqlTools.ServiceLayer.SqlContext
{
public class QueryExecutionSettings
{
private const string DefaultBatchSeparator = "GO";
private string batchSeparator;
public string BatchSeparator
{
get { return batchSeparator ?? DefaultBatchSeparator; }
set { batchSeparator = value; }
}
/// <summary>
/// Update the current settings with the new settings
/// </summary>
/// <param name="newSettings">The new settings</param>
public void Update(QueryExecutionSettings newSettings)
{
BatchSeparator = newSettings.BatchSeparator;
}
}
}

View File

@@ -31,6 +31,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext
this.ScriptAnalysis.Update(settings.ScriptAnalysis, workspaceRootPath);
}
}
public QueryExecutionSettings QueryExecutionSettings { get; set; }
}
/// <summary>

View File

@@ -44,6 +44,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace
ConfigChangeCallbacks = new List<ConfigChangeCallback>();
TextDocChangeCallbacks = new List<TextDocChangeCallback>();
TextDocOpenCallbacks = new List<TextDocOpenCallback>();
CurrentSettings = new TConfig();
}
#endregion
@@ -101,7 +103,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace
{
// Create a workspace that will handle state for the session
Workspace = new Workspace();
CurrentSettings = new TConfig();
// Register the handlers for when changes to the workspae occur
serviceHost.SetEventHandler(DidChangeTextDocumentNotification.Type, HandleDidChangeTextDocumentNotification);