Skip to content

Commit

Permalink
Merge pull request #287 from Vannevelj/issue286
Browse files Browse the repository at this point in the history
Fixed #286
  • Loading branch information
Vannevelj committed Oct 30, 2015
2 parents e1ae9cb + ed67533 commit e0abd91
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Rename;
using VSDiagnostics.Utilities;

namespace VSDiagnostics.Diagnostics.Async.AsyncMethodWithoutAsyncSuffix
{
Expand All @@ -30,22 +29,15 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)

context.RegisterCodeFix(
CodeAction.Create(VSDiagnosticsResources.AsyncMethodWithoutAsyncSuffixCodeFixTitle,
x => AddSuffixAsync(context.Document, methodDeclaration, context.CancellationToken),
x => AddSuffixAsync(context.Document, methodDeclaration, root, context.CancellationToken),
AsyncMethodWithoutAsyncSuffixAnalyzer.Rule.Id),
diagnostic);
}

private async Task<Solution> AddSuffixAsync(Document document, MethodDeclarationSyntax methodDeclaration,
private async Task<Solution> AddSuffixAsync(Document document, MethodDeclarationSyntax methodDeclaration, SyntaxNode root,
CancellationToken cancellationToken)
{
var methodSymbol =
(await document.GetSemanticModelAsync(cancellationToken)).GetDeclaredSymbol(methodDeclaration);
return await Renamer.RenameSymbolAsync(
document.Project.Solution,
methodSymbol,
methodDeclaration.Identifier.Text + "Async",
document.Project.Solution.Workspace.Options,
cancellationToken);
return await RenameHelper.RenameSymbolAsync(document, root, methodDeclaration.Identifier, methodDeclaration.Identifier.Text + "Async", cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Rename;
using VSDiagnostics.Utilities;

namespace VSDiagnostics.Diagnostics.General.NamingConventions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Rename;
using VSDiagnostics.Utilities;

namespace VSDiagnostics.Diagnostics.General.NamingConventions
Expand Down Expand Up @@ -85,15 +84,6 @@ identifierParent is EnumDeclarationSyntax ||
identifierParent = identifierParent.Parent;
} while (identifierParent != null);

//var newRoot = root.ReplaceToken(identifier, identifier.WithAdditionalAnnotations(RenameAnnotation.Create()));
//var newDocument = document.WithSyntaxRoot(newRoot);
//var semanticModel = await newDocument.GetSemanticModelAsync();
//var symbol = semanticModel.GetDeclaredSymbol(identifier.Parent);
//var solution = newDocument.Project.Solution;
//var options = solution.Workspace.Options;

//return await Renamer.RenameSymbolAsync(solution, symbol, newIdentifier.Text, options);

return
await RenameHelper.RenameSymbolAsync(document, root, identifier, newIdentifier.Text, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Rename;
using VSDiagnostics.Utilities;

namespace VSDiagnostics.Diagnostics.Tests.RemoveTestSuffix
{
Expand All @@ -30,21 +32,15 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)

context.RegisterCodeFix(
CodeAction.Create(VSDiagnosticsResources.RemoveTestSuffixCodeFixTitle,
x => RemoveTestSuffix(context.Document, root, methodDeclaration), RemoveTestSuffixAnalyzer.Rule.Id),
x => RemoveTestSuffix(context.Document, root, methodDeclaration, context.CancellationToken), RemoveTestSuffixAnalyzer.Rule.Id),
diagnostic);
}

private async Task<Solution> RemoveTestSuffix(Document document, SyntaxNode root,
MethodDeclarationSyntax methodDeclaration)
MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken)
{
var methodSymbol = (await document.GetSemanticModelAsync()).GetDeclaredSymbol(methodDeclaration);
var newMethodName = methodDeclaration.Identifier.Text.Remove(methodDeclaration.Identifier.Text.Length - 4);

return await Renamer.RenameSymbolAsync(
document.Project.Solution,
methodSymbol,
newMethodName,
document.Project.Solution.Workspace.Options);
return await RenameHelper.RenameSymbolAsync(document, root, methodDeclaration.Identifier, newMethodName, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Rename;

namespace VSDiagnostics.Utilities
Expand Down

0 comments on commit e0abd91

Please sign in to comment.