mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-22 09:35:38 -05:00
Peek definition support for tables, views and stored procedures (#160)
* Add support for peek/go to definition Add unit tests for definition Microsoft/vscode-mssql#253 and Microsoft/vscode-mssql#268 * Format Strings * Add integration tests * Refactor variable names * Remove test file * Remove LIVE_CONNECTION definition * Change method name * Write files to a separate directory * Refactor GetDefinition * Remove unnecessary whitespace and modify variable name * Check intellisense settings * Refactor code to be scalable and modify tests * Refactor to facilitate CodeGen * Reorder methods * Modify method to strip bracket syntax * Add one_second constant * Add comments * Modify null check * Modify GetSchema code to account for spaces * Alter variable names and modify null checks * Remove timeout callback and refactor null check * remove LIVE_CONNECTION_TEST definition
This commit is contained in:
@@ -211,6 +211,49 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Peek Definition/ Go to definition
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task DefinitionTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string query = "SELECT * FROM sys.objects";
|
||||
int lineNumber = 0;
|
||||
int position = 23;
|
||||
|
||||
testHelper.WriteToFile(queryTempFile.FilePath, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
|
||||
{
|
||||
TextDocument = new TextDocumentItem
|
||||
{
|
||||
Uri = queryTempFile.FilePath,
|
||||
LanguageId = "enu",
|
||||
Version = 1,
|
||||
Text = query
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
|
||||
Thread.Sleep(10000);
|
||||
// Request definition for "objects"
|
||||
Location[] locations = await testHelper.RequestDefinition(queryTempFile.FilePath, query, lineNumber, position);
|
||||
|
||||
Assert.True(locations != null, "Location is not null and not empty");
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate the configuration change event
|
||||
/// </summary>
|
||||
|
||||
@@ -257,6 +257,29 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request definition( peek definition/go to definition) for a sql object in a sql string
|
||||
/// </summary>
|
||||
public async Task<Location[]> RequestDefinition(string ownerUri, string text, int line, int character)
|
||||
{
|
||||
// Write the text to a backing file
|
||||
lock (fileLock)
|
||||
{
|
||||
System.IO.File.WriteAllText(ownerUri, text);
|
||||
}
|
||||
|
||||
var definitionParams = new TextDocumentPosition();
|
||||
definitionParams.TextDocument = new TextDocumentIdentifier();
|
||||
definitionParams.TextDocument.Uri = ownerUri;
|
||||
definitionParams.Position = new Position();
|
||||
definitionParams.Position.Line = line;
|
||||
definitionParams.Position.Character = character;
|
||||
|
||||
// Send definition request
|
||||
var result = await Driver.SendRequest(DefinitionRequest.Type, definitionParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run a query using a given connection bound to a URI
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user