Fix broken STS language service tests (#1837)

* Fix broken STS language service tests

* consolidate
This commit is contained in:
Charles Gagnon
2023-01-31 13:25:44 -08:00
committed by GitHub
parent f64d6c5c58
commit 036ce9b527
3 changed files with 34 additions and 14 deletions

View File

@@ -181,7 +181,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
}
}
private CancellationTokenSource existingRequestCancellation;
private CancellationTokenSource? existingRequestCancellation;
/// <summary>
/// Gets or sets the current workspace service instance

View File

@@ -445,6 +445,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
.ToList();
}
public override string ToString()
{
return $"ScriptFile:{this.FilePath}";
}
#endregion
}
}

View File

@@ -97,7 +97,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
result.TextDocumentPosition.Position.Character = 7;
result.ScriptFile.Contents = "select ";
var autoCompleteService = LanguageService.Instance;
var autoCompleteService = CreateLanguageService(result.ScriptFile);
var completions = autoCompleteService.GetCompletionItems(
result.TextDocumentPosition,
result.ScriptFile,
@@ -132,7 +132,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
result.ScriptFile = ScriptFileTests.GetTestScriptFile("select * f");
result.TextDocumentPosition.TextDocument.Uri = result.ScriptFile.FilePath;
var autoCompleteService = LanguageService.Instance;
var autoCompleteService = CreateLanguageService(result.ScriptFile);
var requestContext = new Mock<SqlTools.Hosting.Protocol.RequestContext<bool>>();
requestContext.Setup(x => x.SendResult(It.IsAny<bool>()))
.Returns(Task.FromResult(true));
@@ -218,7 +218,6 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
/// provide signature help.
/// </summary>
[Test]
[Ignore("this test is not stable")]
public async Task GetSignatureHelpReturnsNotNullIfParseInfoInitialized()
{
// When we make a connection to a live database
@@ -242,7 +241,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
};
// If the SQL has already been parsed
var service = LanguageService.Instance;
var service = CreateLanguageService(result.ScriptFile);
await service.UpdateLanguageServiceOnConnection(result.ConnectionInfo);
Thread.Sleep(2000);
@@ -284,11 +283,13 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
public async Task RebuildIntellisenseCacheClearsScriptParseInfoCorrectly()
{
var testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, null, null, "LangSvcTest");
LiveConnectionHelper.TestConnectionResult? connectionInfoResult = null;
try
{
var connectionInfoResult = LiveConnectionHelper.InitLiveConnectionInfo(testDb.DatabaseName);
connectionInfoResult = LiveConnectionHelper.InitLiveConnectionInfo(testDb.DatabaseName);
var langService = CreateLanguageService(connectionInfoResult.ScriptFile);
var langService = LanguageService.Instance;
await langService.UpdateLanguageServiceOnConnection(connectionInfoResult.ConnectionInfo);
var queryText = "SELECT * FROM dbo.";
connectionInfoResult.ScriptFile.SetFileContents(queryText);
@@ -352,12 +353,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
scriptFile.SetFileContents("koko wants a bananas");
File.WriteAllText(scriptFile.ClientUri, scriptFile.Contents);
// Create a workspace and add file to it so that its found for intellense building
var workspace = new ServiceLayer.Workspace.Workspace();
var workspaceService = new WorkspaceService<SqlToolsSettings> { Workspace = workspace };
var langService = new LanguageService() { WorkspaceServiceInstance = workspaceService };
langService.CurrentWorkspace.GetFile(scriptFile.ClientUri);
langService.CurrentWorkspaceSettings.SqlTools.IntelliSense.EnableIntellisense = true;
var langService = CreateLanguageService(scriptFile);
// Add a connection to ensure the intellisense building works
ConnectionInfo connectionInfo = GetLiveAutoCompleteTestObjects().ConnectionInfo;
@@ -427,7 +423,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
{
var connectionInfoResult = LiveConnectionHelper.InitLiveConnectionInfo(testDb.DatabaseName);
var langService = LanguageService.Instance;
var langService = CreateLanguageService(connectionInfoResult.ScriptFile);
await langService.UpdateLanguageServiceOnConnection(connectionInfoResult.ConnectionInfo);
connectionInfoResult.ScriptFile.SetFileContents(sqlStarQuery);
@@ -465,5 +461,24 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
testDb.Cleanup();
}
}
/// <summary>
/// Creates a new language service and sets it up with an initial script file.
/// </summary>
/// <param name="scriptFile">The initial script file to initialize in the workspace</param>
/// <returns></returns>
private LanguageService CreateLanguageService(ScriptFile scriptFile)
{
var langService = new LanguageService()
{
WorkspaceServiceInstance = new WorkspaceService<SqlToolsSettings>()
{
Workspace = new ServiceLayer.Workspace.Workspace()
}
};
langService.CurrentWorkspace.GetFile(scriptFile.ClientUri);
langService.CurrentWorkspaceSettings.SqlTools.IntelliSense.EnableIntellisense = true;
return langService;
}
}
}