diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs index 21bd80cc..e0e43587 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs @@ -702,7 +702,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent { if (string.IsNullOrWhiteSpace(stepInfo.JobName)) { - return new Tuple(false, "JobId cannot be null"); + return new Tuple(false, "JobName cannot be null"); } JobData jobData; diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/SyntaxParse.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/SyntaxParse.cs new file mode 100644 index 00000000..7d26c4d1 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/SyntaxParse.cs @@ -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 Type = + RequestType.Create("query/syntaxparse"); + } +} + diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs index fcd7e177..23b547e9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs @@ -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 + /// + /// T-SQL syntax parse request callback + /// + /// + /// + /// + internal async Task HandleSyntaxParseRequest(SyntaxParseParams param, RequestContext 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()); + } + }); + } + /// /// Auto-complete completion provider request callback /// @@ -499,7 +536,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices await requestContext.SendResult(hover); } } - await requestContext.SendResult(null); } catch (Exception ex) diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs index e8b76a6a..625cd460 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs @@ -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