本文整理汇总了C#中Microsoft.CodeAnalysis.Text.SourceText类的典型用法代码示例。如果您正苦于以下问题:C# SourceText类的具体用法?C# SourceText怎么用?C# SourceText使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SourceText类属于Microsoft.CodeAnalysis.Text命名空间,在下文中一共展示了SourceText类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApiLine
internal ApiLine(string text, TextSpan span, SourceText sourceText, string path)
{
this.Text = text;
this.Span = span;
this.SourceText = sourceText;
this.Path = path;
}
示例2: SyntacticDocument
protected SyntacticDocument(Document document, SourceText text, SyntaxTree tree, SyntaxNode root)
{
this.Document = document;
this.Text = text;
this.SyntaxTree = tree;
this.Root = root;
}
示例3: Collapse
private TextChange Collapse(SourceText newText, List<TextChange> changes)
{
if (changes.Count == 0)
{
return new TextChange(new TextSpan(0, 0), "");
}
else if (changes.Count == 1)
{
return changes[0];
}
// The span we want to replace goes from the start of the first span to the end of
// the last span.
var totalOldSpan = TextSpan.FromBounds(changes.First().Span.Start, changes.Last().Span.End);
// We figure out the text we're replacing with by actually just figuring out the
// new span in the newText and grabbing the text out of that. The newSpan will
// start from the same position as the oldSpan, but it's length will be the old
// span's length + all the deltas we accumulate through each text change. i.e.
// if the first change adds 2 characters and the second change adds 4, then
// the newSpan will be 2+4=6 characters longer than the old span.
var sumOfDeltas = changes.Sum(c => c.NewText.Length - c.Span.Length);
var totalNewSpan = new TextSpan(totalOldSpan.Start, totalOldSpan.Length + sumOfDeltas);
return new TextChange(totalOldSpan, newText.ToString(totalNewSpan));
}
示例4: TestIsEmpty
private static void TestIsEmpty(SourceText text)
{
Assert.Equal(0, text.Length);
Assert.Same(string.Empty, text.ToString());
Assert.Equal(1, text.Lines.Count);
Assert.Equal(0, text.Lines[0].Span.Length);
}
示例5: GetWordSpan
public static TextSpan GetWordSpan(SourceText text, int position,
Func<char, bool> isWordStartCharacter, Func<char, bool> isWordCharacter)
{
int start = position;
while (start > 0 && isWordStartCharacter(text[start - 1]))
{
start--;
}
// If we're brought up in the middle of a word, extend to the end of the word as well.
// This means that if a user brings up the completion list at the start of the word they
// will "insert" the text before what's already there (useful for qualifying existing
// text). However, if they bring up completion in the "middle" of a word, then they will
// "overwrite" the text. Useful for correcting misspellings or just replacing unwanted
// code with new code.
int end = position;
if (start != position)
{
while (end < text.Length && isWordCharacter(text[end]))
{
end++;
}
}
return TextSpan.FromBounds(start, end);
}
示例6: GetStartAndLengthOfLineBreakEndingAt
/// <summary>
/// Return startLineBreak = index-1, lengthLineBreak = 2 if there is a \r\n at index-1
/// Return startLineBreak = index, lengthLineBreak = 1 if there is a 1-char newline at index
/// Return startLineBreak = index+1, lengthLineBreak = 0 if there is no newline at index.
/// </summary>
public static void GetStartAndLengthOfLineBreakEndingAt(SourceText text, int index, out int startLinebreak, out int lengthLinebreak)
{
char c = text[index];
if (c == '\n')
{
if (index > 0 && text[index - 1] == '\r')
{
// "\r\n" is the only 2-character line break.
startLinebreak = index - 1;
lengthLinebreak = 2;
}
else
{
startLinebreak = index;
lengthLinebreak = 1;
}
}
else if (IsAnyLineBreakCharacter(c))
{
startLinebreak = index;
lengthLinebreak = 1;
}
else
{
startLinebreak = index + 1;
lengthLinebreak = 0;
}
}
示例7: GetCommentChangesForDocument
private List<TextChange> GetCommentChangesForDocument(IEnumerable<IEnumerable<TextChange>> partitionedChanges, string projectName, SourceText oldDocumentText, SourceText newDocumentText)
{
var commentChanges = new List<TextChange>();
foreach (var changePartition in partitionedChanges)
{
var startPosition = changePartition.First().Span.Start;
var endPosition = changePartition.Last().Span.End;
var startLineStartPosition = oldDocumentText.Lines.GetLineFromPosition(startPosition).Start;
var endLineEndPosition = oldDocumentText.Lines.GetLineFromPosition(endPosition).End;
var oldText = oldDocumentText.GetSubText(TextSpan.FromBounds(startLineStartPosition, endLineEndPosition));
var adjustedChanges = changePartition.Select(c => new TextChange(TextSpan.FromBounds(c.Span.Start - startLineStartPosition, c.Span.End - startLineStartPosition), c.NewText));
var newText = oldText.WithChanges(adjustedChanges);
var warningText = GetConflictCommentText(
string.Format(WorkspacesResources.UnmergedChangeFromProject, projectName),
TrimBlankLines(oldText),
TrimBlankLines(newText));
if (warningText != null)
{
commentChanges.Add(new TextChange(TextSpan.FromBounds(startLineStartPosition, startLineStartPosition), warningText));
}
}
return commentChanges;
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:29,代码来源:AbstractLinkedFileMergeConflictCommentAdditionService.cs
示例8: FillGaps
private static IEnumerable<Range> FillGaps(SourceText text, IEnumerable<Range> ranges)
{
const string WhitespaceClassification = null;
int current = 0;
Range previous = null;
foreach (Range range in ranges)
{
int start = range.TextSpan.Start;
if (start > current)
{
yield return new Range(WhitespaceClassification, TextSpan.FromBounds(current, start), text);
}
if (previous == null || range.TextSpan != previous.TextSpan)
{
yield return range;
}
previous = range;
current = range.TextSpan.End;
}
if (current < text.Length)
{
yield return new Range(WhitespaceClassification, TextSpan.FromBounds(current, text.Length), text);
}
}
示例9: ConvertClassifications
private static List<SymbolDisplayPart> ConvertClassifications(
SourceText sourceText, int startPosition, IEnumerable<ClassifiedSpan> classifiedSpans, bool insertSourceTextInGaps = false)
{
var parts = new List<SymbolDisplayPart>();
foreach (var span in classifiedSpans)
{
// If there is space between this span and the last one, then add a space.
if (startPosition != span.TextSpan.Start)
{
if (insertSourceTextInGaps)
{
parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Text, null,
sourceText.ToString(TextSpan.FromBounds(
startPosition, span.TextSpan.Start))));
}
else
{
parts.AddRange(Space());
}
}
var kind = GetClassificationKind(span.ClassificationType);
if (kind != null)
{
parts.Add(new SymbolDisplayPart(kind.Value, null, sourceText.ToString(span.TextSpan)));
startPosition = span.TextSpan.End;
}
}
return parts;
}
示例10: PartitionChangesForDocument
private IEnumerable<IEnumerable<TextChange>> PartitionChangesForDocument(IEnumerable<TextChange> changes, SourceText originalSourceText)
{
var partitionedChanges = new List<IEnumerable<TextChange>>();
var currentPartition = new List<TextChange>();
currentPartition.Add(changes.First());
var currentPartitionEndLine = originalSourceText.Lines.GetLineFromPosition(changes.First().Span.End);
foreach (var change in changes.Skip(1))
{
// If changes are on adjacent lines, consider them part of the same change.
var changeStartLine = originalSourceText.Lines.GetLineFromPosition(change.Span.Start);
if (changeStartLine.LineNumber >= currentPartitionEndLine.LineNumber + 2)
{
partitionedChanges.Add(currentPartition);
currentPartition = new List<TextChange>();
}
currentPartition.Add(change);
currentPartitionEndLine = originalSourceText.Lines.GetLineFromPosition(change.Span.End);
}
if (currentPartition.Any())
{
partitionedChanges.Add(currentPartition);
}
return partitionedChanges;
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:29,代码来源:AbstractLinkedFileMergeConflictCommentAdditionService.cs
示例11: UpdateText
public void UpdateText(SourceText newText)
{
_updatding = true;
_editor.Document.BeginUpdate();
try
{
var changes = newText.GetTextChanges(_currentText);
var offset = 0;
foreach (var change in changes)
{
_editor.Document.Replace(change.Span.Start + offset, change.Span.Length, new StringTextSource(change.NewText));
offset += change.NewText.Length - change.Span.Length;
}
_currentText = newText;
}
finally
{
_updatding = false;
_editor.Document.EndUpdate();
}
}
示例12: AvalonEditTextContainer
public AvalonEditTextContainer(TextEditor editor)
{
_editor = editor;
_currentText = SourceText.From(_editor.Text);
_editor.Document.Changed += DocumentOnChanged;
}
示例13: AddAdditionalDocumentUndoUnit
public AddAdditionalDocumentUndoUnit(
VisualStudioWorkspaceImpl workspace,
DocumentInfo docInfo,
SourceText text)
: base(workspace, docInfo, text)
{
}
示例14: ConvertClassifications
private static List<SymbolDisplayPart> ConvertClassifications(
SourceText sourceText, IEnumerable<ClassifiedSpan> classifiedSpans)
{
var parts = new List<SymbolDisplayPart>();
ClassifiedSpan? lastSpan = null;
foreach (var span in classifiedSpans)
{
// If there is space between this span and the last one, then add a space.
if (lastSpan != null && lastSpan.Value.TextSpan.End != span.TextSpan.Start)
{
parts.AddRange(Space());
}
var kind = GetClassificationKind(span.ClassificationType);
if (kind != null)
{
parts.Add(new SymbolDisplayPart(kind.Value, null, sourceText.ToString(span.TextSpan)));
lastSpan = span;
}
}
return parts;
}
示例15: Create
public static StringSplitter Create(
Document document, int position,
SyntaxTree syntaxTree, SyntaxNode root, SourceText sourceText,
bool useTabs, int tabSize, CancellationToken cancellationToken)
{
var token = root.FindToken(position);
if (token.IsKind(SyntaxKind.StringLiteralToken))
{
return new SimpleStringSplitter(
document, position, syntaxTree, root,
sourceText, token, useTabs, tabSize,
cancellationToken);
}
var interpolatedStringExpression = TryGetInterpolatedStringExpression(token, position);
if (interpolatedStringExpression != null)
{
return new InterpolatedStringSplitter(
document, position, syntaxTree, root,
sourceText, interpolatedStringExpression,
useTabs, tabSize, cancellationToken);
}
return null;
}