本文整理汇总了C#中IVsTextLines.GetLengthOfLine方法的典型用法代码示例。如果您正苦于以下问题:C# IVsTextLines.GetLengthOfLine方法的具体用法?C# IVsTextLines.GetLengthOfLine怎么用?C# IVsTextLines.GetLengthOfLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsTextLines
的用法示例。
在下文中一共展示了IVsTextLines.GetLengthOfLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseLine
public List<TokenInfo> ParseLine(IVsTextLines textLines, int line, int maxTokens, out string lineOut)
{
int maxColumn;
textLines.GetLengthOfLine(line, out maxColumn);
textLines.GetLineText(line, 0, line, maxColumn, out lineOut);
return Parse(lineOut, maxTokens);
}
示例2: Line
internal static string Line(IVsTextLines vsTextLines, int index)
{
int length;
vsTextLines.GetLengthOfLine(index, out length);
string result;
vsTextLines.GetLineText(index, 0, index, length, out result);
return result;
}
示例3: SearchForCodeBlocks
// »щет в исходном файле все блоки, обрамленные прагмой #line N / #line default
private void SearchForCodeBlocks(IVsTextLines buffer)
{
ErrorHandler.ThrowOnFailure(buffer.LockBufferEx((uint)BufferLockFlags.BLF_READ));
try
{
int totalLines;
ErrorHandler.ThrowOnFailure(buffer.GetLineCount(out totalLines));
var state = ParseState.WaitForBlockStart;
var blockSpan = new TextSpanAndCookie();
for (int line = 0; line < totalLines; ++line)
{
int lineLen;
ErrorHandler.ThrowOnFailure(buffer.GetLengthOfLine(line, out lineLen));
string lineText;
ErrorHandler.ThrowOnFailure(buffer.GetLineText(line, 0, line, lineLen, out lineText));
if (state == ParseState.WaitForBlockStart)
{
var match = _linePragmaRegex.Match(lineText);
if (match.Success)
{
blockSpan.ulHTMLCookie = uint.Parse(match.Groups[1].Value, NumberStyles.Integer, CultureInfo.InvariantCulture);
blockSpan.CodeSpan = new TextSpan();
blockSpan.CodeSpan.iStartLine = line + 1;
blockSpan.CodeSpan.iStartIndex = 0;
state = ParseState.WaitForBlockEnd;
}
}
else
{
if (lineText.Trim().StartsWith("#line default", StringComparison.InvariantCultureIgnoreCase))
{
blockSpan.CodeSpan.iEndLine = line - 1;
buffer.GetLengthOfLine(blockSpan.CodeSpan.iEndLine, out blockSpan.CodeSpan.iEndIndex);
blocks.Add(blockSpan);
blockSpan = new TextSpanAndCookie();
state = ParseState.WaitForBlockStart;
}
}
}
}
finally
{
// Make sure that the buffer is always unlocked when we exit this function.
buffer.UnlockBufferEx((uint)BufferLockFlags.BLF_READ);
}
}
示例4: addMarkersToDocument
private static void addMarkersToDocument(IVsTextLines textLines)
{
int lineCount;
textLines.GetLineCount(out lineCount);
for (int i = 0; i < lineCount; ++i)
{
string text;
int len;
textLines.GetLengthOfLine(i, out len);
textLines.GetLineText(i, 0, i, len, out text);
string cmt = "//";
string issueKey = "PL-1357";
if (text == null || !text.Contains(cmt) || !text.Contains(issueKey)) continue;
int cmtIdx = text.IndexOf(cmt);
int idx = text.IndexOf(issueKey);
if (idx < cmtIdx) continue;
addMarker(textLines, i, idx, idx + issueKey.Length);
}
}
示例5: PositionCaretForEditing
public int PositionCaretForEditing(IVsTextLines pBuffer, [ComAliasName("Microsoft.VisualStudio.TextManager.Interop.TextSpan")]VsTextSpan[] ts)
{
// If the formatted location of the $end$ position (the inserted comment) was on an
// empty line and indented, then we have already removed the white space on that line
// and the navigation location will be at column 0 on a blank line. We must now
// position the caret in virtual space.
if (indentCaretOnCommit)
{
int lineLength;
pBuffer.GetLengthOfLine(ts[0].iStartLine, out lineLength);
string lineText;
pBuffer.GetLineText(ts[0].iStartLine, 0, ts[0].iStartLine, lineLength, out lineText);
if (lineText == string.Empty)
{
int endLinePosition;
pBuffer.GetPositionOfLine(ts[0].iStartLine, out endLinePosition);
TextView.TryMoveCaretToAndEnsureVisible(new VirtualSnapshotPoint(TextView.TextSnapshot.GetPoint(endLinePosition), indentDepth));
}
}
return VSConstants.S_OK;
}
示例6: Normalize
/// <devdoc>Pins the text span to valid line bounds returned from IVsTextLines.</devdoc>
internal static void Normalize(ref TextSpan span, IVsTextLines textLines)
{
MakePositive(ref span);
if (textLines == null) return;
//adjust max. lines
int lineCount;
if (NativeMethods.Failed(textLines.GetLineCount(out lineCount)))
return;
span.iEndLine = Math.Min(span.iEndLine, lineCount - 1);
//make sure the start is still before the end
if (!IsPositive(span))
{
span.iStartLine = span.iEndLine;
span.iStartIndex = span.iEndIndex;
}
//adjust for line length
int lineLength;
if (NativeMethods.Failed(textLines.GetLengthOfLine(span.iStartLine, out lineLength)))
return;
span.iStartIndex = Math.Min(span.iStartIndex, lineLength);
if (NativeMethods.Failed(textLines.GetLengthOfLine(span.iEndLine, out lineLength)))
return;
span.iEndIndex = Math.Min(span.iEndIndex, lineLength);
}
示例7: PositionCaretForEditing
public int PositionCaretForEditing(IVsTextLines pBuffer, [ComAliasName("Microsoft.VisualStudio.TextManager.Interop.TextSpan")]VsTextSpan[] ts)
{
// If the formatted location of the $end$ position (the inserted comment) was on an
// empty line and indented, then we have already removed the white space on that line
// and the navigation location will be at column 0 on a blank line. We must now
// position the caret in virtual space.
int lineLength;
pBuffer.GetLengthOfLine(ts[0].iStartLine, out lineLength);
string endLineText;
pBuffer.GetLineText(ts[0].iStartLine, 0, ts[0].iStartLine, lineLength, out endLineText);
int endLinePosition;
pBuffer.GetPositionOfLine(ts[0].iStartLine, out endLinePosition);
PositionCaretForEditingInternal(endLineText, endLinePosition);
return VSConstants.S_OK;
}
示例8: GetLineInfo
/// <include file='doc\Colorizer.uex' path='docs/doc[@for="Colorizer.GetLineInfo"]/*' />
public virtual TokenInfo[] GetLineInfo(IVsTextLines buffer, int line, IVsTextColorState colorState) {
int length;
NativeMethods.ThrowOnFailure(buffer.GetLengthOfLine(line, out length));
if (length == 0)
return null;
string text;
NativeMethods.ThrowOnFailure(buffer.GetLineText(line, 0, line, length, out text));
int state;
NativeMethods.ThrowOnFailure(colorState.GetColorStateAtStartOfLine(line, out state));
if (this.cachedLine == line && this.cachedLineText == text &&
this.cachedLineState == state && this.cachedLineInfo != null) {
return this.cachedLineInfo;
}
// recolorize the line, and cache the results
this.cachedLineInfo = null;
this.cachedLine = line;
this.cachedLineText = text;
this.cachedLineState = state;
NativeMethods.ThrowOnFailure(GetColorInfo(text, length, state));
//now it should be in the cache
return this.cachedLineInfo;
}
示例9: CollapseToDefinitions
public int CollapseToDefinitions(IVsTextLines textLines, IVsOutliningSession session){
if (textLines == null || session == null) return (int)HResult.E_INVALIDARG;
int lastLine;
int lastIdx;
string text;
textLines.GetLineCount(out lastLine );
textLines.GetLengthOfLine(--lastLine, out lastIdx);
textLines.GetLineText(0, 0, lastLine, lastIdx, out text);
NewOutlineRegion[] outlineRegions = this.GetCollapsibleRegions(text, VsShell.GetFilePath(textLines));
if (outlineRegions != null && outlineRegions.Length > 0)
session.AddOutlineRegions((uint)ADD_OUTLINE_REGION_FLAGS.AOR_PRESERVE_EXISTING, outlineRegions.Length, outlineRegions);
return 0;
}
示例10: GetLineInfo
/// <include file='doc\Colorizer.uex' path='docs/doc[@for="Colorizer.GetLineInfo"]/*' />
public virtual TokenInfo[] GetLineInfo(IVsTextLines buffer, int line, IVsTextColorState colorState)
{
int length;
NativeMethods.ThrowOnFailure(buffer.GetLengthOfLine(line, out length));
if (length == 0)
return null;
string text;
NativeMethods.ThrowOnFailure(buffer.GetLineText(line, 0, line, length, out text));
int state;
NativeMethods.ThrowOnFailure(colorState.GetColorStateAtStartOfLine(line, out state));
if (this.cachedLine == line && this.cachedLineText == text &&
this.cachedLineState == state && this.cachedLineInfo != null) {
return this.cachedLineInfo;
}
// recolorize the line, and cache the results
this.cachedLineInfo = null;
this.cachedLine = line;
this.cachedLineText = text;
this.cachedLineState = state;
// GetColorInfo will update the cache. Note that here we don't use NativeMethods.ThrowOnFailure
// because the return code is the current parsing state, not an HRESULT.
GetColorInfo(text, length, state);
//now it should be in the cache
return this.cachedLineInfo;
}
示例11: 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>();
string codeToFormat;
int endOfFirstLineIndex;
// Get 1st line and parse custom define
pBuffer.GetLengthOfLine(0, out endOfFirstLineIndex);
pBuffer.GetLineText(0, 0, 0, endOfFirstLineIndex, out codeToFormat);
Dictionary<string,string> defines = ParseDefineLine(codeToFormat);
AsmHighlighterScanner scanner = AsmHighlighterScannerFactory.GetScanner(filePath);
Scanner lexer = scanner.Lexer;
// Iterate on each line of the selection to format
for (int line = span.iStartLine; line <= span.iEndLine; line++)
{
int lineLength;
pBuffer.GetLengthOfLine(line, out lineLength);
pBuffer.GetLineText(line, 0, line, lineLength, out codeToFormat);
string codeToAssemble = ConvertToFasm(lexer, codeToFormat, defines);
lexer.SetSource(codeToFormat, 0);
int state = 0;
int start, end;
bool instructionFound = false, commentFound = false;
int commentStart = 0;
AsmHighlighterToken token = (AsmHighlighterToken)lexer.GetNext(ref state, out start, out end);
while (token != AsmHighlighterToken.EOF )
{
switch (token)
{
case AsmHighlighterToken.INSTRUCTION:
case AsmHighlighterToken.FPUPROCESSOR:
case AsmHighlighterToken.SIMDPROCESSOR:
instructionFound = true;
break;
case AsmHighlighterToken.COMMENT_LINE:
if (!commentFound)
{
commentFound = true;
commentStart = start;
}
break;
}
if ( instructionFound && commentFound )
{
byte[] buffer = null;
try
{
buffer = ManagedFasm.Assemble(codeToAssemble);
}
catch (Exception ex)
{
// Unable to parse instruction... skip
}
if (buffer != null)
{
}
TextSpan editTextSpan = new TextSpan();
editTextSpan.iStartLine = line;
editTextSpan.iEndLine = line;
editTextSpan.iStartIndex = commentStart;
editTextSpan.iEndIndex = commentStart+1;
if ((codeToFormat.Length - commentStart) > 2 && codeToFormat.Substring(commentStart, 2) == ";#")
{
editTextSpan.iEndIndex = editTextSpan.iEndIndex + 2;
}
string text = ";#" + ((buffer == null) ? "?" : string.Format("{0:X}",buffer.Length));
changeList.Add(new EditSpan(editTextSpan, text));
break;
}
token = (AsmHighlighterToken)lexer.GetNext(ref state, out start, out end);
}
}
return changeList;
}
示例12: GetBufferSpan
/// <summary>
/// Get entire TextLines buffer as a TextSpan
/// </summary>
/// <param name="pBuffer"></param>
/// <returns></returns>
private static TextSpan GetBufferSpan(IVsTextLines textBuffer)
{
ArgumentValidation.CheckForNullReference(textBuffer, "textBuffer");
var lineCount = 0;
var charCount = 0;
// Get line count for the whole buffer.
var result = textBuffer.GetLineCount(out lineCount);
if (result == VSConstants.S_OK
&& lineCount > 0)
{
// Get char count for last line.
result = textBuffer.GetLengthOfLine(lineCount - 1, out charCount);
if (result != VSConstants.S_OK)
{
charCount = 0;
}
}
else
{
lineCount = 0;
}
// Create a TextSpan from begin to end of the text buffer.
var span = new TextSpan();
span.iStartLine = 0;
span.iStartIndex = 0;
span.iEndLine = lineCount - 1 > 0 ? lineCount - 1 : 0;
span.iEndIndex = charCount > 0 ? charCount : 0;
return span;
}
示例13: GetTextFromVsTextLines
internal static string GetTextFromVsTextLines(IVsTextLines vsTextLines) {
int lines;
int lastLineLength;
VSErrorHandler.ThrowOnFailure(vsTextLines.GetLineCount(out lines));
VSErrorHandler.ThrowOnFailure(vsTextLines.GetLengthOfLine(lines - 1, out lastLineLength));
string text;
VSErrorHandler.ThrowOnFailure(vsTextLines.GetLineText(0, 0, lines - 1, lastLineLength, out text));
return text;
}
示例14: SearchForCodeBlocks
private void SearchForCodeBlocks(IVsTextLines buffer)
{
// We don't want any change in the buffer while we are parsing,
// so we have to lock it.
ErrorHandler.ThrowOnFailure(buffer.LockBufferEx((uint)BufferLockFlags.BLF_READ));
try {
// Find the total number of lines in the buffer.
int totalLines;
ErrorHandler.ThrowOnFailure(buffer.GetLineCount(out totalLines));
// Set the initial values for the variables used during the parsing.
SimpleParserState state = SimpleParserState.WaitForExternalSource;
TextSpanAndCookie blockSpan = new TextSpanAndCookie();
// Parse all the lines in the buffer
for (int line = 0; line < totalLines; ++line) {
// Get the text of the current line.
int lineLen;
ErrorHandler.ThrowOnFailure(buffer.GetLengthOfLine(line, out lineLen));
if (0 == lineLen) {
// The line is empty, no point in parsing it.
continue;
}
string lineText;
ErrorHandler.ThrowOnFailure(buffer.GetLineText(line, 0, line, lineLen, out lineText));
// Create the tokenizer.
CompilerContext context = new CompilerContext("", new QuietCompilerSink());
using (SystemState systemState = new SystemState()) {
tokenizer = new Tokenizer(lineText.ToCharArray(), true, systemState, context);
Token token = null;
string commentText;
// Read all the token looking for the code blocks inside a Snippet Statements
// nested in an External Source statement. Note that the standard IronPython
// parser does not return such statements and this is the reason for this
// parser.
while (!tokenizer.IsEndOfFile) {
token = tokenizer.Next();
// This parser is strange in that it is only interested in comments:
// an external code statement is in the form
// #ExternalSource("PathOfTheOriginalFile", originalLineNumber)
// ... (some code) ...
// #End ExternalSource
// and a snippet statement is
// # Snippet Statement
// ... (some code) ...
// #End Snippet Statement
// So if we want to find the text region inside a snippet nested
// inside an external source, we are only interested in the comment tokens.
if (TokenKind.Comment != token.Kind) {
continue;
}
// The comments are line comments, so the comment's text is everything that
// is after the beginning of the comment.
commentText = CleanCommentStart(lineText.Substring(tokenizer.StartLocation.Column));
if (string.IsNullOrEmpty(commentText)) {
continue;
}
switch (state) {
case SimpleParserState.WaitForExternalSource:
// This function returns a non zero value only if the comment text
// is a valid external source statment.
blockSpan.ulHTMLCookie = ParseExternalSource(commentText);
if (0 != blockSpan.ulHTMLCookie) {
// The CodeDOM provider is adding 1 to the line number, but in this
// case the number is actualy the HTML editor's cookie, so we have to
// restore the original value.
blockSpan.ulHTMLCookie -= 1;
state = SimpleParserState.WaitForSnippet;
}
break;
case SimpleParserState.WaitForSnippet:
// Check if this comment is the beginning of a snippet block.
if (IsBeginSnippet(commentText)) {
// This is the beginning of a snippet block, so
// the actual code will start at the beginning of the
// next line.
blockSpan.CodeSpan.iStartLine = line + 1;
// Set the default for the start index.
blockSpan.CodeSpan.iStartIndex = 0;
// Now we have to find the end of the snippet section
// to complete the span of the code.
state = SimpleParserState.WaitForEndSnippet;
} else if (IsEndExternalSource(commentText)) {
// This was and external block not related to the HTML editor.
// Reset the text span and wait for the next external source.
blockSpan = new TextSpanAndCookie();
state = SimpleParserState.WaitForExternalSource;
}
break;
case SimpleParserState.WaitForEndSnippet:
if (IsEndSnippet(commentText)) {
//.........这里部分代码省略.........
示例15: TextSpanNormalize
public static void TextSpanNormalize(ref TextSpan span, IVsTextLines textLines ) {
TextSpanMakePositive(ref span );
if (textLines == null) return;
//adjust max. lines
int lineCount;
try {
textLines.GetLineCount(out lineCount );
} catch (Exception) {
return;
}
span.iEndLine = Math.Min( span.iEndLine, lineCount-1 );
//make sure the start is still before the end
if (!TextSpanPositive( span)) {
span.iStartLine = span.iEndLine;
span.iStartIndex = span.iEndIndex;
}
//adjust for line length
int lineLength;
try {
textLines.GetLengthOfLine( span.iStartLine, out lineLength );
} catch (Exception) {
return;
}
span.iStartIndex = Math.Min( span.iStartIndex, lineLength );
try {
textLines.GetLengthOfLine( span.iEndLine, out lineLength );
} catch (Exception) {
return;
}
span.iEndIndex = Math.Min( span.iEndIndex, lineLength );
}