mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-20 01:25:41 -05:00
* Refactored Kusto.ServiceLayer to pass ConnectionDetails to DataSourceFactory instead of connection string. Created KustoConnectionDetails to map needed details to KustoClient. * Removed unused ScriptingScriptOperation from KustoServiceLayer. * Created DstsAuthenticationManager and moved logic for getting DstsToken. Updated error message for failing to create KustoConnection. * Removed DstsAuthenticationManager.cs. Refactored DataSourceFactory to retrieve UserToken from ConnectionDetails. * Renamed AzureAccountToken in ConnectionDetails to AccountToken. Changed mapping to KustoConnectionDetails based on the AccountToken. * Removed Kusto.Data reference from ConnectionService and ScriptingListObjectsOperation. Moved creation of KustoConnectionStringBuilder to DataSourceFactory * Added accountToken validation to DataSourceFactory Create. * Renamed KustoConnectionDetails to DataSourceConnectionDetails. Renamed AzureToken to AuthToken. * Refactored SchemaState and intellisense out of KustoClient to KustoIntellisenseClient. Added IIntellisenseClient. Added unit tests for KustoIntellisenseClient and KustoClient. * Removed unused property dataSourceFactory from LanguageService > InitializeService. Moved KustoIntellisense functions from KustoIntellisenseHelper to KustoIntellisenseClient and made SchemaState private. Added IIntellisenseClient to IDataSource. * Renamed directory from DataSourceIntellisense to Intellisense and updated namespace. Fixed namespace in ScriptDocumentInfo.
91 lines
3.9 KiB
C#
91 lines
3.9 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Kusto.Language;
|
|
using Kusto.Language.Editor;
|
|
using Microsoft.Kusto.ServiceLayer.LanguageServices;
|
|
using Microsoft.Kusto.ServiceLayer.LanguageServices.Contracts;
|
|
using Microsoft.Kusto.ServiceLayer.Workspace.Contracts;
|
|
|
|
namespace Microsoft.Kusto.ServiceLayer.DataSource.Intellisense
|
|
{
|
|
/// <summary>
|
|
/// Kusto specific class for intellisense helper functions.
|
|
/// </summary>
|
|
public class KustoIntellisenseHelper
|
|
{
|
|
/// <summary>
|
|
/// Gets default keyword when user if not connected to any Kusto cluster.
|
|
/// </summary>
|
|
public static LanguageServices.Contracts.CompletionItem[] GetDefaultKeywords(
|
|
ScriptDocumentInfo scriptDocumentInfo, Position textDocumentPosition)
|
|
{
|
|
var kustoCodeService = new KustoCodeService(scriptDocumentInfo.Contents, GlobalState.Default);
|
|
var script = CodeScript.From(scriptDocumentInfo.Contents, GlobalState.Default);
|
|
script.TryGetTextPosition(textDocumentPosition.Line + 1, textDocumentPosition.Character,
|
|
out int position); // Gets the actual offset based on line and local offset
|
|
var completion = kustoCodeService.GetCompletionItems(position);
|
|
|
|
List<LanguageServices.Contracts.CompletionItem> completions =
|
|
new List<LanguageServices.Contracts.CompletionItem>();
|
|
foreach (var autoCompleteItem in completion.Items)
|
|
{
|
|
var label = autoCompleteItem.DisplayText;
|
|
// convert the completion item candidates into vscode format CompletionItems
|
|
completions.Add(AutoCompleteHelper.CreateCompletionItem(label, label + " keyword", label,
|
|
CompletionItemKind.Keyword, scriptDocumentInfo.StartLine, scriptDocumentInfo.StartColumn,
|
|
textDocumentPosition.Character));
|
|
}
|
|
|
|
return completions.ToArray();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets default diagnostics when user if not connected to any Kusto cluster.
|
|
/// </summary>
|
|
public static ScriptFileMarker[] GetDefaultDiagnostics(ScriptParseInfo parseInfo, ScriptFile scriptFile,
|
|
string queryText)
|
|
{
|
|
var kustoCodeService = new KustoCodeService(queryText, GlobalState.Default);
|
|
var script = CodeScript.From(queryText, GlobalState.Default);
|
|
var parseResult = kustoCodeService.GetDiagnostics();
|
|
|
|
parseInfo.ParseResult = parseResult;
|
|
|
|
// build a list of Kusto script file markers from the errors.
|
|
List<ScriptFileMarker> markers = new List<ScriptFileMarker>();
|
|
if (parseResult != null && parseResult.Count() > 0)
|
|
{
|
|
foreach (var error in parseResult)
|
|
{
|
|
script.TryGetLineAndOffset(error.Start, out var startLine, out var startOffset);
|
|
script.TryGetLineAndOffset(error.End, out var endLine, out var endOffset);
|
|
|
|
// vscode specific format for error markers.
|
|
markers.Add(new ScriptFileMarker()
|
|
{
|
|
Message = error.Message,
|
|
Level = ScriptFileMarkerLevel.Error,
|
|
ScriptRegion = new ScriptRegion
|
|
{
|
|
File = scriptFile.FilePath,
|
|
StartLineNumber = startLine,
|
|
StartColumnNumber = startOffset,
|
|
StartOffset = 0,
|
|
EndLineNumber = endLine,
|
|
EndColumnNumber = endOffset,
|
|
EndOffset = 0
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
return markers.ToArray();
|
|
}
|
|
}
|
|
}
|