This repository has been archived on 2026-07-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/DocumentStatusHelper.cs
T
Leila Lali e9398f7182 Sending status change notifications from server (#186)
* Sending status change notifications from server
2016-12-14 13:19:02 -08:00

59 lines
2.2 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.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
{
/// <summary>
/// Helper class to send events to the client
/// </summary>
public class DocumentStatusHelper
{
public const string DefinitionRequested = "DefinitionRequested";
public const string DefinitionRequestCompleted = "DefinitionRequestCompleted";
/// <summary>
/// Sends an event for specific document using the existing request context
/// </summary>
public static void SendStatusChange<T>(RequestContext<T> requestContext, TextDocumentPosition textDocumentPosition, string status)
{
Task.Factory.StartNew(async () =>
{
if (requestContext != null)
{
string ownerUri = textDocumentPosition != null && textDocumentPosition.TextDocument != null ? textDocumentPosition.TextDocument.Uri : "";
await requestContext.SendEvent(StatusChangedNotification.Type, new StatusChangeParams()
{
OwnerUri = ownerUri,
Status = status
});
}
});
}
/// <summary>
/// Sends a telemetry event for specific document using the existing request context
/// </summary>
public static void SendTelemetryEvent<T>(RequestContext<T> requestContext, string telemetryEvent)
{
Task.Factory.StartNew(async () =>
{
await requestContext.SendEvent(TelemetryNotification.Type, new TelemetryParams()
{
Params = new TelemetryProperties
{
EventName = telemetryEvent
}
});
});
}
}
}