mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-03 17:24:53 -05:00
Kusto Auth Refactor Tests (#1148)
* 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.
This commit is contained in:
@@ -15,10 +15,9 @@ using Microsoft.SqlServer.Management.SqlParser.Parser;
|
||||
using Microsoft.SqlServer.Management.SqlParser.SqlCodeDom;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.Kusto.ServiceLayer.DataSource;
|
||||
using Microsoft.Kusto.ServiceLayer.DataSource.DataSourceIntellisense;
|
||||
using Microsoft.Kusto.ServiceLayer.Connection;
|
||||
using Microsoft.Kusto.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.Kusto.ServiceLayer.LanguageServices.Completion;
|
||||
using Microsoft.Kusto.ServiceLayer.DataSource.Intellisense;
|
||||
using Microsoft.Kusto.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.Kusto.ServiceLayer.Utility;
|
||||
using Microsoft.Kusto.ServiceLayer.Workspace;
|
||||
@@ -67,9 +66,6 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
|
||||
|
||||
internal const int PeekDefinitionTimeout = 10 * OneSecond;
|
||||
|
||||
// For testability only
|
||||
internal Task DelayedDiagnosticsTask = null;
|
||||
|
||||
private ConnectionService connectionService = null;
|
||||
|
||||
private WorkspaceService<SqlToolsSettings> workspaceServiceInstance;
|
||||
@@ -209,7 +205,7 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
|
||||
/// <param name="context"></param>
|
||||
/// <param name="dataSourceFactory"></param>
|
||||
/// <param name="connectedBindingQueue"></param>
|
||||
public void InitializeService(ServiceHost serviceHost, IConnectedBindingQueue connectedBindingQueue, IDataSourceFactory dataSourceFactory)
|
||||
public void InitializeService(ServiceHost serviceHost, IConnectedBindingQueue connectedBindingQueue)
|
||||
{
|
||||
_bindingQueue = connectedBindingQueue;
|
||||
// Register the requests that this service will handle
|
||||
@@ -766,18 +762,16 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
|
||||
connInfo.TryGetConnection("Default", out connection);
|
||||
IDataSource dataSource = connection.GetUnderlyingConnection();
|
||||
|
||||
return KustoIntellisenseHelper.GetDefinition(scriptFile.Contents, textDocumentPosition.Position.Character, 1, 1, dataSource.SchemaState);
|
||||
return dataSource.GetDefinition(scriptFile.Contents, textDocumentPosition.Position.Character, 1, 1);
|
||||
}
|
||||
else
|
||||
|
||||
// User is not connected.
|
||||
return new DefinitionResult
|
||||
{
|
||||
// User is not connected.
|
||||
return new DefinitionResult
|
||||
{
|
||||
IsErrorResult = true,
|
||||
Message = SR.PeekDefinitionNotConnectedError,
|
||||
Locations = null
|
||||
};
|
||||
}
|
||||
IsErrorResult = true,
|
||||
Message = SR.PeekDefinitionNotConnectedError,
|
||||
Locations = null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -809,9 +803,8 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
|
||||
|
||||
ReliableDataSourceConnection connection;
|
||||
connInfo.TryGetConnection("Default", out connection);
|
||||
IDataSource dataSource = connection.GetUnderlyingConnection();
|
||||
|
||||
return KustoIntellisenseHelper.GetHoverHelp(scriptDocumentInfo, textDocumentPosition.Position, dataSource.SchemaState);
|
||||
IDataSource dataSource = connection.GetUnderlyingConnection();
|
||||
return dataSource.GetHoverHelp(scriptDocumentInfo, textDocumentPosition.Position);
|
||||
});
|
||||
|
||||
queueItem.ItemProcessed.WaitOne();
|
||||
@@ -855,14 +848,17 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
|
||||
|
||||
ScriptDocumentInfo scriptDocumentInfo = new ScriptDocumentInfo(textDocumentPosition, scriptFile, scriptParseInfo);
|
||||
|
||||
if(connInfo != null){
|
||||
if (connInfo != null)
|
||||
{
|
||||
ReliableDataSourceConnection connection;
|
||||
connInfo.TryGetConnection("Default", out connection);
|
||||
IDataSource dataSource = connection.GetUnderlyingConnection();
|
||||
|
||||
resultCompletionItems = KustoIntellisenseHelper.GetAutoCompleteSuggestions(scriptDocumentInfo, textDocumentPosition.Position, dataSource.SchemaState);
|
||||
|
||||
resultCompletionItems =
|
||||
dataSource.GetAutoCompleteSuggestions(scriptDocumentInfo, textDocumentPosition.Position);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
resultCompletionItems = DataSourceFactory.GetDefaultAutoComplete(DataSourceType.Kusto, scriptDocumentInfo, textDocumentPosition.Position);
|
||||
}
|
||||
|
||||
@@ -932,7 +928,7 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
|
||||
existingRequestCancellation = new CancellationTokenSource();
|
||||
Task.Factory.StartNew(
|
||||
() =>
|
||||
this.DelayedDiagnosticsTask = DelayThenInvokeDiagnostics(
|
||||
DelayThenInvokeDiagnostics(
|
||||
LanguageService.DiagnosticParseDelay,
|
||||
filesToAnalyze,
|
||||
eventContext,
|
||||
@@ -1000,17 +996,19 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
scriptFile.ClientUri,
|
||||
out connInfo);
|
||||
|
||||
if(connInfo != null){
|
||||
|
||||
if (connInfo != null)
|
||||
{
|
||||
connInfo.TryGetConnection("Default", out var connection);
|
||||
IDataSource dataSource = connection.GetUnderlyingConnection();
|
||||
|
||||
semanticMarkers = KustoIntellisenseHelper.GetSemanticMarkers(parseInfo, scriptFile, scriptFile.Contents, dataSource.SchemaState);
|
||||
}
|
||||
else{
|
||||
|
||||
semanticMarkers = dataSource.GetSemanticMarkers(parseInfo, scriptFile, scriptFile.Contents);
|
||||
}
|
||||
else
|
||||
{
|
||||
semanticMarkers = DataSourceFactory.GetDefaultSemanticMarkers(DataSourceType.Kusto, parseInfo, scriptFile, scriptFile.Contents);
|
||||
}
|
||||
|
||||
|
||||
Logger.Write(TraceEventType.Verbose, "Analysis complete.");
|
||||
|
||||
await DiagnosticsHelper.PublishScriptDiagnostics(scriptFile, semanticMarkers, eventContext);
|
||||
|
||||
Reference in New Issue
Block a user