本文整理汇总了C#中ITextSnapshot.GetOpenDocumentInCurrentContextWithChanges方法的典型用法代码示例。如果您正苦于以下问题:C# ITextSnapshot.GetOpenDocumentInCurrentContextWithChanges方法的具体用法?C# ITextSnapshot.GetOpenDocumentInCurrentContextWithChanges怎么用?C# ITextSnapshot.GetOpenDocumentInCurrentContextWithChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextSnapshot
的用法示例。
在下文中一共展示了ITextSnapshot.GetOpenDocumentInCurrentContextWithChanges方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PossibleTypeArgument
private bool PossibleTypeArgument(ITextSnapshot snapshot, SyntaxToken token, CancellationToken cancellationToken)
{
var node = token.Parent as BinaryExpressionSyntax;
// type argument can be easily ambiguous with normal < operations
if (node == null || node.Kind() != SyntaxKind.LessThanExpression || node.OperatorToken != token)
{
return false;
}
// use binding to see whether it is actually generic type or method
var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document == null)
{
return false;
}
var model = document.GetSemanticModelAsync(cancellationToken).WaitAndGetResult(cancellationToken);
// Analyze node on the left of < operator to verify if it is a generic type or method.
var leftNode = node.Left;
if (leftNode is ConditionalAccessExpressionSyntax)
{
// If node on the left is a conditional access expression, get the member binding expression
// from the innermost conditional access expression, which is the left of < operator.
// e.g: Case a?.b?.c< : we need to get the conditional access expression .b?.c and analyze its
// member binding expression (the .c) to see if it is a generic type/method.
// Case a?.b?.c.d< : we need to analyze .c.d
// Case a?.M(x => x?.P)?.M2< : We need to analyze .M2
leftNode = leftNode.GetInnerMostConditionalAccessExpression().WhenNotNull;
}
var info = model.GetSymbolInfo(leftNode, cancellationToken);
return info.CandidateSymbols.Any(IsGenericTypeOrMethod);
}
示例2: UpdateFieldAdornments
internal async Task UpdateFieldAdornments(ITextSnapshot textSnapshot, IEnumerable<ITextViewLine> lines)
{
var workspace = this.view.TextBuffer.GetWorkspace();
var document = textSnapshot.GetOpenDocumentInCurrentContextWithChanges();
var semanticModel = await document.GetSemanticModelAsync();
var syntaxRoot = await document.GetSyntaxRootAsync();
var fields = syntaxRoot.DescendantNodes().OfType<FieldDeclarationSyntax>().SelectMany(f => f.Declaration.Variables).ToList();
var fieldsThatShouldBeReadOnly = fields.Where(f => ShouldBeReadOnly(f, semanticModel, workspace)).ToList();
foreach (ITextViewLine line in lines)
{
this.CreateVisuals(line, fields, fieldsThatShouldBeReadOnly);
}
}
示例3: PossibleTypeArgument
private bool PossibleTypeArgument(ITextSnapshot snapshot, SyntaxToken token, CancellationToken cancellationToken)
{
var node = token.Parent as BinaryExpressionSyntax;
// type argument can be easily ambiguous with normal < operations
if (node == null || node.Kind() != SyntaxKind.LessThanExpression || node.OperatorToken != token)
{
return false;
}
// use binding to see whether it is actually generic type or method
var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document == null)
{
return false;
}
var model = document.GetSemanticModelAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var info = model.GetSymbolInfo(node.Left, cancellationToken);
return info.CandidateSymbols.Any(IsGenericTypeOrMethod);
}
示例4: CreateAsync
public static async Task<MultiLineCommentTaggerContext> CreateAsync(ITextSnapshot snapshot)
{
var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
var semanticModel = await document.GetSemanticModelAsync();
var syntaxRoot = await document.GetSyntaxRootAsync();
return new MultiLineCommentTaggerContext(document, semanticModel, syntaxRoot, snapshot);
}
示例5: CollectSensitiveSyntaxNodes
private static IList<SyntaxNode> CollectSensitiveSyntaxNodes(ITextSnapshot newSnapshot)
{
var sensitiveSyntaxNodes = new List<SyntaxNode>();
// [RS] NuGet package Microsoft.CodeAnalysis.EditorFeatures.Text needed for method 'GetOpenDocumentInCurrentContextWithChanges'.
// There it is defined in Microsoft.CodeAnalysis.Text.
var currentDocument = newSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (currentDocument == null)
return sensitiveSyntaxNodes;
var trees = currentDocument.Project.Documents
.Select(document => document.GetSyntaxTreeAsync().Result)
.SkipWhile(syntaxTree => syntaxTree.Length == 0);
var references = new[]
{
MetadataReference.CreateFromFile(typeof(object).Assembly.CodeBase.Substring(8)),
MetadataReference.CreateFromFile(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Core.dll")
};
var compilation = CSharpCompilation
.Create("CodeInCurrentProject")
.AddReferences(references)
.AddSyntaxTrees(trees);
var tree = currentDocument.GetSyntaxTreeAsync().Result;
var semanticModel = compilation.GetSemanticModel(tree);
var treeRoot = tree.GetRoot() as CompilationUnitSyntax;
// [RS] Collect identifier names.
var identifiers = treeRoot.DescendantNodes().OfType<IdentifierNameSyntax>();
foreach (var identifier in identifiers)
{
if (identifier.IsVar)
continue;
var typeInfo = semanticModel.GetTypeInfo(identifier);
if (typeInfo.Type != null)
{
if (typeInfo.Type.AllInterfaces.Where(namedInterfaceType => namedInterfaceType.Name == "ISensitiveObject").Any())
sensitiveSyntaxNodes.Add(identifier);
}
else
{
var symbolInfo = semanticModel.GetSymbolInfo(identifier);
if (symbolInfo.Symbol != null)
{
var namedType = symbolInfo.Symbol as INamedTypeSymbol;
if (namedType != null && namedType.AllInterfaces.Where(namedInterfaceType => namedInterfaceType.Name == "ISensitiveObject").Any())
sensitiveSyntaxNodes.Add(identifier);
}
}
}
return sensitiveSyntaxNodes;
}
示例6: CreateAsync
public static async Task<SemanticFormatterContext> CreateAsync(ITextSnapshot snapshot)
{
var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
var semanticModel = await document.GetSemanticModelAsync().ConfigureAwait(false);
var syntaxRoot = await document.GetSyntaxRootAsync().ConfigureAwait(false);
return new SemanticFormatterContext(document, semanticModel, syntaxRoot, snapshot);
}
示例7: GetSyntaxNodeFromTextSnapshot
public SyntaxNode GetSyntaxNodeFromTextSnapshot(ITextSnapshot textSnapshot)
{
return textSnapshot.GetOpenDocumentInCurrentContextWithChanges().GetSyntaxRootAsync().Result;
}