From 32f6cbc3041c598c5c90bd86148041c6c8c2dbcc Mon Sep 17 00:00:00 2001 From: Mitchell Sternke Date: Tue, 15 Nov 2016 18:12:16 -0800 Subject: [PATCH] Language service no longer binds on duplicate connections (#148) --- .../LanguageServices/BindingQueue.cs | 11 +++++++++++ .../LanguageServices/ConnectedBindingQueue.cs | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/BindingQueue.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/BindingQueue.cs index 6058ec42..07623afb 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/BindingQueue.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/BindingQueue.cs @@ -112,6 +112,17 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices } } + /// + /// Checks if a binding context already exists for the provided context key + /// + protected bool BindingContextExists(string key) + { + lock (this.bindingContextLock) + { + return this.BindingContextMap.ContainsKey(key); + } + } + private bool HasPendingQueueItems { get diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ConnectedBindingQueue.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ConnectedBindingQueue.cs index 965d94d2..bd767a7a 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ConnectedBindingQueue.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ConnectedBindingQueue.cs @@ -61,6 +61,11 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices // lookup the current binding context string connectionKey = GetConnectionContextKey(connInfo); + if (BindingContextExists(connectionKey)) + { + // no need to populate the context again since the context already exists + return connectionKey; + } IBindingContext bindingContext = this.GetOrCreateBindingContext(connectionKey); if (bindingContext.BindingLock.WaitOne())