mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Kusto Format Fix (#1251)
* Added Format function to DataSourceFactory. Removed unsued code / commented code in TSqlFormatterService. * Renamed TSqlFormatterService to FormatterService in Kusto
This commit is contained in:
@@ -2,16 +2,19 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Composition;
|
using System.Composition;
|
||||||
using Kusto.Data;
|
using Kusto.Data;
|
||||||
|
using Kusto.Language;
|
||||||
|
using Kusto.Language.Editor;
|
||||||
using Microsoft.Kusto.ServiceLayer.Connection.Contracts;
|
using Microsoft.Kusto.ServiceLayer.Connection.Contracts;
|
||||||
using Microsoft.Kusto.ServiceLayer.DataSource.Contracts;
|
using Microsoft.Kusto.ServiceLayer.DataSource.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||||
using Microsoft.Kusto.ServiceLayer.DataSource.Intellisense;
|
using Microsoft.Kusto.ServiceLayer.DataSource.Intellisense;
|
||||||
using Microsoft.Kusto.ServiceLayer.DataSource.Kusto;
|
using Microsoft.Kusto.ServiceLayer.DataSource.Kusto;
|
||||||
using Microsoft.Kusto.ServiceLayer.DataSource.Monitor;
|
using Microsoft.Kusto.ServiceLayer.DataSource.Monitor;
|
||||||
|
using Microsoft.Kusto.ServiceLayer.Formatter;
|
||||||
using Microsoft.Kusto.ServiceLayer.LanguageServices;
|
using Microsoft.Kusto.ServiceLayer.LanguageServices;
|
||||||
using Microsoft.Kusto.ServiceLayer.LanguageServices.Contracts;
|
|
||||||
using Microsoft.Kusto.ServiceLayer.Utility;
|
using Microsoft.Kusto.ServiceLayer.Utility;
|
||||||
using Microsoft.Kusto.ServiceLayer.Workspace.Contracts;
|
using Microsoft.Kusto.ServiceLayer.Workspace.Contracts;
|
||||||
|
using CompletionItem = Microsoft.Kusto.ServiceLayer.LanguageServices.Contracts.CompletionItem;
|
||||||
|
|
||||||
namespace Microsoft.Kusto.ServiceLayer.DataSource
|
namespace Microsoft.Kusto.ServiceLayer.DataSource
|
||||||
{
|
{
|
||||||
@@ -157,5 +160,13 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource
|
|||||||
{
|
{
|
||||||
return Program.ServiceName.Contains("Kusto") ? KustoProviderDescription : LogAnalyticsProviderDescription;
|
return Program.ServiceName.Contains("Kusto") ? KustoProviderDescription : LogAnalyticsProviderDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string Format(string input, FormatOptions options)
|
||||||
|
{
|
||||||
|
var code = KustoCode.ParseAndAnalyze(input);
|
||||||
|
var kustoCodeService = new KustoCodeService(code);
|
||||||
|
var formattedText = kustoCodeService.GetFormattedText();
|
||||||
|
return formattedText.Text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Kusto.ServiceLayer.DataSource;
|
||||||
using Microsoft.SqlTools.Extensibility;
|
using Microsoft.SqlTools.Extensibility;
|
||||||
using Microsoft.SqlTools.Hosting;
|
using Microsoft.SqlTools.Hosting;
|
||||||
using Microsoft.SqlTools.Hosting.Protocol;
|
using Microsoft.SqlTools.Hosting.Protocol;
|
||||||
@@ -18,18 +18,19 @@ using Microsoft.Kusto.ServiceLayer.SqlContext;
|
|||||||
using Microsoft.Kusto.ServiceLayer.Workspace;
|
using Microsoft.Kusto.ServiceLayer.Workspace;
|
||||||
using Microsoft.Kusto.ServiceLayer.Workspace.Contracts;
|
using Microsoft.Kusto.ServiceLayer.Workspace.Contracts;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.Utility;
|
||||||
|
using FormattingOptions = Microsoft.Kusto.ServiceLayer.Formatter.Contracts.FormattingOptions;
|
||||||
using Range = Microsoft.Kusto.ServiceLayer.Workspace.Contracts.Range;
|
using Range = Microsoft.Kusto.ServiceLayer.Workspace.Contracts.Range;
|
||||||
|
|
||||||
namespace Microsoft.Kusto.ServiceLayer.Formatter
|
namespace Microsoft.Kusto.ServiceLayer.Formatter
|
||||||
{
|
{
|
||||||
|
|
||||||
public class TSqlFormatterService : HostedService<TSqlFormatterService>, IComposableService
|
public class FormatterService : HostedService<FormatterService>, IComposableService
|
||||||
{
|
{
|
||||||
private FormatterSettings settings;
|
private FormatterSettings settings;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The default constructor is required for MEF-based composable services
|
/// The default constructor is required for MEF-based composable services
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TSqlFormatterService()
|
public FormatterService()
|
||||||
{
|
{
|
||||||
settings = new FormatterSettings();
|
settings = new FormatterSettings();
|
||||||
}
|
}
|
||||||
@@ -164,8 +165,7 @@ namespace Microsoft.Kusto.ServiceLayer.Formatter
|
|||||||
|
|
||||||
FormatOptions options = GetOptions(docFormatParams);
|
FormatOptions options = GetOptions(docFormatParams);
|
||||||
List<TextEdit> edits = new List<TextEdit>();
|
List<TextEdit> edits = new List<TextEdit>();
|
||||||
edit.NewText = Format(text, options, false);
|
edit.NewText = DataSourceFactory.Format(text, options);
|
||||||
// TODO do not add if no formatting needed?
|
|
||||||
edits.Add(edit);
|
edits.Add(edit);
|
||||||
return edits.ToArray();
|
return edits.ToArray();
|
||||||
}
|
}
|
||||||
@@ -239,62 +239,6 @@ namespace Microsoft.Kusto.ServiceLayer.Formatter
|
|||||||
await requestContext.SendError(ex.ToString());
|
await requestContext.SendError(ex.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public string Format(TextReader input)
|
|
||||||
{
|
|
||||||
string originalSql = input.ReadToEnd();
|
|
||||||
return Format(originalSql, new FormatOptions());
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Format(string input, FormatOptions options)
|
|
||||||
{
|
|
||||||
return Format(input, options, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Format(string input, FormatOptions options, bool verifyOutput)
|
|
||||||
{
|
|
||||||
string result = null;
|
|
||||||
//TODOKusto: Implement formatting for Kusto generically here.
|
|
||||||
//var kustoCodeService = new KustoCodeService(input, GlobalState.Default);
|
|
||||||
//var formattedText = kustoCodeService.GetFormattedText();
|
|
||||||
//DoFormat(input, options, verifyOutput, visitor =>
|
|
||||||
//{
|
|
||||||
//result = formattedText.Text;
|
|
||||||
//});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*public void Format(string input, FormatOptions options, bool verifyOutput, Replacement.OnReplace replace)
|
|
||||||
{
|
|
||||||
DoFormat(input, options, verifyOutput, visitor =>
|
|
||||||
{
|
|
||||||
foreach (Replacement r in visitor.Context.Replacements)
|
|
||||||
{
|
|
||||||
r.Apply(replace);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DoFormat(string input, FormatOptions options, bool verifyOutput, Action<FormatterVisitor> postFormatAction)
|
|
||||||
{
|
|
||||||
Validate.IsNotNull(nameof(input), input);
|
|
||||||
Validate.IsNotNull(nameof(options), options);
|
|
||||||
|
|
||||||
ParseResult result = Parser.Parse(input);
|
|
||||||
FormatContext context = new FormatContext(result.Script, options);
|
|
||||||
|
|
||||||
FormatterVisitor visitor = new FormatterVisitor(context, ServiceProvider);
|
|
||||||
result.Script.Accept(visitor);
|
|
||||||
if (verifyOutput)
|
|
||||||
{
|
|
||||||
visitor.VerifyFormat();
|
|
||||||
}
|
|
||||||
|
|
||||||
postFormatAction?.Invoke(visitor);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class RangeExtensions
|
internal static class RangeExtensions
|
||||||
Reference in New Issue
Block a user