diff --git a/.gitignore b/.gitignore index a52a0fe0..497b0f36 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,9 @@ project.lock.json *.sln.docstates *.exe +# mergetool conflict files +*.orig + # Build results [Dd]ebug/ [Dd]ebugPublic/ diff --git a/src/Microsoft.SqlTools.ServiceLayer/Hosting/ServiceHost.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/ServiceHost.cs index 326cf5ed..94f728a0 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Hosting/ServiceHost.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Hosting/ServiceHost.cs @@ -4,13 +4,13 @@ // using System; -using System.Linq; -using System.Threading.Tasks; using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; using Microsoft.SqlTools.ServiceLayer.Hosting.Contracts; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel; -using System.Reflection; using Microsoft.SqlTools.ServiceLayer.Utility; namespace Microsoft.SqlTools.ServiceLayer.Hosting @@ -63,8 +63,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting #region Member Variables + /// + /// Delegate definition for the host shutdown event + /// + /// + /// public delegate Task ShutdownCallback(object shutdownParams, RequestContext shutdownRequestContext); + /// + /// Delegate definition for the host initialization event + /// + /// + /// public delegate Task InitializeCallback(InitializeRequest startupParams, RequestContext requestContext); private readonly List shutdownCallbacks; @@ -119,8 +129,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting /// private async Task HandleInitializeRequest(InitializeRequest initializeParams, RequestContext requestContext) { - Logger.Write(LogLevel.Verbose, "HandleInitializationRequest"); - // Call all tasks that registered on the initialize request var initializeTasks = initializeCallbacks.Select(t => t(initializeParams, requestContext)); await Task.WhenAll(initializeTasks); @@ -136,7 +144,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting TextDocumentSync = TextDocumentSyncKind.Incremental, DefinitionProvider = true, ReferencesProvider = true, - DocumentHighlightProvider = true, + DocumentHighlightProvider = true, + HoverProvider = true, CompletionProvider = new CompletionOptions { ResolveProvider = true, @@ -144,7 +153,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting }, SignatureHelpProvider = new SignatureHelpOptions { - TriggerCharacters = new string[] { " " } // TODO: Other characters here? + TriggerCharacters = new string[] { " ", "," } } } }); @@ -157,7 +166,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting object versionRequestParams, RequestContext requestContext) { - Logger.Write(LogLevel.Verbose, "HandleVersionRequest"); await requestContext.SendResult(serviceVersion.ToString()); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs index e7da2bca..b0c2440c 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs @@ -12,7 +12,6 @@ using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.SqlParser; using Microsoft.SqlServer.Management.SqlParser.Binder; using Microsoft.SqlServer.Management.SqlParser.Intellisense; -using Microsoft.SqlServer.Management.SqlParser.MetadataProvider; using Microsoft.SqlServer.Management.SqlParser.Parser; using Microsoft.SqlServer.Management.SmoMetadataProvider; using Microsoft.SqlTools.ServiceLayer.Connection; @@ -49,11 +48,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices private ScriptParseInfo currentCompletionParseInfo; - internal bool ShouldEnableAutocomplete() - { - return true; - } - private ConnectionService connectionService = null; /// @@ -83,6 +77,9 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices private Lazy> scriptParseInfoMap = new Lazy>(() => new Dictionary()); + /// + /// Gets a mapping dictionary for SQL file URIs to ScriptParseInfo objects + /// internal Dictionary ScriptParseInfoMap { get @@ -91,6 +88,9 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices } } + /// + /// Gets the singleton instance object + /// public static LanguageService Instance { get { return instance.Value; } @@ -228,7 +228,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices { completionItem = LanguageService.Instance.ResolveCompletionItem(completionItem); await requestContext.SendResult(completionItem); - } + } } private static async Task HandleDefinitionRequest( @@ -262,8 +262,21 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices private static async Task HandleHoverRequest( TextDocumentPosition textDocumentPosition, RequestContext requestContext) - { - await Task.FromResult(true); + { + // check if Quick Info hover tooltips are enabled + if (WorkspaceService.Instance.CurrentSettings.IsQuickInfoEnabled) + { + var scriptFile = WorkspaceService.Instance.Workspace.GetFile( + textDocumentPosition.TextDocument.Uri); + + var hover = LanguageService.Instance.GetHoverItem(textDocumentPosition, scriptFile); + if (hover != null) + { + await requestContext.SendResult(hover); + } + } + + await requestContext.SendResult(new Hover()); } #endregion @@ -280,7 +293,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices ScriptFile scriptFile, EventContext eventContext) { - // if not in the preview window and diagnostics are enabled the run diagnostics + // if not in the preview window and diagnostics are enabled then run diagnostics if (!IsPreviewWindow(scriptFile) && WorkspaceService.Instance.CurrentSettings.IsDiagnositicsEnabled) { @@ -323,15 +336,20 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices bool oldEnableIntelliSense = oldSettings.SqlTools.EnableIntellisense; bool? oldEnableDiagnostics = oldSettings.SqlTools.IntelliSense.EnableDiagnostics; - // Update the settings in the current + // update the current settings to reflect any changes CurrentSettings.Update(newSettings); - // If script analysis settings have changed we need to clear & possibly update the current diagnostic records. + // update the script parse info objects if the settings have changed + foreach (var scriptInfo in this.ScriptParseInfoMap.Values) + { + scriptInfo.OnSettingsChanged(newSettings); + } + + // if script analysis settings have changed we need to clear the current diagnostic markers if (oldEnableIntelliSense != newSettings.SqlTools.EnableIntellisense || oldEnableDiagnostics != newSettings.SqlTools.IntelliSense.EnableDiagnostics) { - // If the user just turned off script analysis or changed the settings path, send a diagnostics - // event to clear the analysis markers that they already have. + // if the user just turned off diagnostics then send an event to clear the error markers if (!newSettings.IsDiagnositicsEnabled) { ScriptFileMarker[] emptyAnalysisDiagnostics = new ScriptFileMarker[0]; @@ -341,6 +359,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices await DiagnosticsHelper.PublishScriptDiagnostics(scriptFile, emptyAnalysisDiagnostics, eventContext); } } + // otherwise rerun diagnostic analysis on all opened SQL files else { await this.RunScriptDiagnostics(CurrentWorkspace.GetOpenedFiles(), eventContext); @@ -440,8 +459,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices ReliableSqlConnection sqlConn = info.SqlConnection as ReliableSqlConnection; if (sqlConn != null) { - ServerConnection serverConn = new ServerConnection(sqlConn.GetUnderlyingConnection()); - scriptInfo.MetadataDisplayInfoProvider = new MetadataDisplayInfoProvider(); + ServerConnection serverConn = new ServerConnection(sqlConn.GetUnderlyingConnection()); scriptInfo.MetadataProvider = SmoMetadataProvider.CreateConnectedProvider(serverConn); scriptInfo.Binder = BinderProvider.CreateBinder(scriptInfo.MetadataProvider); scriptInfo.ServerConnection = serverConn; @@ -516,6 +534,75 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices return completionItem; } + /// + /// Get quick info hover tooltips for the current position + /// + /// + /// + internal Hover GetHoverItem(TextDocumentPosition textDocumentPosition, ScriptFile scriptFile) + { + int startLine = textDocumentPosition.Position.Line; + int startColumn = TextUtilities.PositionOfPrevDelimeter( + scriptFile.Contents, + textDocumentPosition.Position.Line, + textDocumentPosition.Position.Character); + int endColumn = textDocumentPosition.Position.Character; + + ScriptParseInfo scriptParseInfo = GetScriptParseInfo(textDocumentPosition.TextDocument.Uri); + if (scriptParseInfo != null && scriptParseInfo.ParseResult != null) + { + if (scriptParseInfo.BuildingMetadataEvent.WaitOne(LanguageService.FindCompletionStartTimeout)) + { + scriptParseInfo.BuildingMetadataEvent.Reset(); + try + { + // get the current quick info text + Babel.CodeObjectQuickInfo quickInfo = Resolver.GetQuickInfo( + scriptParseInfo.ParseResult, + startLine + 1, + endColumn + 1, + scriptParseInfo.MetadataDisplayInfoProvider); + + // convert from the parser format to the VS Code wire format + var markedStrings = new MarkedString[1]; + if (quickInfo != null) + { + markedStrings[0] = new MarkedString() + { + Language = "SQL", + Value = quickInfo.Text + }; + + return new Hover() + { + Contents = markedStrings, + Range = new Range + { + Start = new Position + { + Line = startLine, + Character = startColumn + }, + End = new Position + { + Line = startLine, + Character = endColumn + } + } + }; + } + } + finally + { + scriptParseInfo.BuildingMetadataEvent.Set(); + } + } + } + + // return null if there isn't a tooltip for the current location + return null; + } + /// /// Return the completion item list for the current text position. /// This method does not await cache builds since it expects to return quickly @@ -646,8 +733,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices /// private Task RunScriptDiagnostics(ScriptFile[] filesToAnalyze, EventContext eventContext) { - if (!CurrentSettings.SqlTools.EnableIntellisense - || !CurrentSettings.SqlTools.IntelliSense.EnableDiagnostics.Value) + if (!CurrentSettings.IsDiagnositicsEnabled) { // If the user has disabled script analysis, skip it entirely return Task.FromResult(true); @@ -769,7 +855,9 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices } else if (createIfNotExists) { + // create a new script parse info object and initialize with the current settings ScriptParseInfo scriptInfo = new ScriptParseInfo(); + scriptInfo.OnSettingsChanged(this.CurrentSettings); this.ScriptParseInfoMap.Add(uri, scriptInfo); return scriptInfo; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ScriptParseInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ScriptParseInfo.cs index 7dca96ab..08f8a07e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ScriptParseInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ScriptParseInfo.cs @@ -13,6 +13,7 @@ using Microsoft.SqlServer.Management.SqlParser.Common; using Microsoft.SqlServer.Management.SqlParser.Intellisense; using Microsoft.SqlServer.Management.SqlParser.MetadataProvider; using Microsoft.SqlServer.Management.SqlParser.Parser; +using Microsoft.SqlTools.ServiceLayer.SqlContext; namespace Microsoft.SqlTools.ServiceLayer.LanguageServices { @@ -27,6 +28,12 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices private ServerConnection serverConnection; + private Lazy metadataDisplayInfoProvider = new Lazy(() => + { + var infoProvider = new MetadataDisplayInfoProvider(); + return infoProvider; + }); + /// /// Event which tells if MetadataProvider is built fully or not /// @@ -141,13 +148,31 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices /// /// Gets or sets the SMO metadata display info provider /// - public MetadataDisplayInfoProvider MetadataDisplayInfoProvider { get; set; } + public MetadataDisplayInfoProvider MetadataDisplayInfoProvider + { + get + { + return this.metadataDisplayInfoProvider.Value; + } + } /// /// Gets or sets the current autocomplete suggestion list /// public IEnumerable CurrentSuggestions { get; set; } + /// + /// Update parse settings if the current configuration has changed + /// + /// + public void OnSettingsChanged(SqlToolsSettings settings) + { + this.MetadataDisplayInfoProvider.BuiltInCasing = + settings.SqlTools.IntelliSense.LowerCaseSuggestions.Value + ? CasingStyle.Lowercase + : CasingStyle.Uppercase; + } + /// /// Gets the database compatibility level from a server version /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Program.cs b/src/Microsoft.SqlTools.ServiceLayer/Program.cs index 3e5a8655..35a659fe 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Program.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Program.cs @@ -16,26 +16,22 @@ namespace Microsoft.SqlTools.ServiceLayer /// /// Main application class for SQL Tools API Service Host executable /// - class Program + internal class Program { /// /// Main entry point into the SQL Tools API Service Host /// - static void Main(string[] args) + internal static void Main(string[] args) { // turn on Verbose logging during early development // we need to switch to Normal when preparing for public preview Logger.Initialize(minimumLogLevel: LogLevel.Verbose); Logger.Write(LogLevel.Normal, "Starting SQL Tools Service Host"); - const string hostName = "SQL Tools Service Host"; - const string hostProfileId = "SQLToolsService"; - Version hostVersion = new Version(1,0); - // set up the host details and profile paths - var hostDetails = new HostDetails(hostName, hostProfileId, hostVersion); - var profilePaths = new ProfilePaths(hostProfileId, "baseAllUsersPath", "baseCurrentUserPath"); - SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails, profilePaths); + var hostDetails = new HostDetails(version: new Version(1,0)); + + SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails); // Grab the instance of the service host ServiceHost serviceHost = ServiceHost.Instance; diff --git a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/HostDetails.cs b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/HostDetails.cs index 1b78faa4..9a2b6e3d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/HostDetails.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/HostDetails.cs @@ -19,13 +19,13 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext /// The default host name for SqlTools Editor Services. Used /// if no host name is specified by the host application. /// - public const string DefaultHostName = "SqlTools Editor Services Host"; + public const string DefaultHostName = "SqlTools Service Host"; /// /// The default host ID for SqlTools Editor Services. Used /// for the host-specific profile path if no host ID is specified. /// - public const string DefaultHostProfileId = "Microsoft.SqlToolsEditorServices"; + public const string DefaultHostProfileId = "Microsoft.SqlToolsServiceHost"; /// /// The default host version for SqlTools Editor Services. If @@ -78,9 +78,9 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext /// /// The host application's version. public HostDetails( - string name, - string profileId, - Version version) + string name = null, + string profileId = null, + Version version = null) { this.Name = name ?? DefaultHostName; this.ProfileId = profileId ?? DefaultHostProfileId; diff --git a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/IntelliSenseSettings.cs b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/IntelliSenseSettings.cs index 7af542c5..f46d3556 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/IntelliSenseSettings.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/IntelliSenseSettings.cs @@ -18,6 +18,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext this.EnableSuggestions = true; this.LowerCaseSuggestions = false; this.EnableDiagnostics = true; + this.EnableQuickInfo = true; } /// @@ -36,6 +37,11 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext /// public bool? EnableDiagnostics { get; set; } + /// + /// Gets or sets a flag determining if quick info is enabled + /// + public bool? EnableQuickInfo { get; set; } + /// /// Update the Intellisense settings /// @@ -47,6 +53,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext this.EnableSuggestions = settings.EnableSuggestions; this.LowerCaseSuggestions = settings.LowerCaseSuggestions; this.EnableDiagnostics = settings.EnableDiagnostics; + this.EnableQuickInfo = settings.EnableQuickInfo; } } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/ProfilePaths.cs b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/ProfilePaths.cs deleted file mode 100644 index f841970d..00000000 --- a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/ProfilePaths.cs +++ /dev/null @@ -1,108 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace Microsoft.SqlTools.ServiceLayer.SqlContext -{ - /// - /// Provides profile path resolution behavior relative to the name - /// of a particular SqlTools host. - /// - public class ProfilePaths - { - #region Constants - - /// - /// The file name for the "all hosts" profile. Also used as the - /// suffix for the host-specific profile filenames. - /// - public const string AllHostsProfileName = "profile.ps1"; - - #endregion - - #region Properties - - /// - /// Gets the profile path for all users, all hosts. - /// - public string AllUsersAllHosts { get; private set; } - - /// - /// Gets the profile path for all users, current host. - /// - public string AllUsersCurrentHost { get; private set; } - - /// - /// Gets the profile path for the current user, all hosts. - /// - public string CurrentUserAllHosts { get; private set; } - - /// - /// Gets the profile path for the current user and host. - /// - public string CurrentUserCurrentHost { get; private set; } - - #endregion - - #region Public Methods - - /// - /// Creates a new instance of the ProfilePaths class. - /// - /// - /// The identifier of the host used in the host-specific X_profile.ps1 filename. - /// - /// The base path to use for constructing AllUsers profile paths. - /// The base path to use for constructing CurrentUser profile paths. - public ProfilePaths( - string hostProfileId, - string baseAllUsersPath, - string baseCurrentUserPath) - { - this.Initialize(hostProfileId, baseAllUsersPath, baseCurrentUserPath); - } - - private void Initialize( - string hostProfileId, - string baseAllUsersPath, - string baseCurrentUserPath) - { - string currentHostProfileName = - string.Format( - "{0}_{1}", - hostProfileId, - AllHostsProfileName); - - this.AllUsersCurrentHost = Path.Combine(baseAllUsersPath, currentHostProfileName); - this.CurrentUserCurrentHost = Path.Combine(baseCurrentUserPath, currentHostProfileName); - this.AllUsersAllHosts = Path.Combine(baseAllUsersPath, AllHostsProfileName); - this.CurrentUserAllHosts = Path.Combine(baseCurrentUserPath, AllHostsProfileName); - } - - /// - /// Gets the list of profile paths that exist on the filesystem. - /// - /// An IEnumerable of profile path strings to be loaded. - public IEnumerable GetLoadableProfilePaths() - { - var profilePaths = - new string[] - { - this.AllUsersAllHosts, - this.AllUsersCurrentHost, - this.CurrentUserAllHosts, - this.CurrentUserCurrentHost - }; - - return profilePaths.Where(p => File.Exists(p)); - } - - #endregion - } -} - diff --git a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsContext.cs b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsContext.cs index d110f28c..baf602f4 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsContext.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsContext.cs @@ -20,9 +20,14 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext get; private set; } - public SqlToolsContext(HostDetails hostDetails, ProfilePaths profilePaths) + /// + /// Initalizes the SQL Tools context instance + /// + /// + public SqlToolsContext(HostDetails hostDetails) { - + this.SqlToolsVersion = hostDetails.Version; } } } + diff --git a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsSettings.cs b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsSettings.cs index 22d83e14..cfa438c0 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsSettings.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsSettings.cs @@ -75,6 +75,18 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext && this.SqlTools.IntelliSense.EnableSuggestions.Value; } } + + /// + /// Gets a flag determining if quick info is enabled + /// + public bool IsQuickInfoEnabled + { + get + { + return this.SqlTools.EnableIntellisense + && this.SqlTools.IntelliSense.EnableQuickInfo.Value; + } + } } /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Utility/Logger.cs b/src/Microsoft.SqlTools.ServiceLayer/Utility/Logger.cs index 5c4adae4..4f1a27a3 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Utility/Logger.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Utility/Logger.cs @@ -45,6 +45,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility { private static LogWriter logWriter; + private static bool isEnabled; + + private static bool isInitialized = false; + /// /// Initializes the Logger for the current session. /// @@ -56,8 +60,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility /// public static void Initialize( string logFilePath = "sqltools", - LogLevel minimumLogLevel = LogLevel.Normal) + LogLevel minimumLogLevel = LogLevel.Normal, + bool isEnabled = true) { + Logger.isEnabled = isEnabled; + + // return if the logger is not enabled or already initialized + if (!Logger.isEnabled || Logger.isInitialized) + { + return; + } + + Logger.isInitialized = true; + // get a unique number to prevent conflicts of two process launching at the same time int uniqueId; try @@ -89,6 +104,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility minimumLogLevel, fullFileName, true); + + Logger.Write(LogLevel.Normal, "Initializing SQL Tools Service Host logger"); } /// @@ -116,7 +133,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility [CallerMemberName] string callerName = null, [CallerFilePath] string callerSourceFile = null, [CallerLineNumber] int callerLineNumber = 0) - { + { + // return if the logger is not enabled or not initialized + if (!Logger.isEnabled || !Logger.isInitialized) + { + return; + } + if (logWriter != null) { logWriter.Write( diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs index 49105601..35214369 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs @@ -7,18 +7,8 @@ using System; using System.Collections.Generic; using System.Data; using System.Data.Common; -using System.Data.SqlClient; using System.IO; using System.Reflection; -using System.Threading.Tasks; -using Microsoft.SqlServer.Management.Common; -using Microsoft.SqlServer.Management.Smo; -using Microsoft.SqlServer.Management.SmoMetadataProvider; -using Microsoft.SqlServer.Management.SqlParser; -using Microsoft.SqlServer.Management.SqlParser.Binder; -using Microsoft.SqlServer.Management.SqlParser.Intellisense; -using Microsoft.SqlServer.Management.SqlParser.MetadataProvider; -using Microsoft.SqlServer.Management.SqlParser.Parser; using Microsoft.SqlTools.ServiceLayer.Connection; using Microsoft.SqlTools.ServiceLayer.Connection.Contracts; using Microsoft.SqlTools.ServiceLayer.Credentials; @@ -154,17 +144,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices #region "General Language Service tests" - /// - /// Check that autocomplete is enabled by default - /// - [Fact] - public void CheckAutocompleteEnabledByDefault() - { - // get test service - LanguageService service = TestObjects.GetTestLanguageService(); - Assert.True(service.ShouldEnableAutocomplete()); - } - /// /// Test the service initialization code path and verify nothing throws /// @@ -260,8 +239,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices // set up the host details and profile paths var hostDetails = new HostDetails(hostName, hostProfileId, hostVersion); - var profilePaths = new ProfilePaths(hostProfileId, "baseAllUsersPath", "baseCurrentUserPath"); - SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails, profilePaths); + SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails); // Grab the instance of the service host Hosting.ServiceHost serviceHost = Hosting.ServiceHost.Instance; @@ -282,9 +260,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices private Hosting.ServiceHost GetTestServiceHost() { // set up the host details and profile paths - var hostDetails = new HostDetails("Test Service Host", "SQLToolsService", new Version(1,0)); - var profilePaths = new ProfilePaths("SQLToolsService", "baseAllUsersPath", "baseCurrentUserPath"); - SqlToolsContext context = new SqlToolsContext(hostDetails, profilePaths); + var hostDetails = new HostDetails("Test Service Host", "SQLToolsService", new Version(1,0)); + SqlToolsContext context = new SqlToolsContext(hostDetails); // Grab the instance of the service host Hosting.ServiceHost host = Hosting.ServiceHost.Instance; diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/QueryExecution/Common.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/QueryExecution/Common.cs index 777cbaa3..1dcf28f9 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test/QueryExecution/Common.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/QueryExecution/Common.cs @@ -257,8 +257,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution new ScriptParseInfo { Binder = binder, - MetadataProvider = metadataProvider, - MetadataDisplayInfoProvider = displayInfoProvider + MetadataProvider = metadataProvider }); scriptFile = new ScriptFile {ClientFilePath = textDocument.TextDocument.Uri}; diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/SqlContext/SettingsTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/SqlContext/SettingsTests.cs index 488d19da..fba65a29 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test/SqlContext/SettingsTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/SqlContext/SettingsTests.cs @@ -25,6 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices Assert.True(sqlToolsSettings.SqlTools.EnableIntellisense); Assert.True(sqlToolsSettings.SqlTools.IntelliSense.EnableDiagnostics); Assert.True(sqlToolsSettings.SqlTools.IntelliSense.EnableSuggestions); + Assert.True(sqlToolsSettings.SqlTools.IntelliSense.EnableQuickInfo); Assert.False(sqlToolsSettings.SqlTools.IntelliSense.LowerCaseSuggestions); } @@ -52,7 +53,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices } /// - /// Validate that the IsDiagnositicsEnabled flag behavior + /// Validate that the IsSuggestionsEnabled flag behavior /// [Fact] public void ValidateIsSuggestionsEnabled() @@ -73,5 +74,28 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices sqlToolsSettings.SqlTools.IntelliSense.EnableSuggestions = false; Assert.False(sqlToolsSettings.IsSuggestionsEnabled); } + + /// + /// Validate that the IsQuickInfoEnabled flag behavior + /// + [Fact] + public void ValidateIsQuickInfoEnabled() + { + var sqlToolsSettings = new SqlToolsSettings(); + + // quick info is enabled if IntelliSense and quick info flags are set + sqlToolsSettings.SqlTools.EnableIntellisense = true; + sqlToolsSettings.SqlTools.IntelliSense.EnableQuickInfo = true; + Assert.True(sqlToolsSettings.IsQuickInfoEnabled); + + // quick info is disabled if either IntelliSense and quick info flags is not set + sqlToolsSettings.SqlTools.EnableIntellisense = false; + sqlToolsSettings.SqlTools.IntelliSense.EnableQuickInfo = true; + Assert.False(sqlToolsSettings.IsQuickInfoEnabled); + + sqlToolsSettings.SqlTools.EnableIntellisense = true; + sqlToolsSettings.SqlTools.IntelliSense.EnableQuickInfo = false; + Assert.False(sqlToolsSettings.IsQuickInfoEnabled); + } } }