mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Add error handling to Connect command
- Handles errors when connecting - Adds method to capture the settings so the connection service can use these. Expect to read settings from here (and possible connections) in the future - Minor rename to the test namespace to be consistent with refactor
This commit is contained in:
@@ -10,6 +10,8 @@ using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.EditorServices.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceServices;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
{
|
||||
@@ -144,12 +146,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
{
|
||||
ConnectionId = maxConnectionId
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Initialize(ServiceHost serviceHost)
|
||||
public void InitializeService(ServiceHost serviceHost)
|
||||
{
|
||||
// Register request and event handlers with the Service Host
|
||||
serviceHost.SetRequestHandler(ConnectionRequest.Type, HandleConnectRequest);
|
||||
|
||||
// Register the configuration update handler
|
||||
WorkspaceService<SqlToolsSettings>.Instance.RegisterConfigChangeCallback(HandleDidChangeConfigurationNotification);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -177,10 +184,28 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleConnectRequest");
|
||||
|
||||
// open connection base on request details
|
||||
ConnectionResult result = ConnectionService.Instance.Connect(connectionDetails);
|
||||
try
|
||||
{
|
||||
// open connection base on request details
|
||||
ConnectionResult result = ConnectionService.Instance.Connect(connectionDetails);
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
#endregion
|
||||
|
||||
#region Handlers for Events from Other Services
|
||||
|
||||
public Task HandleDidChangeConfigurationNotification(
|
||||
SqlToolsSettings newSettings,
|
||||
SqlToolsSettings oldSettings,
|
||||
EventContext eventContext)
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer
|
||||
WorkspaceService<SqlToolsSettings>.Instance.InitializeService(serviceHost);
|
||||
AutoCompleteService.Instance.InitializeService(serviceHost);
|
||||
LanguageService.Instance.InitializeService(serviceHost, sqlToolsContext);
|
||||
ConnectionService.Instance.Initialize(serviceHost);
|
||||
ConnectionService.Instance.InitializeService(serviceHost);
|
||||
|
||||
serviceHost.Initialize();
|
||||
serviceHost.WaitForExit();
|
||||
|
||||
@@ -8,7 +8,7 @@ using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the ServiceHost Language Service tests
|
||||
|
||||
Reference in New Issue
Block a user