mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-15 17:23:32 -05:00
* Initial commit for GitHub IO pages * Add initial doxfx content * Update manifest.json * Update manifest.json * Set theme jekyll-theme-cayman * Set theme jekyll-theme-slate * Set theme jekyll-theme-minimal * Set theme jekyll-theme-tactile * Clear out theme setting * Remove API docs * Revert "Adding Milliseconds to DateTime fields (#173)" (#197) This reverts commit431dfa4156. * ported new BatchParser * added BatchParser tests * fixing merge conflicts * fix build issues * cleaned code and addressed comments from code review * addressed code review and made BatchParser logic more efficient * fixed batch parser tests * changed class name to fix build issues * fixed merge conflicts * added path for lab mode baseline tests * changed env path for lab mode * added env variable to appveyor * testing env variable for appveyor * fixed lab build * debug appveyor build * testing changes for appveyor * changed trace env path * debugging appveyor build * changed baseline env path * debugging * debugging * debugging * switched on trace flag * debugging * debugging * changed build config * changed baseline files * checking baseline output * changed baseline files * debug baseline tests * debugging baseline * debugging * debugging * debug * debugging * testing baseline format * debug * debug * debug * debug * debug * newline debug * changed baseline file * debug * test * try new way to read * added execution engine tests * change test * testing file encoding * moved execution engine tests to integration * try compare without spaces * removed no op test * added env variable for travis * put batch parser tests to integration too * put batch parser in integration * try new baseline string match * compare baseline test logic changed * changed baseline logic as well as cleaned tests * fix build for travis CI * fix travis CI issues * fixed highlighting bugs on vscode * code review changes * ported new BatchParser * added BatchParser tests * Initial commit for GitHub IO pages * Add initial doxfx content * Update manifest.json * Update manifest.json * Set theme jekyll-theme-cayman * Set theme jekyll-theme-slate * Set theme jekyll-theme-minimal * Set theme jekyll-theme-tactile * Clear out theme setting * Remove API docs * Revert "Adding Milliseconds to DateTime fields (#173)" (#197) This reverts commit431dfa4156. * fixing merge conflicts * fix build issues * cleaned code and addressed comments from code review * addressed code review and made BatchParser logic more efficient * fixed batch parser tests * changed class name to fix build issues * fixed merge conflicts * added path for lab mode baseline tests changed env path for lab mode added env variable to appveyor testing env variable for appveyor fixed lab build debug appveyor build testing changes for appveyor changed trace env path debugging appveyor build changed baseline env path debugging debugging debugging switched on trace flag debugging debugging changed build config changed baseline files checking baseline output changed baseline files debug baseline tests debugging baseline debugging debugging debug debugging testing baseline format debug debug debug debug debug newline debug changed baseline file debug test try new way to read added execution engine tests change test testing file encoding moved execution engine tests to integration try compare without spaces removed no op test added env variable for travis * put batch parser tests to integration too * put batch parser in integration try new baseline string match * compare baseline test logic changed * changed baseline logic as well as cleaned tests * fix build for travis CI * fix travis CI issues * fixed highlighting bugs on vscode * code review changes * fixed filestream writer test * added localization string * added localization string * generated new string files again * code review changes
119 lines
4.0 KiB
C#
119 lines
4.0 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System.Collections.Generic;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.BatchParser
|
|
{
|
|
/// <summary>
|
|
/// This class gives information about lines being parsed by
|
|
/// the Batch Parser
|
|
/// </summary>
|
|
class LineInfo
|
|
{
|
|
private IEnumerable<Token> tokens;
|
|
private IEnumerable<VariableReference> variableRefs;
|
|
|
|
/// <summary>
|
|
/// Constructor method for the LineInfo class
|
|
/// </summary>
|
|
public LineInfo(IEnumerable<Token> tokens, IEnumerable<VariableReference> variableRefs)
|
|
{
|
|
this.tokens = tokens;
|
|
this.variableRefs = variableRefs;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the stream position for offset and returns a PositionStruct
|
|
/// </summary>
|
|
public PositionStruct GetStreamPositionForOffset(int offset)
|
|
{
|
|
if (variableRefs != null)
|
|
{
|
|
offset = CalculateVarsUnresolvedOffset(offset);
|
|
}
|
|
int charCount = 0;
|
|
Token lastToken = null;
|
|
foreach (Token token in tokens)
|
|
{
|
|
lastToken = token;
|
|
if (charCount + token.Text.Length > offset)
|
|
{
|
|
int line, column;
|
|
CalculateLineColumnForOffset(token, offset - charCount, out line, out column);
|
|
return new PositionStruct(line, column, token.Begin.Offset + (offset - charCount), token.Filename);
|
|
}
|
|
charCount += token.Text.Length;
|
|
}
|
|
if (lastToken != null)
|
|
{
|
|
return new PositionStruct(lastToken.End.Line, lastToken.End.Column, lastToken.End.Offset, lastToken.Filename);
|
|
}
|
|
else
|
|
{
|
|
return new PositionStruct(1, 1, 0, string.Empty);
|
|
}
|
|
}
|
|
|
|
internal static void CalculateLineColumnForOffset(Token token, int offset, out int line, out int column)
|
|
{
|
|
CalculateLineColumnForOffset(token.Text, offset, 0, token.Begin.Line, token.Begin.Column, out line, out column);
|
|
}
|
|
|
|
internal static void CalculateLineColumnForOffset(string text, int offset,
|
|
int offsetDelta, int lineDelta, int columnDelta, out int line, out int column)
|
|
{
|
|
line = lineDelta;
|
|
column = columnDelta;
|
|
int counter = offsetDelta;
|
|
while (counter < offset)
|
|
{
|
|
bool newLineWithCR = false;
|
|
|
|
if (text[counter] == '\r')
|
|
{
|
|
newLineWithCR = true;
|
|
}
|
|
else if (text[counter] == '\n')
|
|
{
|
|
line++;
|
|
column = 0;
|
|
}
|
|
counter++;
|
|
if (newLineWithCR && counter < text.Length && text[counter] != '\n')
|
|
{
|
|
line++;
|
|
column = 0;
|
|
}
|
|
column++;
|
|
}
|
|
}
|
|
|
|
private int CalculateVarsUnresolvedOffset(int offset)
|
|
{
|
|
// find offset of the beginning of variable substitution (if offset points to the middle of it)
|
|
int diff = 0;
|
|
foreach (VariableReference reference in variableRefs)
|
|
{
|
|
if (reference.Start >= offset)
|
|
{
|
|
break;
|
|
}
|
|
else if (reference.VariableValue != null && offset < reference.Start + reference.VariableValue.Length)
|
|
{
|
|
offset = reference.Start;
|
|
break;
|
|
}
|
|
if (reference.VariableValue != null)
|
|
{
|
|
diff += reference.Length - reference.VariableValue.Length;
|
|
}
|
|
}
|
|
return offset + diff;
|
|
}
|
|
|
|
}
|
|
}
|