本文整理汇总了C#中IDocument.GetLineNumberForOffset方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetLineNumberForOffset方法的具体用法?C# IDocument.GetLineNumberForOffset怎么用?C# IDocument.GetLineNumberForOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetLineNumberForOffset方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPointForOffset
static void GetPointForOffset(IDocument document, int offset, out int line, out int column) {
if (offset > document.TextLength) {
line = document.TotalNumberOfLines + 1;
column = 1;
} else if (offset < 0) {
line = -1;
column = -1;
} else {
line = document.GetLineNumberForOffset(offset);
column = offset - document.GetLineSegment(line).Offset;
}
}
示例2: MarkTokens
public void MarkTokens(IDocument document, List<LineSegment> inputLines)
{
if (Rules.Count == 0) {
return;
}
Dictionary<LineSegment, bool> processedLines = new Dictionary<LineSegment, bool>();
bool spanChanged = false;
foreach (LineSegment lineToProcess in inputLines) {
if (!processedLines.ContainsKey(lineToProcess)) {
int lineNumber = document.GetLineNumberForOffset(lineToProcess.Offset);
bool processNextLine = true;
if (lineNumber != -1) {
while (processNextLine && lineNumber < document.TotalNumberOfLines) {
if (lineNumber >= document.LineSegmentCollection.Count) { // may be, if the last line ends with a delimiter
break; // then the last line is not in the collection :)
}
processNextLine = MarkTokensInLine(document, lineNumber, ref spanChanged);
processedLines[currentLine] = true;
++lineNumber;
}
}
}
}
if (spanChanged) {
document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
} else {
// document.Caret.ValidateCaretPos();
// document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(document.Caret.Offset)));
//
foreach (LineSegment lineToProcess in inputLines) {
document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(lineToProcess.Offset)));
}
}
document.CommitUpdate();
currentLine = null;
}
示例3: SetupDataProvider
public void SetupDataProvider(string fileName, TextArea textArea)
{
if (setupOnlyOnce && this.textArea != null) return;
IDocument document = textArea.Document;
this.fileName = fileName;
this.document = document;
this.textArea = textArea;
int useOffset = (lookupOffset < 0) ? textArea.Caret.Offset : lookupOffset;
initialOffset = useOffset;
IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(fileName);
ExpressionResult expressionResult;
if (expressionFinder == null)
expressionResult = new ExpressionResult(TextUtilities.GetExpressionBeforeOffset(textArea, useOffset));
else
expressionResult = expressionFinder.FindExpression(textArea.Document.TextContent, useOffset);
if (expressionResult.Expression == null) // expression is null when cursor is in string/comment
return;
expressionResult.Expression = expressionResult.Expression.Trim();
if (LoggingService.IsDebugEnabled) {
if (expressionResult.Context == ExpressionContext.Default)
LoggingService.DebugFormatted("ShowInsight for >>{0}<<", expressionResult.Expression);
else
LoggingService.DebugFormatted("ShowInsight for >>{0}<<, context={1}", expressionResult.Expression, expressionResult.Context);
}
int caretLineNumber = document.GetLineNumberForOffset(useOffset);
int caretColumn = useOffset - document.GetLineSegment(caretLineNumber).Offset;
// the parser works with 1 based coordinates
SetupDataProvider(fileName, document, expressionResult, caretLineNumber + 1, caretColumn + 1);
}
示例4: SafeGetLineNumberForOffset
static int SafeGetLineNumberForOffset(IDocument document, int offset)
{
if (offset <= 0)
return 0;
if (offset >= document.TextLength)
return document.TotalNumberOfLines;
return document.GetLineNumberForOffset(offset);
}
示例5: FindFullExpression
private string FindFullExpression(string text, int offset, IDocument doc, out int start_off, out int end_off)
{
int i = offset;
int beg_line=1;
int off=0;
start_off = 0;
end_off = 0;
if (debuggedProcess != null)
{
beg_line = (int)debuggedProcess.SelectedFunction.symMethod.SequencePoints[0].Line;
off = doc.LineSegmentCollection[beg_line - 1].Offset;
}
//int lll = doc.GetLineNumberForOffset(offset) - 1;
int cur_str_off = doc.LineSegmentCollection[doc.GetLineNumberForOffset(offset)].Offset;
List<int> strs = new List<int>();
i = cur_str_off;
int cur_sk = 0;
//while (i >= 0 && text[i] != '\n')
//int len = text.Length;
while (text[i] != '\n')
if (text[i] == '\'')
{
if (i == offset) return null;
cur_sk = (cur_sk == 0) ? 1 : 0;
i++;
}
else if (i == offset && cur_sk == 1) return null;
else i++;
i = offset;
bool new_line = false;
while (i >= off)
if (text[i] == '\n') { new_line = true; i--; }
else
if (text[i] == '/' && i > 0 && text[i - 1] == '/') if (!new_line) return null; else i--;
else if (text[i] == '}') break;
else if (text[i] == '{') return null;
else i--;
i = offset;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (i >= 0 && !(Char.IsLetterOrDigit(text[i]) || text[i] == '_')) i--;
while (i >= 0 && (Char.IsLetterOrDigit(text[i]) || text[i] == '_'))
i--;
bool is_dot = false;
if (i >= 0)
{
if (text[i] == '.') is_dot = true;
int j = i + 1;
while (j < text.Length && (Char.IsLetterOrDigit(text[j]) || text[j] == '_'))
sb.Append(text[j++]);
if (j < text.Length && text[j] == '(')
return null;
end_off = j-1;
start_off = i+1;
}
else
{
int j = i + 1;
while (j < text.Length && (Char.IsLetterOrDigit(text[j]) || text[j] == '_'))
sb.Append(text[j++]);
if (j < text.Length && text[j] == '(')
return null;
end_off = j-1;
start_off = i+1;
}
if (is_dot)
{
/*StringBuilder new_sb = new StringBuilder();
new_sb.Insert(0,text[i]);
int j = i-1;
while (j >= 0)
{
if (text[j])
}*/
sb.Insert(0,'.');
PascalABCCompiler.Parsers.KeywordKind keyw=PascalABCCompiler.Parsers.KeywordKind.None;
string s = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.
FindExpression(i,text,0,0,out keyw);
if (s != null)
{
sb.Insert(0,s);
string tmp = s.TrimStart(' ','\n','\t','\r');
start_off = i-tmp.Length;
}
}
else
{
string s = sb.ToString().Trim(' ','\n','\t','\r');
if (string.Compare(s,"array",true)==0)
return "";
}
return sb.ToString();
}
示例6: RemoveMarker
public void RemoveMarker(IDocument doc)
{
try
{
if (oldMarker != null && doc != null && doc.TextLength >= oldMarker.Offset)
{
doc.MarkerStrategy.RemoveMarker(oldMarker);
doc.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine,doc.GetLineNumberForOffset(oldMarker.Offset)));
doc.CommitUpdate();
}
}
catch(System.Exception e)
{
}
}
示例7: SearchBracketBackward
public override int SearchBracketBackward(IDocument document, int offset, char openBracket, char closingBracket) {
int brackets = -1;
int lineStart = document.GetLineNumberForOffset(offset);
int openMultilineComments = 0;
// find the matching bracket if there is no string/comment in the way
for (int i = offset; i >= 0; i--) {
char ch = document.GetCharAt(i);
if (ch == openBracket) {
// Found a bracket, check if we are in a comment line
int testOffset = IsInCommentLine(document, i);
// nothing found, count bracket
if (testOffset < 0) {
brackets++;
if (brackets == 0)
return i;
} else {
i = testOffset;
}
} else if (ch == closingBracket) {
// Found a bracket, check if we are in a comment line
int testOffset = IsInCommentLine(document, i);
// nothing found, count bracket
if (testOffset < 0) {
brackets--;
} else {
i = testOffset;
}
} else if (ch == '"') {
// Tricky..
// We dont know, if this is start of a quote or end of it >.>
// Best thing we can do is check for next quote in the same line
int startOffset = i;
for (i--; i >= 0; i--) {
ch = document.GetCharAt(i);
if (ch == '"') {
// Found next quote in front of the last
// Now we can assume that the quote starts here
break;
} else if (ch == '\n') {
// We are 1 line before the quote.. and didnt found a previous quote
// Assume the found quote was the start of a string
// So just reset our iterator
i = startOffset;
break;
}
}
} else if (ch == '/' && i > 0) {
ch = document.GetCharAt(i - 1);
if (ch == '/') {
// Bracket is after a line comment, dont highlight
if (document.GetLineNumberForOffset(i) == lineStart) {
break;
}
// Reached start of line comment, nothing to do
i--;
} else if (ch == '*') {
// This means, we encounter a multiline comment end
// So skip everthing until comment start
for (i -= 2; i >= 0; i--) {
ch = document.GetCharAt(i);
if (ch == '*') {
if (i > 0 && document.GetCharAt(i - 1) == '/') {
break;
}
}
}
// End of text or comment
i--;
} else if ((i + 1) < document.TextLength && (ch = document.GetCharAt(i + 1)) == '*') {
// This means, we encounter the start of a multiline comment
// If we found a ENDING comment in a previous run, this is the start of it
// So the bracket is not IN this comment
if (openMultilineComments == 0) {
// The counter is 0, so we didnt found a ending comment yet
// this means, our bracket comes after the current multiline comment start
// and we dont highlight it
break;
}
// Yep we found a multiline start
openMultilineComments++;
}
} else if (ch == '*' && (i + 1) < document.TextLength) {
ch = document.GetCharAt(i + 1);
if (ch == '/') {
// This means, we encounter the end of a multiline comment
// So we have to find a start of it
openMultilineComments--;
}
}
}
return -1;
}
示例8: 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.TextContent, caretOffset);
if (result.Expression == null) {
// Try to find an expression to the left, but only
// in the same line.
if (foundStringLiteral || --caretOffset < 0 || document.GetLineNumberForOffset(caretOffset) != 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(new TextLocation(result.Region.BeginColumn - 1, result.Region.BeginLine - 1)) - 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.TextContent, ef, charTyped);
}
}
示例9: SetupDataProvider
public void SetupDataProvider(string fileName, TextArea textArea)
{
this.fileName = fileName;
this.document = textArea.Document;
this.textArea = textArea;
initialOffset = textArea.Caret.Offset;
string word = TextUtilities.GetExpressionBeforeOffset(textArea, textArea.Caret.Offset);
string methodObject = word;
// the parser works with 1 based coordinates
int caretLineNumber = document.GetLineNumberForOffset(textArea.Caret.Offset) + 1;
int caretColumn = textArea.Caret.Offset - document.GetLineSegment(caretLineNumber - 1).Offset + 1;
IParserService parserService = (IParserService)ServiceManager.Services.GetService(typeof(IParserService));
ResolveResult results = parserService.Resolve(methodObject,
caretLineNumber,
caretColumn,
fileName,
document.TextContent);
if (results != null && results.Type != null) {
foreach (IClass c in results.Type.ClassInheritanceTree) {
foreach (IIndexer indexer in c.Indexer) {
methods.Add(indexer);
}
}
foreach (object o in results.ResolveContents) {
if (o is IClass) {
foreach (IClass c in ((IClass)o).ClassInheritanceTree) {
foreach (IIndexer indexer in c.Indexer) {
methods.Add(indexer);
}
}
}
}
}
}
示例10: MarkTokens
// Mark document文档中的某些行.
public void MarkTokens(IDocument document, ArrayList Lines)
{
if (RuleSets.Count == 0) {
return;
}
Hashtable processedLines = new Hashtable();
bool spanChanged = false;
foreach (LineSegment lineToProcess in Lines) {
if (processedLines[lineToProcess] == null) {
int lineNumber = document.GetLineNumberForOffset(lineToProcess.Offset);
bool processNextLine = true;
if (lineNumber != -1) {
while (processNextLine && lineNumber < document.TotalNumberOfLines) {
if (lineNumber >= document.LineSegmentCollection.Count) { // may be, if the last line ends with a delimiter
break; // then the last line is not in the collection :)
}
processNextLine = MarkTokensInLine(document, lineNumber, ref spanChanged);
processedLines[currentLine] = String.Empty;
++lineNumber;
}
}
}
}
if (spanChanged) {
document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
} else {
foreach (LineSegment lineToProcess in Lines) {
document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(lineToProcess.Offset)));
}
}
document.OnUpdateCommited();
}
示例11: SetupDataProvider
public void SetupDataProvider(string fileName, TextArea textArea)
{
IDocument document = textArea.Document;
this.fileName = fileName;
this.document = document;
this.textArea = textArea;
initialOffset = textArea.Caret.Offset;
string word = TextUtilities.GetExpressionBeforeOffset(textArea, textArea.Caret.Offset);
string methodObject = word;
string methodName = null;
int idx = methodObject.LastIndexOf('.');
if (idx >= 0) {
methodName = methodObject.Substring(idx + 1);
methodObject = methodObject.Substring(0, idx);
} else {
methodObject = "this";
methodName = word;
}
if (methodName.Length == 0 || methodObject.Length == 0) {
return;
}
// the parser works with 1 based coordinates
caretLineNumber = document.GetLineNumberForOffset(textArea.Caret.Offset) + 1;
caretColumn = textArea.Caret.Offset - document.GetLineSegment(caretLineNumber).Offset + 1;
string[] words = word.Split(' ');
bool contructorInsight = false;
if (words.Length > 1) {
contructorInsight = words[words.Length - 2] == "new";
if (contructorInsight) {
methodObject = words[words.Length - 1];
}
}
IParserService parserService = (IParserService)ServiceManager.Services.GetService(typeof(IParserService));
ResolveResult results = parserService.Resolve(methodObject, caretLineNumber, caretColumn, fileName, document.TextContent);
if (results != null && results.Type != null) {
if (contructorInsight) {
AddConstructors(results.Type);
} else {
foreach (IClass c in results.Type.ClassInheritanceTree) {
AddMethods(c, methodName, false);
}
}
}
}