Added support for T-SQL parse (#642)

* added support for t-sql parse

* added syntax parse to language service instead

* fixed misleading error

* code review comments
This commit is contained in:
Aditya Bist
2018-06-26 14:19:05 -07:00
committed by GitHub
parent 539d579a9b
commit 7c7395fce0
4 changed files with 76 additions and 5 deletions

View File

@@ -702,7 +702,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{
if (string.IsNullOrWhiteSpace(stepInfo.JobName))
{
return new Tuple<bool, string>(false, "JobId cannot be null");
return new Tuple<bool, string>(false, "JobName cannot be null");
}
JobData jobData;

View File

@@ -0,0 +1,31 @@
//
// 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.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts
{
public class SyntaxParseParams
{
public string OwnerUri { get; set; }
public string Query { get; set; }
}
public class SyntaxParseResult
{
public bool Parseable { get; set; }
public string[] Errors { get; set; }
}
public class SyntaxParseRequest
{
public static readonly
RequestType<SyntaxParseParams, SyntaxParseResult> Type =
RequestType<SyntaxParseParams, SyntaxParseResult>.Create("query/syntaxparse");
}
}

View File

@@ -243,6 +243,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
serviceHost.SetRequestHandler(HoverRequest.Type, HandleHoverRequest);
serviceHost.SetRequestHandler(CompletionRequest.Type, HandleCompletionRequest);
serviceHost.SetRequestHandler(DefinitionRequest.Type, HandleDefinitionRequest);
serviceHost.SetRequestHandler(SyntaxParseRequest.Type, HandleSyntaxParseRequest);
serviceHost.SetEventHandler(RebuildIntelliSenseNotification.Type, HandleRebuildIntelliSenseNotification);
serviceHost.SetEventHandler(LanguageFlavorChangeNotification.Type, HandleDidChangeLanguageFlavorNotification);
@@ -281,6 +282,42 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
#region Request Handlers
/// <summary>
/// T-SQL syntax parse request callback
/// </summary>
/// <param name="param"></param>
/// <param name="requestContext"></param>
/// <returns></returns>
internal async Task HandleSyntaxParseRequest(SyntaxParseParams param, RequestContext<SyntaxParseResult> requestContext)
{
await Task.Run(async () =>
{
try
{
ParseResult result = Parser.Parse(param.Query);
SyntaxParseResult syntaxResult = new SyntaxParseResult();
if (result != null && result.Errors.Count() == 0)
{
syntaxResult.Parseable = true;
} else
{
syntaxResult.Parseable = false;
string[] errorMessages = new string[result.Errors.Count()];
for (int i = 0; i < result.Errors.Count(); i++)
{
errorMessages[i] = result.Errors.ElementAt(i).Message;
}
syntaxResult.Errors = errorMessages;
}
await requestContext.SendResult(syntaxResult);
}
catch (Exception ex)
{
await requestContext.SendError(ex.ToString());
}
});
}
/// <summary>
/// Auto-complete completion provider request callback
/// </summary>
@@ -499,7 +536,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
await requestContext.SendResult(hover);
}
}
await requestContext.SendResult(null);
}
catch (Exception ex)

View File

@@ -3,20 +3,22 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.Workspace;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Microsoft.SqlTools.Utility;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
{
@@ -573,6 +575,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
#region Private Helpers
private Query CreateQuery(ExecuteRequestParamsBase executeParams, ConnectionInfo connInfo)
{
// Attempt to get the connection for the editor