Skip to content

Commit

Permalink
Support disconnect message from object explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Oct 25, 2023
1 parent 17c2a73 commit 10aa0fb
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace MarkMpn.Sql4Cds.LanguageServer.ObjectExplorer.Contracts
{
/// <summary>
/// Parameters to the <see cref="CloseSessionRequest"/>.
/// </summary>
public class CloseSessionParams
{
/// <summary>
/// The Id returned from a <see cref="CreateSessionRequest"/>. This
/// is used to disambiguate between different trees.
/// </summary>
public string SessionId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using MarkMpn.Sql4Cds.LanguageServer.Connection.Contracts;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace MarkMpn.Sql4Cds.LanguageServer.ObjectExplorer.Contracts
{
/// <summary>
/// Closes an Object Explorer tree session for a specific connection.
/// </summary>
public class CloseSessionRequest
{
public const string MessageName = "objectexplorer/closesession";

public static readonly LspRequest<CloseSessionParams, CloseSessionResponse> Type = new LspRequest<CloseSessionParams, CloseSessionResponse>(MessageName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace MarkMpn.Sql4Cds.LanguageServer.ObjectExplorer.Contracts
{
/// <summary>
/// Information returned from a <see cref="CloseSessionRequest"/>.
/// Contains success information, a <see cref="SessionId"/> to be used when
/// requesting closing an existing session.
/// </summary>
public class CloseSessionResponse
{
/// <summary>
/// Boolean indicating if the session was closed successfully
/// </summary>
public bool Success { get; set; }

/// <summary>
/// Unique ID to use when sending any requests for objects in the
/// tree under the node
/// </summary>
public string SessionId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace MarkMpn.Sql4Cds.LanguageServer.ObjectExplorer.Contracts
{
/// <summary>
/// Information returned when a session is disconnected.
/// Contains success information and a <see cref="SessionId"/>
/// </summary>
public class SessionDisconnectedParameters
{
/// <summary>
/// Boolean indicating if the connection was successful
/// </summary>
public bool Success { get; set; }

/// <summary>
/// Unique ID to use when sending any requests for objects in the
/// tree under the node
/// </summary>
public string SessionId { get; set; }

/// <summary>
/// Error message returned from the engine for a object explorer session failure reason, if any.
/// </summary>
public string ErrorMessage { get; set; }
}

/// <summary>
/// Session disconnected notification
/// </summary>
public class SessionDisconnectedNotification
{
public const string MessageName = "objectexplorer/sessiondisconnected";

public static readonly LspNotification<SessionDisconnectedParameters> Type = new LspNotification<SessionDisconnectedParameters>(MessageName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void Initialize(JsonRpc lsp)
lsp.AddHandler(CreateSessionRequest.Type, HandleCreateSession);
lsp.AddHandler(ExpandRequest.Type, HandleExpand);
lsp.AddHandler(RefreshRequest.Type, HandleRefresh);
lsp.AddHandler(CloseSessionRequest.Type, HandleCloseSession);
}

public CreateSessionResponse HandleCreateSession(ConnectionDetails request)
Expand Down Expand Up @@ -61,6 +62,24 @@ public CreateSessionResponse HandleCreateSession(ConnectionDetails request)
return new CreateSessionResponse { SessionId = session.SessionId };
}

public CloseSessionResponse HandleCloseSession(CloseSessionParams request)
{
_connectionManager.Disconnect(request.SessionId);

_ = _lsp.NotifyAsync(SessionDisconnectedNotification.Type, new SessionDisconnectedParameters
{
SessionId = request.SessionId,
Success = true,
ErrorMessage = null
});

return new CloseSessionResponse
{
SessionId = request.SessionId,
Success = true
};
}

public bool HandleExpand(ExpandParams request)
{
var session = _connectionManager.GetConnection(request.SessionId);
Expand Down

0 comments on commit 10aa0fb

Please sign in to comment.