本文整理汇总了C#中SyntaxTree.GetLocation方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTree.GetLocation方法的具体用法?C# SyntaxTree.GetLocation怎么用?C# SyntaxTree.GetLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxTree
的用法示例。
在下文中一共展示了SyntaxTree.GetLocation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateClassificationDiagnostics
// Create one diagnostic for each unnecessary span that will be classified as Unnecessary
private IEnumerable<Diagnostic> CreateClassificationDiagnostics(IEnumerable<TextSpan> contiguousSpans, SyntaxTree tree, CancellationToken cancellationToken = default(CancellationToken))
{
foreach (var span in contiguousSpans)
{
if (tree.OverlapsHiddenPosition(span, cancellationToken))
{
continue;
}
yield return Diagnostic.Create(s_classificationIdDescriptor, tree.GetLocation(span));
}
}
示例2: CreateItem
private ITaskItem CreateItem(Document document, SourceText text, SyntaxTree tree, TodoComment comment)
{
var textSpan = new TextSpan(comment.Position, 0);
var location = tree == null ? Location.Create(document.FilePath, textSpan, text.Lines.GetLinePositionSpan(textSpan)) : tree.GetLocation(textSpan);
var originalLineInfo = location.GetLineSpan();
var mappedLineInfo = location.GetMappedLineSpan();
return new TodoTaskItem(
comment.Descriptor.Priority,
comment.Message,
document.Project.Solution.Workspace,
document.Id,
mappedLine: mappedLineInfo.StartLinePosition.Line,
originalLine: originalLineInfo.StartLinePosition.Line,
mappedColumn: mappedLineInfo.StartLinePosition.Character,
originalColumn: originalLineInfo.StartLinePosition.Character,
mappedFilePath: mappedLineInfo.HasMappedPath ? mappedLineInfo.Path : null,
originalFilePath: document.FilePath);
}
示例3: GetDiagnostic
internal async Task<IEnumerable<Diagnostic>> GetDiagnostic(SyntaxTree tree, DiagnosticDescriptor diagnosticDescriptor, CancellationToken cancellationToken)
{
try
{
// This can be called on a background thread. We are being asked whether a
// lightbulb should be shown for the given document, but we only know about the
// current state of the buffer. Compare the text to see if we should bail early.
// Even if the text is the same, the buffer may change on the UI thread during this
// method. If it does, we may give an incorrect response, but the diagnostics
// engine will know that the document changed and not display the lightbulb anyway.
if (Buffer.AsTextContainer().CurrentText != await tree.GetTextAsync(cancellationToken).ConfigureAwait(false))
{
return SpecializedCollections.EmptyEnumerable<Diagnostic>();
}
TrackingSession trackingSession;
if (CanInvokeRename(out trackingSession, waitForResult: true, cancellationToken: cancellationToken))
{
SnapshotSpan snapshotSpan = trackingSession.TrackingSpan.GetSpan(Buffer.CurrentSnapshot);
var textSpan = snapshotSpan.Span.ToTextSpan();
var builder = ImmutableDictionary.CreateBuilder<string, string>();
builder.Add(RenameTrackingDiagnosticAnalyzer.RenameFromPropertyKey, trackingSession.OriginalName);
builder.Add(RenameTrackingDiagnosticAnalyzer.RenameToPropertyKey, snapshotSpan.GetText());
var properties = builder.ToImmutable();
var diagnostic = Diagnostic.Create(diagnosticDescriptor,
tree.GetLocation(textSpan),
properties);
return SpecializedCollections.SingletonEnumerable(diagnostic);
}
return SpecializedCollections.EmptyEnumerable<Diagnostic>();
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
示例4: AddLocationsToRenameInStringsAndComments
private static void AddLocationsToRenameInStringsAndComments(
Document document,
SyntaxTree tree,
string renameText,
IEnumerable<Tuple<string, int, TextSpan>> renameStringsAndPositions,
List<RenameLocation> renameLocations,
bool isRenameInStrings,
bool isRenameInComments)
{
var regex = GetRegexForMatch(renameText);
foreach (var renameStringAndPosition in renameStringsAndPositions)
{
string renameString = renameStringAndPosition.Item1;
int renameStringPosition = renameStringAndPosition.Item2;
var containingSpan = renameStringAndPosition.Item3;
MatchCollection matches = regex.Matches(renameString);
foreach (Match match in matches)
{
int start = renameStringPosition + match.Index;
Debug.Assert(renameText.Length == match.Length);
var matchTextSpan = new TextSpan(start, renameText.Length);
var matchLocation = tree.GetLocation(matchTextSpan);
var renameLocation = new RenameLocation(matchLocation, document.Id, containingLocationForStringOrComment: containingSpan);
renameLocations.Add(renameLocation);
}
}
}
示例5: CreateFixableDiagnostics
private IEnumerable<Diagnostic> CreateFixableDiagnostics(IEnumerable<SyntaxNode> nodes, SyntaxTree tree, CancellationToken cancellationToken = default(CancellationToken))
{
var spans = GetFixableDiagnosticSpans(nodes, tree, cancellationToken);
foreach (var span in spans)
{
yield return Diagnostic.Create(s_fixableIdDescriptor, tree.GetLocation(span));
}
}
示例6: ToDiagnostic
internal Diagnostic ToDiagnostic(SyntaxTree tree)
{
var descriptor = RudeEditDiagnosticDescriptors.GetDescriptor(this.Kind);
return Diagnostic.Create(descriptor, tree.GetLocation(this.Span), Arguments);
}
示例7: ToDiagnostic
public Diagnostic ToDiagnostic(SyntaxTree tree)
{
var location = Location.None;
if (tree != null)
{
var span = _textSpan.HasValue ? _textSpan.Value : GetTextSpan(tree.GetText());
location = tree.GetLocation(span);
}
else if (OriginalFilePath != null && _textSpan != null)
{
var span = _textSpan.Value;
location = Location.Create(OriginalFilePath, span, new LinePositionSpan(
new LinePosition(OriginalStartLine, OriginalStartColumn),
new LinePosition(OriginalEndLine, OriginalEndColumn)));
}
return Diagnostic.Create(this.Id, this.Category, this.Message, this.Severity, this.DefaultSeverity, this.IsEnabledByDefault, this.WarningLevel, this.Title, this.Description, this.HelpLink, location, customTags: this.CustomTags, properties: this.Properties);
}
示例8: CreateItem
private TodoItem CreateItem(Document document, SourceText text, SyntaxTree tree, TodoComment comment)
{
// make sure given position is within valid text range.
var textSpan = new TextSpan(Math.Min(text.Length, Math.Max(0, comment.Position)), 0);
var location = tree == null ? Location.Create(document.FilePath, textSpan, text.Lines.GetLinePositionSpan(textSpan)) : tree.GetLocation(textSpan);
var originalLineInfo = location.GetLineSpan();
var mappedLineInfo = location.GetMappedLineSpan();
return new TodoItem(
comment.Descriptor.Priority,
comment.Message,
document.Project.Solution.Workspace,
document.Id,
mappedLine: mappedLineInfo.StartLinePosition.Line,
originalLine: originalLineInfo.StartLinePosition.Line,
mappedColumn: mappedLineInfo.StartLinePosition.Character,
originalColumn: originalLineInfo.StartLinePosition.Character,
mappedFilePath: mappedLineInfo.GetMappedFilePathIfExist(),
originalFilePath: document.FilePath);
}
示例9: ToDiagnostic
public Diagnostic ToDiagnostic(SyntaxTree tree)
{
var location = Location.None;
if (tree != null)
{
var span = _textSpan.HasValue ? _textSpan.Value : GetTextSpan(tree.GetText());
location = tree.GetLocation(span);
}
return Diagnostic.Create(this.Id, this.Category, this.Message, this.Severity, this.DefaultSeverity, this.IsEnabledByDefault, this.WarningLevel, this.Title, this.Description, this.HelpLink, location, customTags: this.CustomTags);
}