mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-20 09:35:38 -05:00
Feature/sqlcmd : Enable running scripts with SQLCMD variables - Part 1 (#839)
* Part1 : Changes to make cmdcmd script to work with parameters in script * Stop SQL intellisense for SQLCMD * Adding test for Intellisense handling of SQLCMD page * Removing unintentional spacing changes caused by formatting * Updating with smaller CR comments. Will discuss regarding script vs other options in batch info * Removing unintentional change * Adding latest PR comments
This commit is contained in:
@@ -58,12 +58,16 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private / internal instance fields and constructor
|
||||
private const int PrepopulateBindTimeout = 60000;
|
||||
#region Instance fields and constructor
|
||||
|
||||
public const string SQL_LANG = "SQL";
|
||||
|
||||
public const string SQL_CMD_LANG = "SQLCMD";
|
||||
|
||||
private const int OneSecond = 1000;
|
||||
|
||||
private const int PrepopulateBindTimeout = 60000;
|
||||
|
||||
internal const string DefaultBatchSeperator = "GO";
|
||||
|
||||
internal const int DiagnosticParseDelay = 750;
|
||||
@@ -80,6 +84,9 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
|
||||
internal const int CompletionExtTimeout = 200;
|
||||
|
||||
// For testability only
|
||||
internal Task DelayedDiagnosticsTask = null;
|
||||
|
||||
private ConnectionService connectionService = null;
|
||||
|
||||
private WorkspaceService<SqlToolsSettings> workspaceServiceInstance;
|
||||
@@ -836,7 +843,10 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
if (SQL_LANG.Equals(changeParams.Language, StringComparison.OrdinalIgnoreCase)) {
|
||||
shouldBlock = !ServiceHost.ProviderName.Equals(changeParams.Flavor, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
if (SQL_CMD_LANG.Equals(changeParams.Language, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
shouldBlock = true; // the provider will continue to be mssql
|
||||
}
|
||||
if (shouldBlock) {
|
||||
this.nonMssqlUriMap.AddOrUpdate(changeParams.Uri, true, (k, oldValue) => true);
|
||||
if (CurrentWorkspace.ContainsFile(changeParams.Uri))
|
||||
@@ -848,7 +858,10 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
{
|
||||
bool value;
|
||||
this.nonMssqlUriMap.TryRemove(changeParams.Uri, out value);
|
||||
}
|
||||
// should rebuild intellisense when re-considering as sql
|
||||
RebuildIntelliSenseParams param = new RebuildIntelliSenseParams { OwnerUri = changeParams.Uri };
|
||||
await HandleRebuildIntelliSenseNotification(param, eventContext);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1733,7 +1746,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
existingRequestCancellation = new CancellationTokenSource();
|
||||
Task.Factory.StartNew(
|
||||
() =>
|
||||
DelayThenInvokeDiagnostics(
|
||||
this.DelayedDiagnosticsTask = DelayThenInvokeDiagnostics(
|
||||
LanguageService.DiagnosticParseDelay,
|
||||
filesToAnalyze,
|
||||
eventContext,
|
||||
|
||||
@@ -116,7 +116,12 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
|
||||
// Process the query into batches
|
||||
BatchParserWrapper parser = new BatchParserWrapper();
|
||||
List<BatchDefinition> parserResult = parser.GetBatches(queryText);
|
||||
ExecutionEngineConditions conditions = null;
|
||||
if (settings.IsSqlCmdMode)
|
||||
{
|
||||
conditions = new ExecutionEngineConditions() { IsSqlCmd = settings.IsSqlCmdMode };
|
||||
}
|
||||
List<BatchDefinition> parserResult = parser.GetBatches(queryText, conditions);
|
||||
|
||||
var batchSelection = parserResult
|
||||
.Select((batchDefinition, index) =>
|
||||
|
||||
@@ -163,6 +163,11 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext
|
||||
/// </summary>
|
||||
private const int DefaultQueryGovernorCostLimit = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Default value for flag to run query in sqlcmd mode
|
||||
/// </summary>
|
||||
private bool DefaultSqlCmdMode = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Member Variables
|
||||
@@ -633,6 +638,21 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set sqlCmd Mode
|
||||
/// </summary>
|
||||
public bool IsSqlCmdMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetOptionValue<bool>("isSqlCmdMode", DefaultSqlCmdMode);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetOptionValue("isSqlCmdMode", value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
@@ -670,6 +690,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext
|
||||
AnsiPadding = newSettings.AnsiPadding;
|
||||
AnsiWarnings = newSettings.AnsiWarnings;
|
||||
AnsiNulls = newSettings.AnsiNulls;
|
||||
IsSqlCmdMode = newSettings.IsSqlCmdMode;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user