本文整理汇总了C#中IDocument.GetLineForOffset方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetLineForOffset方法的具体用法?C# IDocument.GetLineForOffset怎么用?C# IDocument.GetLineForOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetLineForOffset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindEndStatementAroundOffset
static int FindEndStatementAroundOffset(IDocument document, int offset, out VBStatement statement)
{
IDocumentLine line = document.GetLineForOffset(offset);
string interestingText = VBNetFormattingStrategy.TrimLine(line.Text).Trim(' ', '\t');
//LoggingService.Debug("text: '" + interestingText + "'");
foreach (VBStatement s in VBNetFormattingStrategy.Statements) {
Match match = Regex.Matches(interestingText, s.EndRegex, RegexOptions.Singleline | RegexOptions.IgnoreCase).OfType<Match>().FirstOrDefault();
if (match != null) {
//LoggingService.DebugFormatted("Found end statement at offset {1}: {0}", s, offset);
statement = s;
int result = match.Index + (line.Length - line.Text.TrimStart(' ', '\t').Length) + line.Offset;
if (offset >= result && offset <= (result + match.Length))
return result;
}
}
statement = null;
return -1;
}
示例2: Resolve
// ********************************************************************************************************************************
/// <summary>
/// Attempts to resolve a reference to a resource.
/// </summary>
/// <param name="fileName">The name of the file that contains the expression to be resolved.</param>
/// <param name="document">The document that contains the expression to be resolved.</param>
/// <param name="caretLine">The 0-based line in the file that contains the expression to be resolved.</param>
/// <param name="caretColumn">The 0-based column position of the expression to be resolved.</param>
/// <param name="caretOffset">The offset of the position of the expression to be resolved.</param>
/// <param name="charTyped">The character that has been typed at the caret position but is not yet in the buffer (this is used when invoked from code completion), or <c>null</c>.</param>
/// <returns>A <see cref="ResourceResolveResult"/> that describes which resource is referenced by the expression at the specified position in the specified file, or <c>null</c> if that expression does not reference a (known) resource.</returns>
protected override ResourceResolveResult Resolve(string fileName, IDocument document, int caretLine, int caretColumn, int caretOffset, char? charTyped)
{
IExpressionFinder ef = ResourceResolverService.GetExpressionFinder(fileName);
if (ef == null) {
return null;
}
bool foundStringLiteral = false;
while (true) {
ExpressionResult result = ef.FindFullExpression(document.Text, caretOffset);
if (result.Expression == null) {
// Try to find an expression to the left, but only
// in the same line.
if (foundStringLiteral || --caretOffset < 0)
return null;
var line = document.GetLineForOffset(caretOffset);
if (line.LineNumber - 1 != caretLine)
return null;
continue;
}
if (!result.Region.IsEmpty) {
caretLine = result.Region.BeginLine - 1;
caretColumn = result.Region.BeginColumn - 1;
}
PrimitiveExpression pe;
Expression expr = NRefactoryAstCacheService.ParseExpression(fileName, result.Expression, caretLine + 1, caretColumn + 1);
if (expr == null) {
return null;
} else if ((pe = expr as PrimitiveExpression) != null) {
if (pe.Value is string) {
if (foundStringLiteral) {
return null;
}
// We are inside a string literal and need to find
// the next outer expression to decide
// whether it is a resource key.
if (!result.Region.IsEmpty) {
// Go back to the start of the string literal - 2.
caretOffset = document.PositionToOffset(result.Region.BeginLine, result.Region.BeginColumn) - 2;
if (caretOffset < 0) return null;
} else {
LoggingService.Debug("ResourceToolkit: NRefactoryResourceResolver: Found string literal, but result region is empty. Trying to infer position from text.");
int newCaretOffset = document.GetText(0, Math.Min(document.TextLength, caretOffset + result.Expression.Length)).LastIndexOf(result.Expression);
if (newCaretOffset == -1) {
LoggingService.Warn("ResourceToolkit: NRefactoryResourceResolver: Could not find resolved expression in text.");
--caretOffset;
continue;
} else {
caretOffset = newCaretOffset;
}
}
foundStringLiteral = true;
continue;
} else {
return null;
}
}
return TryResolve(result, expr, caretLine, caretColumn, fileName, document.Text, ef, charTyped);
}
}
示例3: GetNextLineStart
/// <summary>
/// Get start of the next line (that is, from offset, go one line down and to its start).
/// </summary>
int GetNextLineStart(IDocument document, int offset)
{
int nextLineNuber = document.GetLineForOffset(offset).LineNumber + 1;
return document.GetLine(nextLineNuber).Offset;
}
示例4: GetBodyIndent
/// <summary>
/// Indents the switch body by the same indent the whole snippet has and adds one TAB.
/// </summary>
string GetBodyIndent(IDocument document, int offset)
{
int lineStart = document.GetLineForOffset(offset).Offset;
string indent = DocumentUtilitites.GetWhitespaceAfter(document, lineStart);
return indent;
}
示例5: findBodyChanges
/// <summary>
/// Find first change in project structure. Determines which method is changed etc. .
/// </summary>
/// <param name="change">Additional info about change in source code text.</param>
/// <param name="doc">Document, that was changed.</param>
/// <returns>Instance of BodyChange, containing info about change in structure.</returns>
private BodyChange findBodyChanges(TextChangeEventArgs change, IDocument doc)
{
IDocumentLine line = doc.GetLineForOffset(change.Offset);
int row = line.LineNumber;
int column = change.Offset - line.Offset;
bool found = false;
BodyChange entity = null;
foreach(IClass classEl in ParserService.CurrentProjectContent.Classes)
{
if (classEl is CompoundClass)
{
CompoundClass compClass = classEl as CompoundClass;
foreach (IClass compPart in compClass.Parts)
{
if (compPart.BodyRegion.IsInside(row, column) && FileUtility.IsEqualFileName(classEl.CompilationUnit.FileName, changingFilename))
{
entity = findBodyChangesClass(compPart, row, column);
if(entity != null){
found = true;
break;
}
}
}
if(found)
break;
}
if (classEl.BodyRegion.IsInside(row, column) && FileUtility.IsEqualFileName(classEl.CompilationUnit.FileName,changingFilename))
{
entity = findBodyChangesClass(classEl, row, column);
if(entity != null){
found = true;
break;
}
}
}
return entity;
}