diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/IntelliSenseReady.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/IntelliSenseReady.cs new file mode 100644 index 00000000..4b61e4b7 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/IntelliSenseReady.cs @@ -0,0 +1,30 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; + +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts +{ + /// + /// Parameters sent back with an IntelliSense ready event + /// + public class IntelliSenseReadyParams + { + /// + /// URI identifying the text document + /// + public string OwnerUri { get; set; } + } + + /// + /// Event sent when the language service is finished updating after a connection + /// + public class IntelliSenseReadyNotification + { + public static readonly + EventType Type = + EventType.Create("textDocument/intelliSenseReady"); + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs index efaa4135..bc85780b 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs @@ -561,7 +561,10 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices } } - AutoCompleteHelper.PrepopulateCommonMetadata(info, scriptInfo, this.BindingQueue); + AutoCompleteHelper.PrepopulateCommonMetadata(info, scriptInfo, this.BindingQueue); + + // Send a notification to signal that autocomplete is ready + ServiceHost.Instance.SendEvent(IntelliSenseReadyNotification.Type, new IntelliSenseReadyParams() {OwnerUri = info.OwnerUri}); }); } diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Driver/ServiceTestDriver.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Driver/ServiceTestDriver.cs index 51e46ffe..8eb49dc6 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Driver/ServiceTestDriver.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Driver/ServiceTestDriver.cs @@ -93,6 +93,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Driver // Setup events to queue for testing this.QueueEventsForType(ConnectionCompleteNotification.Type); + this.QueueEventsForType(IntelliSenseReadyNotification.Type); this.QueueEventsForType(QueryExecuteCompleteEvent.Type); this.QueueEventsForType(PublishDiagnosticsNotification.Type); } diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/LanguageServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/LanguageServiceTests.cs index 6eb3e303..74183c02 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/LanguageServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/LanguageServiceTests.cs @@ -258,5 +258,26 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests } } + [Fact] + public async Task NotificationIsSentAfterOnConnectionAutoCompleteUpdate() + { + try + { + // Connect + string ownerUri = System.IO.Path.GetTempFileName(); + await Connect(ownerUri, ConnectionTestUtils.LocalhostConnection); + + // An event signalling that IntelliSense is ready should be sent shortly thereafter + var readyParams = await Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 30000); + Assert.NotNull(readyParams); + Assert.Equal(ownerUri, readyParams.OwnerUri); + + await Disconnect(ownerUri); + } + finally + { + WaitForExit(); + } + } } }