Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 7aa8587

Browse files
add support for renaming local variables and parameters
1 parent b7d181f commit 7aa8587

9 files changed

Lines changed: 51 additions & 15 deletions

File tree

src/AddIns/Analysis/UnitTesting/Commands/TestableCondition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static IEnumerable<ITest> GetTests(ITestSolution testSolution, object cal
4141
return testTreeView.SelectedTests;
4242
}
4343
if (testSolution != null) {
44-
IEntity entity = ResolveResultMenuCommand.GetEntity(caller);
44+
IEntity entity = ResolveResultMenuCommand.GetSymbol(caller) as IEntity;
4545
return testSolution.GetTestsForEntity(entity);
4646
}
4747
return Enumerable.Empty<ITest>();

src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ namespace ICSharpCode.XamlBinding
2424
public class XamlSymbolSearch : ISymbolSearch
2525
{
2626
ICompilation compilation;
27-
IEntity entity;
27+
ISymbol entity;
2828
List<FileName> interestingFileNames;
2929
int workAmount;
3030
double workAmountInverse;
3131

3232
public XamlSymbolSearch(IProject project, ISymbol entity)
3333
{
3434
compilation = SD.ParserService.GetCompilation(project);
35-
this.entity = compilation.Import((IEntity)entity);
35+
if (entity is IEntity)
36+
this.entity = compilation.Import((IEntity)entity);
3637
interestingFileNames = new List<FileName>();
3738
if (this.entity == null)
3839
return;
@@ -69,7 +70,7 @@ public Task FindReferencesAsync(SymbolSearchArgs searchArguments, Action<Searche
6970
);
7071
}
7172

72-
void FindReferencesInFile(SymbolSearchArgs searchArguments, IEntity entity, FileName fileName, Action<SearchedFile> callback, CancellationToken cancellationToken)
73+
void FindReferencesInFile(SymbolSearchArgs searchArguments, ISymbol entity, FileName fileName, Action<SearchedFile> callback, CancellationToken cancellationToken)
7374
{
7475
ITextSource textSource = searchArguments.ParseableFileContentFinder.Create(fileName);
7576
if (textSource == null)

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/FindBaseClasses.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class FindBaseClasses : ResolveResultMenuCommand
2020
{
2121
public override void Run(ResolveResult symbol)
2222
{
23-
IEntity entityUnderCaret = GetEntity(symbol);
23+
IEntity entityUnderCaret = GetSymbol(symbol) as IEntity;
2424
if (entityUnderCaret is ITypeDefinition) {
2525
MakePopupWithBaseClasses((ITypeDefinition)entityUnderCaret).OpenAtCaretAndFocus();
2626
} else {

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/FindDerivedClassesOrOverrides.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class FindDerivedClassesOrOverrides : ResolveResultMenuCommand
2020
{
2121
public override void Run(ResolveResult symbol)
2222
{
23-
IEntity entityUnderCaret = GetEntity(symbol);
23+
IEntity entityUnderCaret = GetSymbol(symbol) as IEntity;
2424
if (entityUnderCaret is ITypeDefinition && !entityUnderCaret.IsSealed) {
2525
MakePopupWithDerivedClasses((ITypeDefinition)entityUnderCaret).OpenAtCaretAndFocus();
2626
return;

src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/OpenInILSpyCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using ICSharpCode.NRefactory.Semantics;
6+
using ICSharpCode.NRefactory.TypeSystem;
67
using ICSharpCode.SharpDevelop.Editor.Commands;
78

89
namespace ICSharpCode.ILSpyAddIn
@@ -15,7 +16,7 @@ public sealed class OpenInILSpyCommand : ResolveResultMenuCommand
1516
{
1617
public override void Run(ResolveResult symbol)
1718
{
18-
var entity = GetEntity(symbol);
19+
var entity = GetSymbol(symbol) as IEntity;
1920
if (entity != null) {
2021
ILSpyController.OpenInILSpy(entity);
2122
}

src/Main/Base/Project/Src/Editor/Commands/FindReferencesCommand.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using ICSharpCode.Core;
66
using ICSharpCode.NRefactory.Semantics;
7+
using ICSharpCode.NRefactory.TypeSystem;
78
using ICSharpCode.SharpDevelop;
89
using ICSharpCode.SharpDevelop.Editor.Dialogs;
910
using ICSharpCode.SharpDevelop.Gui;
@@ -18,7 +19,7 @@ public class FindReferencesCommand : ResolveResultMenuCommand
1819
{
1920
public override void Run(ResolveResult symbol)
2021
{
21-
var entity = GetEntity(symbol);
22+
var entity = GetSymbol(symbol) as IEntity;
2223
if (entity != null) {
2324
FindReferencesAndRenameHelper.RunFindReferences(entity);
2425
return;
@@ -36,9 +37,9 @@ public class RenameSymbolCommand : ResolveResultMenuCommand
3637
{
3738
public override void Run(ResolveResult symbol)
3839
{
39-
var entity = GetEntity(symbol);
40+
var entity = GetSymbol(symbol);
4041
if (entity != null) {
41-
var project = entity.ParentAssembly.GetProject();
42+
var project = GetProjectFromSymbol(entity);
4243
if (project != null) {
4344
var languageBinding = project.LanguageBinding;
4445

@@ -58,6 +59,35 @@ public override void Run(ResolveResult symbol)
5859
}
5960
}
6061

62+
ICSharpCode.SharpDevelop.Project.IProject GetProjectFromSymbol(ISymbol symbol)
63+
{
64+
switch (symbol.SymbolKind) {
65+
case SymbolKind.None:
66+
return null;
67+
case SymbolKind.TypeDefinition:
68+
case SymbolKind.Field:
69+
case SymbolKind.Property:
70+
case SymbolKind.Indexer:
71+
case SymbolKind.Event:
72+
case SymbolKind.Method:
73+
case SymbolKind.Operator:
74+
case SymbolKind.Constructor:
75+
case SymbolKind.Destructor:
76+
case SymbolKind.Accessor:
77+
return ((IEntity)symbol).ParentAssembly.GetProject();
78+
case SymbolKind.Namespace:
79+
return null; // TODO : extend rename on namespaces
80+
case SymbolKind.Variable:
81+
return SD.ProjectService.FindProjectContainingFile(new FileName(((IVariable)symbol).Region.FileName));
82+
case SymbolKind.Parameter:
83+
return ((IParameter)symbol).Owner.ParentAssembly.GetProject();
84+
case SymbolKind.TypeParameter:
85+
return null; // TODO : extend rename on type parameters
86+
default:
87+
throw new ArgumentOutOfRangeException();
88+
}
89+
}
90+
6191
bool CheckName(string name, ILanguageBinding language)
6292
{
6393
if (string.IsNullOrEmpty(name))

src/Main/Base/Project/Src/Editor/Commands/GoToDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public override void Run(ResolveResult symbol)
3131

3232
DomRegion pos = symbol.GetDefinitionRegion();
3333
if (string.IsNullOrEmpty(pos.FileName)) {
34-
IEntity entity = GetEntity(symbol);
34+
IEntity entity = GetSymbol(symbol) as IEntity;
3535
if (entity != null) {
3636
NavigationService.NavigateTo(entity);
3737
}

src/Main/Base/Project/Src/Editor/Commands/SymbolUnderCaretMenuCommand.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public static ResolveResult GetResolveResult(object owner)
5252
return GetResolveResult(null, owner);
5353
}
5454

55-
public static IEntity GetEntity(object owner)
55+
public static ISymbol GetSymbol(object owner)
5656
{
57-
return GetEntity(GetResolveResult(null, owner));
57+
return GetSymbol(GetResolveResult(null, owner));
5858
}
5959

6060
static ResolveResult GetResolveResult(ITextEditor currentEditor, object owner)
@@ -80,14 +80,17 @@ static ResolveResult GetResolveResultFromEntityModel(IEntityModel entityModel)
8080
return ErrorResolveResult.UnknownError;
8181
}
8282

83-
protected static IEntity GetEntity(ResolveResult symbol)
83+
protected static ISymbol GetSymbol(ResolveResult symbol)
8484
{
8585
TypeResolveResult trr = symbol as TypeResolveResult;
8686
if (trr != null)
8787
return trr.Type.GetDefinition();
8888
MemberResolveResult mrr = symbol as MemberResolveResult;
8989
if (mrr != null)
9090
return mrr.Member.MemberDefinition;
91+
LocalResolveResult lrr = symbol as LocalResolveResult;
92+
if (lrr != null)
93+
return lrr.Variable;
9194
return null;
9295
}
9396
}

src/Main/SharpDevelop/Dom/ClassBrowser/Commands.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using ICSharpCode.NRefactory.Semantics;
9+
using ICSharpCode.NRefactory.TypeSystem;
910
using ICSharpCode.SharpDevelop.Debugging;
1011
using ICSharpCode.SharpDevelop.Editor.Commands;
1112
using Microsoft.Win32;
@@ -141,7 +142,7 @@ class OpenInClassBrowserCommand : ResolveResultMenuCommand
141142
public override void Run(ResolveResult symbol)
142143
{
143144
var classBrowser = SD.GetService<IClassBrowser>();
144-
var entity = GetEntity(symbol);
145+
var entity = GetSymbol(symbol) as IEntity;
145146
if ((classBrowser != null) && (entity != null)) {
146147
classBrowser.GoToEntity(entity);
147148
}

0 commit comments

Comments
 (0)