コード例 #1
0
        protected override SyntaxNode AddGlobalSuppressMessageAttribute(
            SyntaxNode newRoot,
            ISymbol targetSymbol,
            INamedTypeSymbol suppressMessageAttribute,
            Diagnostic diagnostic,
            HostSolutionServices services,
            SyntaxFormattingOptions options,
            IAddImportsService addImportsService,
            CancellationToken cancellationToken)
        {
            var compilationRoot = (CompilationUnitSyntax)newRoot;
            var isFirst         = !compilationRoot.AttributeLists.Any();

            var attributeName = suppressMessageAttribute.GenerateNameSyntax()
                                .WithAdditionalAnnotations(Simplifier.AddImportsAnnotation);

            compilationRoot = compilationRoot.AddAttributeLists(
                CreateAttributeList(
                    targetSymbol,
                    attributeName,
                    diagnostic,
                    isAssemblyAttribute: true,
                    leadingTrivia: default));

            if (isFirst && !newRoot.HasLeadingTrivia)
            {
                compilationRoot = compilationRoot.WithLeadingTrivia(SyntaxFactory.Comment(GlobalSuppressionsFileHeaderComment));
            }

            return(compilationRoot);
        }
コード例 #2
0
 public static Func <CancellationToken, Task <CompletionDescription> > CreateDescriptionFactory(
     HostSolutionServices workspaceServices,
     SemanticModel semanticModel,
     int position,
     ISymbol symbol,
     SymbolDescriptionOptions options)
 {
     return(CreateDescriptionFactory(workspaceServices, semanticModel, position, options, new[] { symbol }));
 }
コード例 #3
0
        public static Task <CompletionDescription> CreateDescriptionAsync(
            HostSolutionServices workspaceServices, SemanticModel semanticModel, int position, IReadOnlyList <ISymbol> symbols, SymbolDescriptionOptions options, SupportedPlatformData?supportedPlatforms, CancellationToken cancellationToken)
        {
            // Lets try to find the first non-obsolete symbol (overload) and fall-back
            // to the first symbol if all are obsolete.
            var symbol = symbols.FirstOrDefault(s => !s.IsObsolete()) ?? symbols[0];

            return(CreateDescriptionAsync(workspaceServices, semanticModel, position, symbol, overloadCount: symbols.Count - 1, options, supportedPlatforms, cancellationToken));
        }
コード例 #4
0
 protected abstract SyntaxNode AddGlobalSuppressMessageAttribute(
     SyntaxNode newRoot,
     ISymbol targetSymbol,
     INamedTypeSymbol suppressMessageAttribute,
     Diagnostic diagnostic,
     HostSolutionServices services,
     SyntaxFormattingOptions options,
     IAddImportsService addImportsService,
     CancellationToken cancellationToken);
 public SymbolDescriptionBuilder(
     SemanticModel semanticModel,
     int position,
     HostSolutionServices services,
     IStructuralTypeDisplayService structuralTypeDisplayService,
     SymbolDescriptionOptions options,
     CancellationToken cancellationToken)
     : base(semanticModel, position, services, structuralTypeDisplayService, options, cancellationToken)
 {
 }
コード例 #6
0
 public CommonQuickInfoContext(
     HostSolutionServices services,
     SemanticModel semanticModel,
     int position,
     SymbolDescriptionOptions options,
     CancellationToken cancellationToken)
 {
     Services          = services;
     SemanticModel     = semanticModel;
     Position          = position;
     Options           = options;
     CancellationToken = cancellationToken;
 }
コード例 #7
0
        private static SyntaxNode ReplaceAnonymousWithLocalFunction(
            HostSolutionServices services, SyntaxNode currentRoot,
            LocalDeclarationStatementSyntax localDeclaration, AnonymousFunctionExpressionSyntax anonymousFunction,
            IMethodSymbol delegateMethod, ParameterListSyntax parameterList, bool makeStatic)
        {
            var newLocalFunctionStatement = CreateLocalFunctionStatement(localDeclaration, anonymousFunction, delegateMethod, parameterList, makeStatic)
                                            .WithTriviaFrom(localDeclaration)
                                            .WithAdditionalAnnotations(Formatter.Annotation);

            var editor = new SyntaxEditor(currentRoot, services);

            editor.ReplaceNode(localDeclaration, newLocalFunctionStatement);

            var anonymousFunctionStatement = anonymousFunction.GetAncestor <StatementSyntax>();

            if (anonymousFunctionStatement != localDeclaration)
            {
                // This is the split decl+init form.  Remove the second statement as we're
                // merging into the first one.
                editor.RemoveNode(anonymousFunctionStatement);
            }

            return(editor.GetChangedRoot());
        }
コード例 #8
0
        public static async Task <QuickInfoItem> CreateQuickInfoItemAsync(
            HostSolutionServices services,
            SemanticModel semanticModel,
            TextSpan span,
            ImmutableArray <ISymbol> symbols,
            SupportedPlatformData?supportedPlatforms,
            bool showAwaitReturn,
            NullableFlowState flowState,
            SymbolDescriptionOptions options,
            CancellationToken cancellationToken)
        {
            var descriptionService = services.GetRequiredLanguageService <ISymbolDisplayService>(semanticModel.Language);
            var groups             = await descriptionService.ToDescriptionGroupsAsync(semanticModel, span.Start, symbols, options, cancellationToken).ConfigureAwait(false);

            using var _1 = ArrayBuilder <QuickInfoSection> .GetInstance(out var sections);

            var symbol = symbols.First();

            if (showAwaitReturn)
            {
                // We show a special message if the Task being awaited has no return
                if (symbol is INamedTypeSymbol {
                    SpecialType : SpecialType.System_Void
                })
コード例 #9
0
 public static Func <CancellationToken, Task <CompletionDescription> > CreateDescriptionFactory(
     HostSolutionServices workspaceServices, SemanticModel semanticModel, int position, SymbolDescriptionOptions options, IReadOnlyList <ISymbol> symbols)
 {
     return(c => CreateDescriptionAsync(workspaceServices, semanticModel, position, symbols, options, supportedPlatforms: null, cancellationToken: c));
 }
コード例 #10
0
        public static async Task <CompletionDescription> CreateDescriptionAsync(
            HostSolutionServices workspaceServices, SemanticModel semanticModel, int position, ISymbol symbol, int overloadCount, SymbolDescriptionOptions options, SupportedPlatformData?supportedPlatforms, CancellationToken cancellationToken)
        {
            var symbolDisplayService = workspaceServices.GetRequiredLanguageService <ISymbolDisplayService>(semanticModel.Language);
            var formatter            = workspaceServices.GetRequiredLanguageService <IDocumentationCommentFormattingService>(semanticModel.Language);

            // TODO(cyrusn): Figure out a way to cancel this.
            var sections = await symbolDisplayService.ToDescriptionGroupsAsync(semanticModel, position, ImmutableArray.Create(symbol), options, cancellationToken).ConfigureAwait(false);

            if (!sections.ContainsKey(SymbolDescriptionGroups.MainDescription))
            {
                return(CompletionDescription.Empty);
            }

            var textContentBuilder = new List <TaggedText>();

            textContentBuilder.AddRange(sections[SymbolDescriptionGroups.MainDescription]);

            switch (symbol.Kind)
            {
            case SymbolKind.Method:
            case SymbolKind.Property:
            case SymbolKind.NamedType:
                if (overloadCount > 0)
                {
                    var isGeneric = symbol.GetArity() > 0;

                    textContentBuilder.AddSpace();
                    textContentBuilder.AddPunctuation("(");
                    textContentBuilder.AddPunctuation("+");
                    textContentBuilder.AddText(NonBreakingSpaceString + overloadCount.ToString());

                    AddOverloadPart(textContentBuilder, overloadCount, isGeneric);

                    textContentBuilder.AddPunctuation(")");
                }

                break;
            }

            AddDocumentationPart(textContentBuilder, symbol, semanticModel, position, formatter, cancellationToken);

            if (sections.TryGetValue(SymbolDescriptionGroups.AwaitableUsageText, out var parts))
            {
                textContentBuilder.AddRange(parts);
            }

            if (sections.TryGetValue(SymbolDescriptionGroups.StructuralTypes, out parts))
            {
                if (!parts.IsDefaultOrEmpty)
                {
                    textContentBuilder.AddLineBreak();
                    textContentBuilder.AddLineBreak();
                    textContentBuilder.AddRange(parts);
                }
            }

            if (supportedPlatforms != null)
            {
                textContentBuilder.AddLineBreak();
                textContentBuilder.AddRange(supportedPlatforms.ToDisplayParts().ToTaggedText());
            }

            return(CompletionDescription.Create(textContentBuilder.AsImmutable()));
        }
コード例 #11
0
 public static Task <QuickInfoItem> CreateQuickInfoItemAsync(HostSolutionServices services, SemanticModel semanticModel, TextSpan span, ImmutableArray <ISymbol> symbols, SymbolDescriptionOptions options, CancellationToken cancellationToken)
 => CreateQuickInfoItemAsync(services, semanticModel, span, symbols, supportedPlatforms: null, showAwaitReturn: false, flowState: NullableFlowState.None, options, cancellationToken);