mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-22 09:35:38 -05:00
Feature/cleanups1 (#114)
* Intellisense cleanups. * Additional intellisense cleanups for default list * Add missing Monitor.Exit in completion resolve * A couple more cleanups. * Bug fixes for auto-complete. * Add comment regarding conditional logic
This commit is contained in:
@@ -6,7 +6,34 @@
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
{
|
||||
public static class TextUtilities
|
||||
{
|
||||
{
|
||||
/// <summary>
|
||||
/// Find the position of the cursor in the SQL script content buffer and return previous new line position
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <param name="startRow"></param>
|
||||
/// <param name="startColumn"></param>
|
||||
/// <param name="prevNewLine"></param>
|
||||
public static int PositionOfCursor(string sql, int startRow, int startColumn, out int prevNewLine)
|
||||
{
|
||||
prevNewLine = 0;
|
||||
if (string.IsNullOrWhiteSpace(sql))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < startRow; ++i)
|
||||
{
|
||||
while (prevNewLine < sql.Length && sql[prevNewLine] != '\n')
|
||||
{
|
||||
++prevNewLine;
|
||||
}
|
||||
++prevNewLine;
|
||||
}
|
||||
|
||||
return startColumn + prevNewLine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the position of the previous delimeter for autocomplete token replacement.
|
||||
/// SQL Parser may have similar functionality in which case we'll delete this method.
|
||||
@@ -14,49 +41,70 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
/// <param name="sql"></param>
|
||||
/// <param name="startRow"></param>
|
||||
/// <param name="startColumn"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="tokenText"></param>
|
||||
public static int PositionOfPrevDelimeter(string sql, int startRow, int startColumn)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sql))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
int prevNewLine;
|
||||
int delimeterPos = PositionOfCursor(sql, startRow, startColumn, out prevNewLine);
|
||||
|
||||
int prevLineColumns = 0;
|
||||
for (int i = 0; i < startRow; ++i)
|
||||
if (delimeterPos - 1 < sql.Length)
|
||||
{
|
||||
while (sql[prevLineColumns] != '\n' && prevLineColumns < sql.Length)
|
||||
while (--delimeterPos >= prevNewLine)
|
||||
{
|
||||
++prevLineColumns;
|
||||
}
|
||||
++prevLineColumns;
|
||||
}
|
||||
|
||||
startColumn += prevLineColumns;
|
||||
|
||||
if (startColumn - 1 < sql.Length)
|
||||
{
|
||||
while (--startColumn >= prevLineColumns)
|
||||
{
|
||||
if (sql[startColumn] == ' '
|
||||
|| sql[startColumn] == '\t'
|
||||
|| sql[startColumn] == '\n'
|
||||
|| sql[startColumn] == '.'
|
||||
|| sql[startColumn] == '+'
|
||||
|| sql[startColumn] == '-'
|
||||
|| sql[startColumn] == '*'
|
||||
|| sql[startColumn] == '>'
|
||||
|| sql[startColumn] == '<'
|
||||
|| sql[startColumn] == '='
|
||||
|| sql[startColumn] == '/'
|
||||
|| sql[startColumn] == '%')
|
||||
if (IsCharacterDelimeter(sql[delimeterPos]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delimeterPos = delimeterPos + 1 - prevNewLine;
|
||||
}
|
||||
|
||||
return startColumn + 1 - prevLineColumns;
|
||||
return delimeterPos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the position of the next delimeter for autocomplete token replacement.
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <param name="startRow"></param>
|
||||
/// <param name="startColumn"></param>
|
||||
public static int PositionOfNextDelimeter(string sql, int startRow, int startColumn)
|
||||
{
|
||||
int prevNewLine;
|
||||
int delimeterPos = PositionOfCursor(sql, startRow, startColumn, out prevNewLine);
|
||||
|
||||
while (delimeterPos < sql.Length)
|
||||
{
|
||||
if (IsCharacterDelimeter(sql[delimeterPos]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
++delimeterPos;
|
||||
}
|
||||
|
||||
return delimeterPos - prevNewLine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine if the character is a SQL token delimiter
|
||||
/// </summary>
|
||||
/// <param name="ch"></param>
|
||||
private static bool IsCharacterDelimeter(char ch)
|
||||
{
|
||||
return ch == ' '
|
||||
|| ch == '\t'
|
||||
|| ch == '\n'
|
||||
|| ch == '.'
|
||||
|| ch == '+'
|
||||
|| ch == '-'
|
||||
|| ch == '*'
|
||||
|| ch == '>'
|
||||
|| ch == '<'
|
||||
|| ch == '='
|
||||
|| ch == '/'
|
||||
|| ch == '%'
|
||||
|| ch == ',';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user