本文整理汇总了C#中IVsTextLines.GetLineIndexOfPosition方法的典型用法代码示例。如果您正苦于以下问题:C# IVsTextLines.GetLineIndexOfPosition方法的具体用法?C# IVsTextLines.GetLineIndexOfPosition怎么用?C# IVsTextLines.GetLineIndexOfPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsTextLines
的用法示例。
在下文中一共展示了IVsTextLines.GetLineIndexOfPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReformatCode
public static List<EditSpan> ReformatCode(IVsTextLines pBuffer, TextSpan span, int tabSize)
{
string filePath = FilePathUtilities.GetFilePath(pBuffer);
// Return dynamic scanner based on file extension
List<EditSpan> changeList = new List<EditSpan>();
int nbLines;
pBuffer.GetLineCount(out nbLines);
string codeToFormat;
int lastLine;
int lastLineIndex;
pBuffer.GetLastLineIndex(out lastLine, out lastLineIndex);
pBuffer.GetLineText(0, 0, lastLine, lastLineIndex, out codeToFormat);
NShaderScanner shaderScanner = NShaderScannerFactory.GetShaderScanner(filePath);
Scanner lexer = shaderScanner.Lexer;
lexer.SetSource(codeToFormat, 0);
int spanStart;
int spanEnd;
pBuffer.GetPositionOfLineIndex(span.iStartLine, span.iStartIndex, out spanStart);
pBuffer.GetPositionOfLineIndex(span.iEndLine, span.iEndIndex, out spanEnd);
int state = 0;
int start, end;
ShaderToken token = (ShaderToken) lexer.GetNext(ref state, out start, out end);
List<int> brackets = new List<int>();
List<int> delimiters = new List<int>();
// !EOL and !EOF
int level = 0;
int startCopy = 0;
int levelParenthesis = 0;
while (token != ShaderToken.EOF)
{
switch (token)
{
case ShaderToken.LEFT_PARENTHESIS:
levelParenthesis++;
break;
case ShaderToken.RIGHT_PARENTHESIS:
levelParenthesis--;
if ( levelParenthesis < 0 )
{
levelParenthesis = 0;
}
break;
case ShaderToken.LEFT_BRACKET:
level++;
if (codeToFormat[start] == '{' && start >= spanStart && end <= spanEnd)
{
Match match = matchBraceStart.Match(codeToFormat, start);
StringBuilder codeFormatted = new StringBuilder();
codeFormatted.Append("{\r\n");
int levelToIndentNext = level;
if (match.Groups.Count == 2)
{
string matchStr = match.Groups[1].Value;
levelToIndentNext--;
}
for (int i = 0; i < levelToIndentNext; i++)
{
for (int j = 0; j < tabSize; j++)
{
codeFormatted.Append(' ');
}
}
if (match.Groups.Count == 2)
{
codeFormatted.Append("}\r\n");
}
TextSpan editTextSpan = new TextSpan();
pBuffer.GetLineIndexOfPosition(start,
out editTextSpan.iStartLine,
out editTextSpan.iStartIndex);
pBuffer.GetLineIndexOfPosition(startCopy + match.Index + match.Length,
out editTextSpan.iEndLine,
out editTextSpan.iEndIndex);
changeList.Add(new EditSpan(editTextSpan, codeFormatted.ToString()));
}
break;
case ShaderToken.RIGHT_BRACKET:
level--;
if (level < 0)
{
level = 0;
}
brackets.Add(start);
break;
case ShaderToken.DELIMITER:
if (codeToFormat[start] == ';' && start >= spanStart && end <= spanEnd && levelParenthesis == 0)
{
Match match = matchEndOfStatement.Match(codeToFormat, start);
//.........这里部分代码省略.........