本文整理汇总了C#中IVsTextBuffer.GetLengthOfLine方法的典型用法代码示例。如果您正苦于以下问题:C# IVsTextBuffer.GetLengthOfLine方法的具体用法?C# IVsTextBuffer.GetLengthOfLine怎么用?C# IVsTextBuffer.GetLengthOfLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsTextBuffer
的用法示例。
在下文中一共展示了IVsTextBuffer.GetLengthOfLine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateBreakpointLocation
public override int ValidateBreakpointLocation(IVsTextBuffer buffer, int line, int col, TextSpan[] pCodeSpan)
{
if (pCodeSpan != null) {
pCodeSpan[0].iStartLine = line;
pCodeSpan[0].iEndLine = line;
List<TokenInfo> tokens = new List<TokenInfo>();
if (buffer != null) {
int length;
buffer.GetLengthOfLine(line, out length);
IVsTextLines lines = (IVsTextLines)buffer;
string text;
lines.GetLineText(line, 0, line, length, out text);
Scanner scanner = new Scanner();
scanner.SetSource(text, 0);
int state = 0, start, end;
int tokenType = -1;
while (tokenType != ((int)Tokens.EOF)) {
tokenType = scanner.GetNext(ref state, out start, out end);
tokens.Add(new TokenInfo(start, end, tokenType, scanner.yytext));
}
for (int i = 0; i < tokens.Count; i++) {
TokenInfo t = tokens[i];
if (t.type == (int)Tokens.OUTACTION
|| t.type == (int)Tokens.METHOD
|| t.type == (int)Tokens.LCASEIDENT
|| (t.type == (int)Tokens.NUMBER && t.text == "0")) {
pCodeSpan[0].iStartIndex = t.start;
pCodeSpan[0].iEndIndex = t.end + 1;
return Microsoft.VisualStudio.VSConstants.S_OK;
} else if (t.type == (int)Tokens.PROC) {
//Just a heuristic, if there is a '=' somewhere after this, then we don't want it
//Most likely it is Foo = proc or Foo(x,y,z) = proc and we don't want to highlight that
bool canUseProc = true;
for (int j = i + 1; j < tokens.Count; j++) {
if (tokens[j].type == (int)'=') {
i = j;
canUseProc = false;
break;
}
}
if (canUseProc) {
pCodeSpan[0].iStartIndex = t.start;
pCodeSpan[0].iEndIndex = t.end + 1;
return Microsoft.VisualStudio.VSConstants.S_OK;
}
}
}
}
}
return Microsoft.VisualStudio.VSConstants.S_FALSE;
}
示例2: ValidateBreakpointLocation
public override int ValidateBreakpointLocation(IVsTextBuffer buffer, int line, int col, TextSpan[] pCodeSpan)
{
if (pCodeSpan != null)
{
pCodeSpan[0].iStartLine = line;
pCodeSpan[0].iStartIndex = col;
pCodeSpan[0].iEndLine = line;
pCodeSpan[0].iEndIndex = col;
if (buffer != null)
{
int length;
buffer.GetLengthOfLine(line, out length);
pCodeSpan[0].iStartIndex = 0;
pCodeSpan[0].iEndIndex = length;
}
return Microsoft.VisualStudio.VSConstants.S_OK;
}
else
{
return Microsoft.VisualStudio.VSConstants.S_FALSE;
}
}
示例3: ValidateBreakpointLocation
/// <summary>
/// Called to determine if the given location can have a breakpoint applied to it.
/// </summary>
/// <param name="buffer">The IVsTextBuffer object containing the source file.</param>
/// <param name="line">The line number where the breakpoint is to be set.</param>
/// <param name="col">The offset into the line where the breakpoint is to be set.</param>
/// <param name="pCodeSpan">
/// Returns the TextSpan giving the extent of the code affected by the breakpoint if the
/// breakpoint can be set.
/// </param>
/// <returns>
/// If successful, returns S_OK; otherwise returns S_FALSE if there is no code at the given
/// position or returns an error code (the validation is deferred until the debug engine is loaded).
/// </returns>
/// <remarks>
/// <para>
/// CAUTION: Even if you do not intend to support the ValidateBreakpointLocation but your language
/// does support breakpoints, you must override the ValidateBreakpointLocation method and return a
/// span that contains the specified line and column; otherwise, breakpoints cannot be set anywhere
/// except line 1. You can return E_NOTIMPL to indicate that you do not otherwise support this
/// method but the span must always be set. The example shows how this can be done.
/// </para>
/// <para>
/// Since the language service parses the code, it generally knows what is considered code and what
/// is not. Normally, the debug engine is loaded and the pending breakpoints are bound to the source. It is at this time the breakpoint location is validated. This method is a fast way to determine if a breakpoint can be set at a particular location without loading the debug engine.
/// </para>
/// <para>
/// You can implement this method to call the ParseSource method with the parse reason of CodeSpan.
/// The parser examines the specified location and returns a span identifying the code at that
/// location. If there is code at the location, the span identifying that code should be passed to
/// your implementation of the CodeSpan method in your version of the AuthoringSink class. Then your
/// implementation of the ValidateBreakpointLocation method retrieves that span from your version of
/// the AuthoringSink class and returns that span in the pCodeSpan argument.
/// </para>
/// <para>
/// The base method returns E_NOTIMPL.
/// </para>
/// </remarks>
public override int ValidateBreakpointLocation(IVsTextBuffer buffer, int line, int col, TextSpan[] pCodeSpan)
{
// TODO: Add code to not allow breakpoints to be placed on non-code lines.
// TODO: Refactor to allow breakpoint locations to span multiple lines.
if (pCodeSpan != null)
{
pCodeSpan[0].iStartLine = line;
pCodeSpan[0].iStartIndex = col;
pCodeSpan[0].iEndLine = line;
pCodeSpan[0].iEndIndex = col;
if (buffer != null)
{
int length;
buffer.GetLengthOfLine(line, out length);
pCodeSpan[0].iStartIndex = 0;
pCodeSpan[0].iEndIndex = length;
}
return VSConstants.S_OK;
}
return VSConstants.S_FALSE;
}