-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5bd432
commit c6b05a9
Showing
13 changed files
with
768 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
################################################################################ | ||
# This .gitignore file was automatically created by Microsoft(R) Visual Studio. | ||
################################################################################ | ||
|
||
/.localhistory/* | ||
/.vs/* | ||
*/obj/* | ||
*/bin/* | ||
*.user | ||
/packages | ||
*.nupkg |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.572 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resharper.QuickActions", "Resharper.QuickActions\Resharper.QuickActions.csproj", "{C472A182-29CD-4733-B556-C8364E5AC780}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C472A182-29CD-4733-B556-C8364E5AC780}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C472A182-29CD-4733-B556-C8364E5AC780}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C472A182-29CD-4733-B556-C8364E5AC780}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C472A182-29CD-4733-B556-C8364E5AC780}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{D38986F0-68FF-4D86-B1E6-115D2BFEDC0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D38986F0-68FF-4D86-B1E6-115D2BFEDC0F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D38986F0-68FF-4D86-B1E6-115D2BFEDC0F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D38986F0-68FF-4D86-B1E6-115D2BFEDC0F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {3F3538DF-5EC3-478D-B357-AEF3050F312A} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using JetBrains.Application.Progress; | ||
using JetBrains.ProjectModel; | ||
using JetBrains.ReSharper.Feature.Services.ContextActions; | ||
using JetBrains.ReSharper.Feature.Services.CSharp.Analyses.Bulbs; | ||
using JetBrains.ReSharper.Psi.CSharp.Tree; | ||
using JetBrains.TextControl; | ||
using JetBrains.Util; | ||
using Resharper.QuickActions.Helpers; | ||
using Resharper.QuickActions.Models; | ||
|
||
namespace Resharper.QuickActions.Actions | ||
{ | ||
[ContextAction(Name = Constants.PluginName, Description = "Clones selected method", Group = "C#")] | ||
public class CloneMethod : ContextActionBase | ||
{ | ||
readonly ICSharpContextActionDataProvider _provider; | ||
|
||
ActionContext Context => _provider.GetActionContext(); | ||
|
||
public CloneMethod(ICSharpContextActionDataProvider provider) | ||
{ | ||
_provider = provider; | ||
} | ||
|
||
/// <summary> | ||
/// Popup menu item text | ||
/// </summary> | ||
public override string Text => Constants.PluginName; | ||
|
||
public override bool IsAvailable(IUserDataHolder bag) | ||
{ | ||
return Context != null; | ||
} | ||
|
||
protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) | ||
{ | ||
var context = Context; | ||
if (context == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var code = context.Method.GetText(); | ||
if (string.IsNullOrEmpty(code)) | ||
{ | ||
return null; | ||
} | ||
|
||
var typeMember = _provider.ElementFactory.CreateTypeMemberDeclaration(code); | ||
|
||
var classDeclaration = context.ContainingType as IClassLikeDeclaration; | ||
if (classDeclaration == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var memberDeclaration = typeMember as IClassMemberDeclaration; | ||
Debug.Assert(memberDeclaration != null, "memberDeclaration != null"); | ||
|
||
var result = classDeclaration.AddClassMemberDeclarationBefore(memberDeclaration, context.Method); | ||
|
||
result.Format(); | ||
|
||
return null; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Resharper.QuickActions/CI/NuGet/Resharper.QuickActions.nuspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<package > | ||
<metadata> | ||
<id>Resharper.QuickActions</id> | ||
<version>1.0.0</version> | ||
<title>Quick actions</title> | ||
<authors>Ruslan Mogilevskiy</authors> | ||
<copyright>(c) Ruslan Mogilevskiy</copyright> | ||
<description>Useful and quick context actions: Clone method</description> | ||
<projectUrl>https://github.com/ruslanmogilevskiy/Resharper.QuickActions</projectUrl> | ||
<tags>Context Actions</tags> | ||
<dependencies> | ||
<dependency id="Wave" version="8.0" /> | ||
</dependencies> | ||
</metadata> | ||
<files> | ||
<file src="..\..\bin\debug\Resharper.QuickActions.dll" target="DotFiles" /> | ||
<file src="..\..\bin\debug\Resharper.QuickActions.pdb" target="DotFiles" /> | ||
</files> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
..\..\..\CI\nuget pack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Resharper.QuickActions | ||
{ | ||
public static class Constants | ||
{ | ||
public const string PluginName = "Clone method"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using JetBrains.Application.Progress; | ||
using JetBrains.DocumentManagers; | ||
using JetBrains.DocumentModel; | ||
using JetBrains.ReSharper.Psi; | ||
using JetBrains.ReSharper.Psi.CodeStyle; | ||
using JetBrains.ReSharper.Psi.CSharp.CodeStyle; | ||
using JetBrains.ReSharper.Psi.Tree; | ||
|
||
namespace Resharper.QuickActions.Helpers | ||
{ | ||
public static class FormatExtensions | ||
{ | ||
/// <summary> | ||
/// The format body. | ||
/// </summary> | ||
/// <param name="statement">The body.</param> | ||
public static void Format(this ITreeNode statement) | ||
{ | ||
if (!statement.IsPhysical()) | ||
{ | ||
return; | ||
} | ||
|
||
var documentRange = statement.GetDocumentRange(); | ||
if (!documentRange.IsValid()) | ||
{ | ||
return; | ||
} | ||
|
||
var containingFile = statement.GetContainingFile(); | ||
var psiSourceFile = containingFile?.GetSourceFile(); | ||
if (psiSourceFile == null) | ||
{ | ||
return; | ||
} | ||
|
||
var document = psiSourceFile.Document; | ||
var solution = statement.GetPsiServices().Solution; | ||
|
||
var languageService = statement.Language.LanguageService(); | ||
var codeFormatter = languageService?.CodeFormatter; | ||
if (codeFormatter == null) | ||
{ | ||
return; | ||
} | ||
|
||
var rangeMarker = new DocumentRange(document, documentRange.TextRange).CreateRangeMarker(DocumentManager.GetInstance(solution)); | ||
|
||
containingFile.OptimizeImportsAndRefs(rangeMarker, false, true, NullProgressIndicator.Instance); | ||
codeFormatter.Format(statement, CodeFormatProfile.DEFAULT); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using JetBrains.ReSharper.Feature.Services.CSharp.Analyses.Bulbs; | ||
using JetBrains.ReSharper.Psi.CSharp.Tree; | ||
using JetBrains.ReSharper.Psi.Tree; | ||
using Resharper.QuickActions.Models; | ||
|
||
namespace Resharper.QuickActions.Helpers | ||
{ | ||
public static class ActionContextExtensions | ||
{ | ||
public static ActionContext GetActionContext(this ICSharpContextActionDataProvider provider) | ||
{ | ||
var result = provider.GetSelectedElement<IMethodDeclaration>(true, true); | ||
if (result == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var selectedTreeNode = provider.SelectedElement; | ||
if (selectedTreeNode == null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (!result.GetNameDocumentRange().Contains(selectedTreeNode.GetDocumentRange())) | ||
{ | ||
return null; | ||
} | ||
|
||
var containingType = result.GetContainingTypeDeclaration(); | ||
if (containingType == null) | ||
{ | ||
return null; | ||
} | ||
|
||
return new ActionContext | ||
{ | ||
Method = result, | ||
ContainingType = containingType | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using JetBrains.ReSharper.Psi.CSharp.Tree; | ||
|
||
namespace Resharper.QuickActions.Models | ||
{ | ||
public class ActionContext | ||
{ | ||
public ICSharpTypeDeclaration ContainingType { get; set; } | ||
|
||
/// <summary> | ||
/// Selected method under cursor. | ||
/// </summary> | ||
public IMethodDeclaration Method { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Reflection; | ||
|
||
[assembly: AssemblyTitle("Resharper.QuickActions")] | ||
[assembly: AssemblyDescription("Quick context actions for Resharper")] | ||
[assembly: AssemblyCompany("Ruslan Mogilevskiy")] | ||
[assembly: AssemblyProduct("Resharper.QuickActions")] | ||
[assembly: AssemblyCopyright("Copyright © Ruslan Mogilevskiy")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.