From d0188867814f05163365774263ab12f034b20877 Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Tue, 24 Jun 2014 01:48:47 +0200 Subject: [PATCH 1/5] Fixed #357: Ctrl+R: Does not rename ctors of types --- .../Project/Src/Parser/CSharpSymbolSearch.cs | 145 +++++++++++------- .../Editor/Commands/FindReferencesCommand.cs | 4 + 2 files changed, 94 insertions(+), 55 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs index afcd34aff9..435d0a8747 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs @@ -24,6 +24,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using ICSharpCode.NRefactory.Analysis; using CSharpBinding.Parser; using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Highlighting; @@ -56,22 +57,44 @@ namespace CSharpBinding FindReferences fr = new FindReferences(); IList searchScopes; IList[] interestingFileNames; + Dictionary> searchScopesPerFile; int workAmount; double workAmountInverse; public CSharpSymbolSearch(IProject project, ISymbol entity) { this.project = project; - searchScopes = fr.GetSearchScopes(entity); compilation = SD.ParserService.GetCompilation(project); + var relatedSymbols = GetRelatedSymbols(entity); + if ((relatedSymbols != null) && relatedSymbols.Any()) { + searchScopes = relatedSymbols.SelectMany(e => fr.GetSearchScopes(e)).ToList(); + } else { + searchScopes = fr.GetSearchScopes(entity); + } + + searchScopesPerFile = new Dictionary>(); interestingFileNames = new IList[searchScopes.Count]; for (int i = 0; i < searchScopes.Count; i++) { - interestingFileNames[i] = fr.GetInterestingFiles(searchScopes[i], compilation).Select(f => f.FileName).ToList(); - workAmount += interestingFileNames[i].Count; + var thisSearchScope = searchScopes[i]; + var interestingFiles = fr.GetInterestingFiles(thisSearchScope, compilation).Select(f => f.FileName).ToList(); + foreach (var file in interestingFiles) { + if (!searchScopesPerFile.ContainsKey(file)) + searchScopesPerFile[file] = new List(); + searchScopesPerFile[file].Add(thisSearchScope); + } + interestingFileNames[i] = interestingFiles.ToList(); + workAmount += interestingFiles.Count; } workAmountInverse = 1.0 / workAmount; } + IEnumerable GetRelatedSymbols(ISymbol entity) + { + TypeGraph typeGraph = new TypeGraph(new [] { compilation.MainAssembly }); + var symbolCollector = new SymbolCollector(); + return symbolCollector.GetRelatedSymbols(typeGraph, entity); + } + public double WorkAmount { get { return workAmount; } } @@ -83,40 +106,38 @@ namespace CSharpBinding var cancellationToken = args.ProgressMonitor.CancellationToken; return Task.Run( () => { - for (int i = 0; i < searchScopes.Count; i++) { - IFindReferenceSearchScope searchScope = searchScopes[i]; - object progressLock = new object(); - Parallel.ForEach( - interestingFileNames[i], - new ParallelOptions { - MaxDegreeOfParallelism = Environment.ProcessorCount, - CancellationToken = cancellationToken - }, - delegate (string fileName) { - try { - FindReferencesInFile(args, searchScope, FileName.Create(fileName), callback, cancellationToken); - } catch (OperationCanceledException) { - throw; - } catch (Exception ex) { - throw new ApplicationException("Error searching in file '" + fileName + "'", ex); - } - lock (progressLock) - args.ProgressMonitor.Progress += workAmountInverse; - }); - } + object progressLock = new object(); + Parallel.ForEach( + searchScopesPerFile.Keys, + new ParallelOptions { + MaxDegreeOfParallelism = Environment.ProcessorCount, + CancellationToken = cancellationToken + }, + delegate (string fileName) { + try { + FindReferencesInFile(args, searchScopesPerFile[fileName], FileName.Create(fileName), callback, cancellationToken); + } catch (OperationCanceledException) { + throw; + } catch (Exception ex) { + throw new ApplicationException("Error searching in file '" + fileName + "'", ex); + } + lock (progressLock) + args.ProgressMonitor.Progress += workAmountInverse; + }); }, cancellationToken ); } - void FindReferencesInFile(SymbolSearchArgs args, IFindReferenceSearchScope searchScope, FileName fileName, Action callback, CancellationToken cancellationToken) + void FindReferencesInFile(SymbolSearchArgs args, IList searchScopeList, FileName fileName, Action callback, CancellationToken cancellationToken) { ITextSource textSource = args.ParseableFileContentFinder.Create(fileName); if (textSource == null) return; - if (searchScope.SearchTerm != null) { - if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0) - return; - } + // TODO Reactivate somehow! +// if (searchScope.SearchTerm != null) { +// if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0) +// return; +// } var parseInfo = SD.ParserService.Parse(fileName, textSource) as CSharpFullParseInformation; if (parseInfo == null) @@ -134,7 +155,7 @@ namespace CSharpBinding } fr.FindReferencesInFile( - searchScope, unresolvedFile, parseInfo.SyntaxTree, compilation, + searchScopeList, unresolvedFile, parseInfo.SyntaxTree, compilation, delegate (AstNode node, ResolveResult result) { if (document == null) { document = new ReadOnlyDocument(textSource, fileName); @@ -154,8 +175,18 @@ namespace CSharpBinding if (highlighter != null) { highlighter.Dispose(); } - if (results.Count > 0) - callback(new SearchedFile(fileName, results)); + if (results.Count > 0) { + // Remove overlapping results + List fixedResults = new List(); + int lastEndOffset = 0; + foreach (var result in results.OrderBy(m => m.StartOffset)) { + if (result.StartOffset >= lastEndOffset) { + fixedResults.Add(result); + lastEndOffset = result.EndOffset; + } + } + callback(new SearchedFile(fileName, fixedResults)); + } } public Task RenameAsync(SymbolRenameArgs args, Action callback, Action errorCallback) @@ -166,34 +197,32 @@ namespace CSharpBinding return Task.Run( () => { bool isNameValid = Mono.CSharp.Tokenizer.IsValidIdentifier(args.NewName); - for (int i = 0; i < searchScopes.Count; i++) { - IFindReferenceSearchScope searchScope = searchScopes[i]; - object progressLock = new object(); - Parallel.ForEach( - interestingFileNames[i], - new ParallelOptions { - MaxDegreeOfParallelism = Environment.ProcessorCount, - CancellationToken = cancellationToken - }, - delegate (string fileName) { - RenameReferencesInFile(args, searchScope, FileName.Create(fileName), callback, errorCallback, isNameValid, cancellationToken); - lock (progressLock) - args.ProgressMonitor.Progress += workAmountInverse; - }); - } + object progressLock = new object(); + Parallel.ForEach( + searchScopesPerFile.Keys, + new ParallelOptions { + MaxDegreeOfParallelism = Environment.ProcessorCount, + CancellationToken = cancellationToken + }, + delegate (string fileName) { + RenameReferencesInFile(args, searchScopesPerFile[fileName], FileName.Create(fileName), callback, errorCallback, isNameValid, cancellationToken); + lock (progressLock) + args.ProgressMonitor.Progress += workAmountInverse; + }); }, cancellationToken ); } - void RenameReferencesInFile(SymbolRenameArgs args, IFindReferenceSearchScope searchScope, FileName fileName, Action callback, Action errorCallback, bool isNameValid, CancellationToken cancellationToken) + void RenameReferencesInFile(SymbolRenameArgs args, IList searchScopeList, FileName fileName, Action callback, Action errorCallback, bool isNameValid, CancellationToken cancellationToken) { ITextSource textSource = args.ParseableFileContentFinder.Create(fileName); if (textSource == null) return; - if (searchScope.SearchTerm != null) { - if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0) - return; - } + // TODO Reactivate somehow! +// if (searchScope.SearchTerm != null) { +// if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0) +// return; +// } var parseInfo = SD.ParserService.Parse(fileName, textSource) as CSharpFullParseInformation; if (parseInfo == null) @@ -213,7 +242,7 @@ namespace CSharpBinding CSharpAstResolver resolver = new CSharpAstResolver(compilation, parseInfo.SyntaxTree, unresolvedFile); fr.RenameReferencesInFile( - new[] { searchScope }, args.NewName, resolver, + searchScopeList, args.NewName, resolver, delegate (RenameCallbackArguments callbackArgs) { var node = callbackArgs.NodeToReplace; string newCode = callbackArgs.NewNode.ToString(); @@ -249,10 +278,16 @@ namespace CSharpBinding } IDocument changedDocument = new TextDocument(document); var oldVersion = changedDocument.Version; + List fixedResults = new List(); + int lastStartOffset = changedDocument.TextLength + 1; foreach (var result in results.OrderByDescending(m => m.StartOffset)) { - changedDocument.Replace(result.StartOffset, result.Length, result.NewCode); + if (result.EndOffset <= lastStartOffset) { + changedDocument.Replace(result.StartOffset, result.Length, result.NewCode); + fixedResults.Add(result); + lastStartOffset = result.StartOffset; + } } - callback(new PatchedFile(fileName, results, oldVersion, changedDocument.Version)); + callback(new PatchedFile(fileName, fixedResults, oldVersion, changedDocument.Version)); } } } diff --git a/src/Main/Base/Project/Src/Editor/Commands/FindReferencesCommand.cs b/src/Main/Base/Project/Src/Editor/Commands/FindReferencesCommand.cs index 16c0a301ce..f69b37c176 100644 --- a/src/Main/Base/Project/Src/Editor/Commands/FindReferencesCommand.cs +++ b/src/Main/Base/Project/Src/Editor/Commands/FindReferencesCommand.cs @@ -53,6 +53,10 @@ namespace ICSharpCode.SharpDevelop.Editor.Commands public override void Run(ResolveResult symbol) { var entity = GetSymbol(symbol); + if ((entity is IMember) && ((entity.SymbolKind == SymbolKind.Constructor) || (entity.SymbolKind == SymbolKind.Destructor))) { + // Don't rename constructors/destructors, rename their declaring type instead + entity = ((IMember) entity).DeclaringType.GetDefinition(); + } if (entity != null) { var project = GetProjectFromSymbol(entity); if (project != null) { From 11dcc20cc4951457cae14f032f634d9c9e5199af Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Thu, 26 Jun 2014 01:41:22 +0200 Subject: [PATCH 2/5] Readded additional lookups for search term before searching for references in CSharpSymbolSearch. --- .../Project/Src/Parser/CSharpSymbolSearch.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs index 435d0a8747..2e38fa7dc6 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs @@ -133,11 +133,11 @@ namespace CSharpBinding ITextSource textSource = args.ParseableFileContentFinder.Create(fileName); if (textSource == null) return; - // TODO Reactivate somehow! -// if (searchScope.SearchTerm != null) { -// if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0) -// return; -// } + if (searchScopeList != null) { + if (!searchScopeList.Any( + scope => (scope.SearchTerm == null) || (textSource.IndexOf(scope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) >= 0))) + return; + } var parseInfo = SD.ParserService.Parse(fileName, textSource) as CSharpFullParseInformation; if (parseInfo == null) @@ -218,11 +218,11 @@ namespace CSharpBinding ITextSource textSource = args.ParseableFileContentFinder.Create(fileName); if (textSource == null) return; - // TODO Reactivate somehow! -// if (searchScope.SearchTerm != null) { -// if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0) -// return; -// } + if (searchScopeList != null) { + if (!searchScopeList.Any( + scope => (scope.SearchTerm == null) || (textSource.IndexOf(scope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) >= 0))) + return; + } var parseInfo = SD.ParserService.Parse(fileName, textSource) as CSharpFullParseInformation; if (parseInfo == null) From e2aacef60cd1dde7141401febdf7464c4cd87ad8 Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Thu, 26 Jun 2014 02:05:02 +0200 Subject: [PATCH 3/5] Fix #328: Settings > File Format Associations Dialog Issue --- .../Project/Src/RegisterFiletypesPanel.Designer.cs | 12 +++++++----- .../Project/Src/RegisterFiletypesPanel.cs | 7 +++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/AddIns/Misc/FiletypeRegisterer/Project/Src/RegisterFiletypesPanel.Designer.cs b/src/AddIns/Misc/FiletypeRegisterer/Project/Src/RegisterFiletypesPanel.Designer.cs index 1970bae87d..fc94603d6f 100644 --- a/src/AddIns/Misc/FiletypeRegisterer/Project/Src/RegisterFiletypesPanel.Designer.cs +++ b/src/AddIns/Misc/FiletypeRegisterer/Project/Src/RegisterFiletypesPanel.Designer.cs @@ -38,7 +38,7 @@ namespace ICSharpCode.FiletypeRegisterer } base.Dispose(disposing); } - + /// /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might @@ -53,24 +53,25 @@ namespace ICSharpCode.FiletypeRegisterer // captionLabel // this.captionLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + | System.Windows.Forms.AnchorStyles.Right))); this.captionLabel.Location = new System.Drawing.Point(3, 0); this.captionLabel.Name = "captionLabel"; this.captionLabel.Size = new System.Drawing.Size(328, 23); this.captionLabel.TabIndex = 0; this.captionLabel.Text = "${res:ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.RegisterFiletypesPanel.Ca" + - "ptionLabel}"; + "ptionLabel}"; // // fileTypesListBox // this.fileTypesListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.fileTypesListBox.IntegralHeight = false; this.fileTypesListBox.Location = new System.Drawing.Point(3, 26); this.fileTypesListBox.Name = "fileTypesListBox"; this.fileTypesListBox.Size = new System.Drawing.Size(328, 299); this.fileTypesListBox.TabIndex = 1; + this.fileTypesListBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.fileTypesListBox_MouseClick); // // RegisterFiletypesPanel // @@ -79,6 +80,7 @@ namespace ICSharpCode.FiletypeRegisterer this.Name = "RegisterFiletypesPanel"; this.Size = new System.Drawing.Size(334, 328); this.ResumeLayout(false); + } private System.Windows.Forms.CheckedListBox fileTypesListBox; private System.Windows.Forms.Label captionLabel; diff --git a/src/AddIns/Misc/FiletypeRegisterer/Project/Src/RegisterFiletypesPanel.cs b/src/AddIns/Misc/FiletypeRegisterer/Project/Src/RegisterFiletypesPanel.cs index 2af5952278..0a40e941a1 100644 --- a/src/AddIns/Misc/FiletypeRegisterer/Project/Src/RegisterFiletypesPanel.cs +++ b/src/AddIns/Misc/FiletypeRegisterer/Project/Src/RegisterFiletypesPanel.cs @@ -80,5 +80,12 @@ namespace ICSharpCode.FiletypeRegisterer } return true; } + + void fileTypesListBox_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) + { + if (fileTypesListBox.IndexFromPoint(e.X, e.Y) == ListBox.NoMatches) { + fileTypesListBox.SelectedIndex = -1; + } + } } } From 1c1e65518b148a4c81cd962a71a500b63ca6e452 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 22 Jun 2014 15:30:19 +0200 Subject: [PATCH 4/5] Fix adding 32-bit image format to .ico --- .../DisplayBindings/IconEditor/PickFormatDialog.Designer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/IconEditor/PickFormatDialog.Designer.cs b/src/AddIns/DisplayBindings/IconEditor/PickFormatDialog.Designer.cs index c0b83322fb..4815c9c6c2 100644 --- a/src/AddIns/DisplayBindings/IconEditor/PickFormatDialog.Designer.cs +++ b/src/AddIns/DisplayBindings/IconEditor/PickFormatDialog.Designer.cs @@ -133,7 +133,6 @@ namespace ICSharpCode.IconEditor "Monochrome", "4 bit", "8 bit", - "16 bit", "24 bit", "32 bit"}); this.colorDepthComboBox.Location = new System.Drawing.Point(93, 73); From d8fd301d251c738540d67588467bb9143b09d4cb Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 22 Jun 2014 15:33:25 +0200 Subject: [PATCH 5/5] Debugger: ignore "Process was terminated" error when trying to terminate the process. --- src/AddIns/Debugger/Debugger.Core/Process.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.Core/Process.cs b/src/AddIns/Debugger/Debugger.Core/Process.cs index 6ebdeee737..da2cc09f06 100644 --- a/src/AddIns/Debugger/Debugger.Core/Process.cs +++ b/src/AddIns/Debugger/Debugger.Core/Process.cs @@ -527,8 +527,16 @@ namespace Debugger System.Threading.Thread.Sleep(0); // Stop&terminate - both must be called - corProcess.Stop(uint.MaxValue); - corProcess.Terminate(0); + try { + corProcess.Stop(uint.MaxValue); + corProcess.Terminate(0); + } catch (COMException ex) { + if (ex.ErrorCode == unchecked((int)0x80131301)) { + // COMException (0x80131301): Process was terminated. + } else { + throw; + } + } this.TerminateCommandIssued = true; // Do not mark the process as exited