当前位置: 首页>>代码示例>>C#>>正文


C# ITextSnapshot.GetOpenDocumentInCurrentContextWithChanges方法代码示例

本文整理汇总了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);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:35,代码来源:LessAndGreaterThanCompletionSession.cs

示例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);
            }
        }
开发者ID:itowlson,项目名称:torment-roslyn,代码行数:14,代码来源:FieldShouldBeReadOnlyNagger.cs

示例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);
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:22,代码来源:LessAndGreaterThanCompletionSession.cs

示例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);
        }
开发者ID:fschneidereit,项目名称:VSEssentials,代码行数:8,代码来源:MultiLineCommentTaggerContext.cs

示例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;
        }
开发者ID:robinsedlaczek,项目名称:WaveDev.SensitiveCodeMarker,代码行数:60,代码来源:TextAdornment.cs

示例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);
        }
开发者ID:fschneidereit,项目名称:VSEssentials,代码行数:8,代码来源:SemanticFormatterContext.cs

示例7: GetSyntaxNodeFromTextSnapshot

 public SyntaxNode GetSyntaxNodeFromTextSnapshot(ITextSnapshot textSnapshot)
 {
     return textSnapshot.GetOpenDocumentInCurrentContextWithChanges().GetSyntaxRootAsync().Result;
 }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:4,代码来源:RoslynDocumentProvider.cs


注:本文中的ITextSnapshot.GetOpenDocumentInCurrentContextWithChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。