mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-17 17:23:48 -05:00
Take column into account when getting current statement query (#458)
This commit is contained in:
@@ -15,6 +15,7 @@ using Microsoft.SqlServer.Management.SqlParser.Binder;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Common;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Intellisense;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Parser;
|
||||
using Microsoft.SqlServer.Management.SqlParser.SqlCodeDom;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
@@ -1702,6 +1703,10 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
continue;
|
||||
}
|
||||
|
||||
// If there is a single statement on the line, track it so that we can return it regardless of where the user's cursor is
|
||||
SqlStatement lineStatement = null;
|
||||
bool? lineHasSingleStatement = null;
|
||||
|
||||
// check if the batch matches parameters
|
||||
if (batch.StartLocation.LineNumber <= parserLine
|
||||
&& batch.EndLocation.LineNumber >= parserLine)
|
||||
@@ -1712,10 +1717,29 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
if (statement.StartLocation.LineNumber <= parserLine
|
||||
&& statement.EndLocation.LineNumber >= parserLine)
|
||||
{
|
||||
if (statement.EndLocation.LineNumber == parserLine && statement.EndLocation.ColumnNumber < parserColumn
|
||||
|| statement.StartLocation.LineNumber == parserLine && statement.StartLocation.ColumnNumber > parserColumn)
|
||||
{
|
||||
if (lineHasSingleStatement == null)
|
||||
{
|
||||
lineHasSingleStatement = true;
|
||||
lineStatement = statement;
|
||||
}
|
||||
else if (lineHasSingleStatement == true)
|
||||
{
|
||||
lineHasSingleStatement = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
return statement.Sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lineHasSingleStatement == true)
|
||||
{
|
||||
return lineStatement.Sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user