mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 11:01:39 -05:00
Fix broken STS language service tests (#1837)
* Fix broken STS language service tests * consolidate
This commit is contained in:
@@ -181,7 +181,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CancellationTokenSource existingRequestCancellation;
|
private CancellationTokenSource? existingRequestCancellation;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the current workspace service instance
|
/// Gets or sets the current workspace service instance
|
||||||
|
|||||||
@@ -445,6 +445,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"ScriptFile:{this.FilePath}";
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
result.TextDocumentPosition.Position.Character = 7;
|
result.TextDocumentPosition.Position.Character = 7;
|
||||||
result.ScriptFile.Contents = "select ";
|
result.ScriptFile.Contents = "select ";
|
||||||
|
|
||||||
var autoCompleteService = LanguageService.Instance;
|
var autoCompleteService = CreateLanguageService(result.ScriptFile);
|
||||||
var completions = autoCompleteService.GetCompletionItems(
|
var completions = autoCompleteService.GetCompletionItems(
|
||||||
result.TextDocumentPosition,
|
result.TextDocumentPosition,
|
||||||
result.ScriptFile,
|
result.ScriptFile,
|
||||||
@@ -132,7 +132,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
result.ScriptFile = ScriptFileTests.GetTestScriptFile("select * f");
|
result.ScriptFile = ScriptFileTests.GetTestScriptFile("select * f");
|
||||||
result.TextDocumentPosition.TextDocument.Uri = result.ScriptFile.FilePath;
|
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>>();
|
var requestContext = new Mock<SqlTools.Hosting.Protocol.RequestContext<bool>>();
|
||||||
requestContext.Setup(x => x.SendResult(It.IsAny<bool>()))
|
requestContext.Setup(x => x.SendResult(It.IsAny<bool>()))
|
||||||
.Returns(Task.FromResult(true));
|
.Returns(Task.FromResult(true));
|
||||||
@@ -218,7 +218,6 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
/// provide signature help.
|
/// provide signature help.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Test]
|
[Test]
|
||||||
[Ignore("this test is not stable")]
|
|
||||||
public async Task GetSignatureHelpReturnsNotNullIfParseInfoInitialized()
|
public async Task GetSignatureHelpReturnsNotNullIfParseInfoInitialized()
|
||||||
{
|
{
|
||||||
// When we make a connection to a live database
|
// 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
|
// If the SQL has already been parsed
|
||||||
var service = LanguageService.Instance;
|
var service = CreateLanguageService(result.ScriptFile);
|
||||||
await service.UpdateLanguageServiceOnConnection(result.ConnectionInfo);
|
await service.UpdateLanguageServiceOnConnection(result.ConnectionInfo);
|
||||||
Thread.Sleep(2000);
|
Thread.Sleep(2000);
|
||||||
|
|
||||||
@@ -284,11 +283,13 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
public async Task RebuildIntellisenseCacheClearsScriptParseInfoCorrectly()
|
public async Task RebuildIntellisenseCacheClearsScriptParseInfoCorrectly()
|
||||||
{
|
{
|
||||||
var testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, null, null, "LangSvcTest");
|
var testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, null, null, "LangSvcTest");
|
||||||
|
LiveConnectionHelper.TestConnectionResult? connectionInfoResult = null;
|
||||||
try
|
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);
|
await langService.UpdateLanguageServiceOnConnection(connectionInfoResult.ConnectionInfo);
|
||||||
var queryText = "SELECT * FROM dbo.";
|
var queryText = "SELECT * FROM dbo.";
|
||||||
connectionInfoResult.ScriptFile.SetFileContents(queryText);
|
connectionInfoResult.ScriptFile.SetFileContents(queryText);
|
||||||
@@ -352,12 +353,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
scriptFile.SetFileContents("koko wants a bananas");
|
scriptFile.SetFileContents("koko wants a bananas");
|
||||||
File.WriteAllText(scriptFile.ClientUri, scriptFile.Contents);
|
File.WriteAllText(scriptFile.ClientUri, scriptFile.Contents);
|
||||||
|
|
||||||
// Create a workspace and add file to it so that its found for intellense building
|
var langService = CreateLanguageService(scriptFile);
|
||||||
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;
|
|
||||||
|
|
||||||
// Add a connection to ensure the intellisense building works
|
// Add a connection to ensure the intellisense building works
|
||||||
ConnectionInfo connectionInfo = GetLiveAutoCompleteTestObjects().ConnectionInfo;
|
ConnectionInfo connectionInfo = GetLiveAutoCompleteTestObjects().ConnectionInfo;
|
||||||
@@ -427,7 +423,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
{
|
{
|
||||||
var connectionInfoResult = LiveConnectionHelper.InitLiveConnectionInfo(testDb.DatabaseName);
|
var connectionInfoResult = LiveConnectionHelper.InitLiveConnectionInfo(testDb.DatabaseName);
|
||||||
|
|
||||||
var langService = LanguageService.Instance;
|
var langService = CreateLanguageService(connectionInfoResult.ScriptFile);
|
||||||
await langService.UpdateLanguageServiceOnConnection(connectionInfoResult.ConnectionInfo);
|
await langService.UpdateLanguageServiceOnConnection(connectionInfoResult.ConnectionInfo);
|
||||||
connectionInfoResult.ScriptFile.SetFileContents(sqlStarQuery);
|
connectionInfoResult.ScriptFile.SetFileContents(sqlStarQuery);
|
||||||
|
|
||||||
@@ -465,5 +461,24 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
testDb.Cleanup();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user