Output verbose logging during tests (#1698)

* Output verbose logging during tests

* fix compile
This commit is contained in:
Charles Gagnon
2022-09-16 16:57:06 -07:00
committed by GitHub
parent 019481e8db
commit 5e0302a95f
3 changed files with 31 additions and 11 deletions

View File

@@ -887,6 +887,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
/// <returns>The ParseResult instance returned from SQL Parser</returns> /// <returns>The ParseResult instance returned from SQL Parser</returns>
public ParseResult ParseAndBind(ScriptFile scriptFile, ConnectionInfo connInfo) public ParseResult ParseAndBind(ScriptFile scriptFile, ConnectionInfo connInfo)
{ {
Logger.Verbose($"ParseAndBind - {scriptFile}");
// get or create the current parse info object // get or create the current parse info object
ScriptParseInfo parseInfo = GetScriptParseInfo(scriptFile.ClientUri, createIfNotExists: true); ScriptParseInfo parseInfo = GetScriptParseInfo(scriptFile.ClientUri, createIfNotExists: true);
@@ -1487,20 +1488,22 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
/// <summary> /// <summary>
/// Get function signature help for the current position /// Get function signature help for the current position
/// </summary> /// </summary>
internal SignatureHelp GetSignatureHelp(TextDocumentPosition textDocumentPosition, ScriptFile scriptFile) internal SignatureHelp? GetSignatureHelp(TextDocumentPosition textDocumentPosition, ScriptFile scriptFile)
{ {
Logger.Verbose($"GetSignatureHelp - {scriptFile}");
int startLine = textDocumentPosition.Position.Line; int startLine = textDocumentPosition.Position.Line;
int endColumn = textDocumentPosition.Position.Character; int endColumn = textDocumentPosition.Position.Character;
ScriptParseInfo scriptParseInfo = GetScriptParseInfo(scriptFile.ClientUri); ScriptParseInfo? scriptParseInfo = GetScriptParseInfo(scriptFile.ClientUri);
if (scriptParseInfo == null) if (scriptParseInfo == null)
{ {
Logger.Verbose($"GetSignatureHelp - Could not find ScriptParseInfo for {scriptFile}");
// Cache not set up yet - skip and wait until later // Cache not set up yet - skip and wait until later
return null; return null;
} }
ConnectionInfo connInfo; ConnectionInfo? connInfo;
ConnectionServiceInstance.TryFindConnection( ConnectionServiceInstance.TryFindConnection(
scriptFile.ClientUri, scriptFile.ClientUri,
out connInfo); out connInfo);
@@ -1509,6 +1512,9 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
if (RequiresReparse(scriptParseInfo, scriptFile)) if (RequiresReparse(scriptParseInfo, scriptFile))
{ {
ParseAndBind(scriptFile, connInfo); ParseAndBind(scriptFile, connInfo);
} else
{
Logger.Verbose($"GetSignatureHelp - No reparse needed for {scriptFile}");
} }
if (scriptParseInfo.ParseResult != null) if (scriptParseInfo.ParseResult != null)
@@ -1558,6 +1564,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
} }
} }
} }
Logger.Verbose($"GetSignatureHelp - No ScriptParseInfo.ParseResult for {scriptFile}");
// return null if there isn't a tooltip for the current location // return null if there isn't a tooltip for the current location
return null; return null;
@@ -1836,10 +1843,12 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
{ {
if (this.ScriptParseInfoMap.ContainsKey(uri)) if (this.ScriptParseInfoMap.ContainsKey(uri))
{ {
Logger.Verbose($"Updating ScriptParseInfo for uri {uri}");
this.ScriptParseInfoMap[uri] = scriptInfo; this.ScriptParseInfoMap[uri] = scriptInfo;
} }
else else
{ {
Logger.Verbose($"Adding ScriptParseInfo for uri {uri}");
this.ScriptParseInfoMap.Add(uri, scriptInfo); this.ScriptParseInfoMap.Add(uri, scriptInfo);
} }
@@ -1852,16 +1861,18 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
/// </summary> /// </summary>
/// <param name="uri"></param> /// <param name="uri"></param>
/// <param name="createIfNotExists">Creates a new instance if one doesn't exist</param> /// <param name="createIfNotExists">Creates a new instance if one doesn't exist</param>
internal ScriptParseInfo GetScriptParseInfo(string uri, bool createIfNotExists = false) internal ScriptParseInfo? GetScriptParseInfo(string uri, bool createIfNotExists = false)
{ {
lock (this.parseMapLock) lock (this.parseMapLock)
{ {
if (this.ScriptParseInfoMap.ContainsKey(uri)) if (this.ScriptParseInfoMap.ContainsKey(uri))
{ {
Logger.Verbose($"Found ScriptParseInfo for uri {uri}");
return this.ScriptParseInfoMap[uri]; return this.ScriptParseInfoMap[uri];
} }
else if (createIfNotExists) else if (createIfNotExists)
{ {
Logger.Verbose($"ScriptParseInfo for uri {uri} did not exist, creating new one");
// create a new script parse info object and initialize with the current settings // create a new script parse info object and initialize with the current settings
ScriptParseInfo scriptInfo = new ScriptParseInfo(); ScriptParseInfo scriptInfo = new ScriptParseInfo();
this.ScriptParseInfoMap.Add(uri, scriptInfo); this.ScriptParseInfoMap.Add(uri, scriptInfo);
@@ -1869,6 +1880,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
} }
else else
{ {
Logger.Verbose($"Could not find ScriptParseInfo for uri {uri}");
return null; return null;
} }
} }
@@ -1880,6 +1892,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
{ {
if (this.ScriptParseInfoMap.ContainsKey(uri)) if (this.ScriptParseInfoMap.ContainsKey(uri))
{ {
Logger.Verbose($"Removing ScriptParseInfo for uri {uri}");
return this.ScriptParseInfoMap.Remove(uri); return this.ScriptParseInfoMap.Remove(uri);
} }
else else

View File

@@ -246,12 +246,12 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
Thread.Sleep(2000); Thread.Sleep(2000);
// We should get back a non-null ScriptParseInfo // We should get back a non-null ScriptParseInfo
ScriptParseInfo parseInfo = service.GetScriptParseInfo(result.ScriptFile.ClientUri); ScriptParseInfo? parseInfo = service.GetScriptParseInfo(result.ScriptFile.ClientUri);
Assert.NotNull(parseInfo); Assert.That(parseInfo, Is.Not.Null, "ScriptParseInfo");
// And we should get back a non-null SignatureHelp // And we should get back a non-null SignatureHelp
SignatureHelp signatureHelp = service.GetSignatureHelp(textDocument, result.ScriptFile); SignatureHelp? signatureHelp = service.GetSignatureHelp(textDocument, result.ScriptFile);
Assert.NotNull(signatureHelp); Assert.That(signatureHelp, Is.Not.Null, "SignatureHelp");
} }
/// <summary> /// <summary>

View File

@@ -5,6 +5,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@@ -17,6 +18,7 @@ using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Microsoft.SqlTools.ServiceLayer.QueryExecution; using Microsoft.SqlTools.ServiceLayer.QueryExecution;
using Microsoft.SqlTools.ServiceLayer.SqlContext; using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.Workspace; using Microsoft.SqlTools.ServiceLayer.Workspace;
using Microsoft.SqlTools.Utility;
using NUnit.Framework; using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.Test.Common namespace Microsoft.SqlTools.ServiceLayer.Test.Common
@@ -85,7 +87,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
} }
/// <summary> /// <summary>
/// Runs a query by calling the services directly (not using the test driver) /// Runs a query by calling the services directly (not using the test driver)
/// </summary> /// </summary>
public void RunQuery(TestServerType serverType, string databaseName, string queryText, bool throwOnError = false) public void RunQuery(TestServerType serverType, string databaseName, string queryText, bool throwOnError = false)
{ {
@@ -94,7 +96,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
} }
/// <summary> /// <summary>
/// Runs a query by calling the services directly (not using the test driver) /// Runs a query by calling the services directly (not using the test driver)
/// </summary> /// </summary>
public async Task RunQueryAsync(TestServerType serverType, string databaseName, string queryText, bool throwOnError = false) public async Task RunQueryAsync(TestServerType serverType, string databaseName, string queryText, bool throwOnError = false)
{ {
@@ -185,13 +187,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
const string hostProfileId = "SQLToolsTestService"; const string hostProfileId = "SQLToolsTestService";
Version hostVersion = new Version(1, 0); Version hostVersion = new Version(1, 0);
// set up the host details and profile paths // set up the host details and profile paths
var hostDetails = new HostDetails(hostName, hostProfileId, hostVersion); var hostDetails = new HostDetails(hostName, hostProfileId, hostVersion);
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails); SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
// Initialize the ServiceHost, using a MemoryStream for the output stream so that we don't fill up the logs // Initialize the ServiceHost, using a MemoryStream for the output stream so that we don't fill up the logs
// with a bunch of outgoing messages (which aren't used for anything during tests) // with a bunch of outgoing messages (which aren't used for anything during tests)
ServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext, null, new MemoryStream()); ServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext, null, new MemoryStream());
// Set up our logger to write to Console for tests to help debug issues
Logger.Initialize(autoFlush: true);
Logger.TracingLevel = System.Diagnostics.SourceLevels.All;
Logger.TraceSource.Listeners.Add(new ConsoleTraceListener());
} }
} }