private async Task <Document> Execute(Document document, MemberDeclarationSyntax membDecl, CancellationToken cancellationToken) { // Get the symbol representing the type to be renamed. var semanticModel = await document.GetSemanticModelAsync(cancellationToken); var memberSymbol = semanticModel.GetDeclaredSymbol(membDecl, cancellationToken); PullThroughInfo pullThroughInfo = new PullThroughInfo(memberSymbol, cancellationToken); if (!pullThroughInfo.SupportsPullingThroughDoc()) { return(document); } // Just use the first syntax reference because who cares at this point IEnumerable <SyntaxTrivia> trivia = GetTriviaFromMember(pullThroughInfo, membDecl); MemberDeclarationSyntax newMembDecl = membDecl.WithLeadingTrivia(trivia); // Produce a new document SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken); SyntaxNode other = root.ReplaceNode(membDecl, newMembDecl); return(document.WithSyntaxRoot(other)); }
private static void AnalyzeSymbol(SymbolAnalysisContext context) { PullThroughInfo pullThroughInfo = new PullThroughInfo( context.Symbol, context.CancellationToken ); // Check if we can pull through the doc if (pullThroughInfo.SupportsPullingThroughDoc() && pullThroughInfo.HasBaseSummaryDocumentation()) { DiagnosticDescriptor diagDesc = null; if (!pullThroughInfo.HasDocComments()) { diagDesc = s_pullThroughDocRule; } else if (pullThroughInfo.SuggestReplaceWithInheritDoc()) { diagDesc = s_swapToInheritDocRule; } else if (pullThroughInfo.SuggestReplaceWithPullThroughDoc()) { diagDesc = s_swapToPullThroughDocRule; } if (diagDesc != null) { var diagnostic = Diagnostic.Create(diagDesc, context.Symbol.Locations[0], context.Symbol.Name); context.ReportDiagnostic(diagnostic); } } }
protected override IEnumerable <SyntaxTrivia> GetTriviaFromMember(PullThroughInfo pullThroughInfo, SyntaxNode targetMember) { IEnumerable <SyntaxTrivia> leadingTrivia = targetMember.GetLeadingTrivia(); SyntaxTrivia indentWhitespace = leadingTrivia.GetIndentation(); leadingTrivia = CollapseWhitespace(leadingTrivia.Where(t => !t.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia))); var triviaList = SyntaxFactory.ParseLeadingTrivia("/// <inheritdoc/>"); return(leadingTrivia .Concat(triviaList) .Concat(new [] { SyntaxFactory.CarriageReturnLineFeed }) .Concat(new[] { indentWhitespace })); }
protected override IEnumerable <SyntaxTrivia> GetTriviaFromMember(PullThroughInfo pullThroughInfo, SyntaxNode targetMember) { IEnumerable <SyntaxTrivia> leadingTrivia = targetMember.GetLeadingTrivia(); var indentWhitespace = leadingTrivia.GetIndentation(); leadingTrivia = CollapseWhitespace(leadingTrivia.Where(t => !t.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia))); // Grab only the doc comment trivia. Seems to include a line break at the end IEnumerable <SyntaxTrivia> nonRegion = pullThroughInfo.GetBaseMemberTrivia() .Where(tr => tr.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia)) .ToList(); return(leadingTrivia .Concat(nonRegion) .Concat(new[] { indentWhitespace })); }
protected abstract IEnumerable <SyntaxTrivia> GetTriviaFromMember(PullThroughInfo pullThroughInfo, SyntaxNode targetMember);