Browse Source

Add 200ms timeout to CaretReferencesRenderer.

pull/14/head
Daniel Grunwald 15 years ago
parent
commit
7ec189fc1d
  1. 20
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CaretReferencesRenderer.cs
  2. 6
      src/Main/Base/Project/Src/Gui/IProgressMonitor.cs
  3. 20
      src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

20
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CaretReferencesRenderer.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Windows.Threading; using System.Windows.Threading;
using ICSharpCode.AvalonEdit.AddIn.Options; using ICSharpCode.AvalonEdit.AddIn.Options;
@ -10,6 +11,7 @@ using ICSharpCode.Core;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Refactoring; using ICSharpCode.SharpDevelop.Refactoring;
namespace ICSharpCode.AvalonEdit.AddIn namespace ICSharpCode.AvalonEdit.AddIn
@ -127,10 +129,20 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// </summary> /// </summary>
List<Reference> GetReferencesInCurrentFile(ResolveResult resolveResult) List<Reference> GetReferencesInCurrentFile(ResolveResult resolveResult)
{ {
var references = RefactoringService.FindReferencesLocal(resolveResult, Editor.FileName, null); var cancellationTokenSource = new CancellationTokenSource();
if (references == null || references.Count == 0) using (new Timer(
return null; delegate {
return references; LoggingService.Debug("Aborting GetReferencesInCurrentFile due to timeout");
cancellationTokenSource.Cancel();
}, null, 200, Timeout.Infinite))
{
var progressMonitor = new DummyProgressMonitor();
progressMonitor.CancellationToken = cancellationTokenSource.Token;
var references = RefactoringService.FindReferencesLocal(resolveResult, Editor.FileName, progressMonitor);
if (references == null || references.Count == 0)
return null;
return references;
}
} }
/// <summary> /// <summary>

6
src/Main/Base/Project/Src/Gui/IProgressMonitor.cs

@ -120,15 +120,13 @@ namespace ICSharpCode.SharpDevelop.Gui
public OperationStatus Status { get; set; } public OperationStatus Status { get; set; }
public CancellationToken CancellationToken { public CancellationToken CancellationToken { get; set; }
get { return CancellationToken.None; }
}
public double Progress { get; set; } public double Progress { get; set; }
public IProgressMonitor CreateSubTask(double workAmount) public IProgressMonitor CreateSubTask(double workAmount)
{ {
return new DummyProgressMonitor(); return new DummyProgressMonitor() { CancellationToken = this.CancellationToken };
} }
public void Dispose() public void Dispose()

20
src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Threading;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
@ -228,6 +229,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (progressMonitor != null) progressMonitor.ShowingDialog = false; if (progressMonitor != null) progressMonitor.ShowingDialog = false;
return null; return null;
} }
CancellationToken ct = progressMonitor != null ? progressMonitor.CancellationToken : CancellationToken.None;
List<ProjectItem> files; List<ProjectItem> files;
if (!string.IsNullOrEmpty(fileName)) { if (!string.IsNullOrEmpty(fileName)) {
// search just in given file // search just in given file
@ -249,7 +253,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (progressMonitor != null) { if (progressMonitor != null) {
progressMonitor.Progress += 1.0 / files.Count; progressMonitor.Progress += 1.0 / files.Count;
if (progressMonitor.CancellationToken.IsCancellationRequested) if (ct.IsCancellationRequested)
return null; return null;
} }
// Don't read files we don't have a parser for. // Don't read files we don't have a parser for.
@ -257,7 +261,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (ParserService.GetParser(itemFileName) != null) { if (ParserService.GetParser(itemFileName) != null) {
ITextBuffer content = finder.Create(itemFileName); ITextBuffer content = finder.Create(itemFileName);
if (content != null) { if (content != null) {
AddReferences(references, ownerClass, member, itemFileName, content.Text); try {
AddReferences(references, ownerClass, member, itemFileName, content.Text, ct);
} catch (OperationCanceledException ex) {
if (ex.CancellationToken == ct)
return null;
else
throw;
}
} }
} }
} }
@ -270,7 +281,8 @@ namespace ICSharpCode.SharpDevelop.Refactoring
/// </summary> /// </summary>
static void AddReferences(List<Reference> list, static void AddReferences(List<Reference> list,
IClass parentClass, IMember member, IClass parentClass, IMember member,
string fileName, string fileContent) string fileName, string fileContent,
CancellationToken cancellationToken)
{ {
TextFinder textFinder; // the class used to find the position to resolve TextFinder textFinder; // the class used to find the position to resolve
if (member == null) { if (member == null) {
@ -292,6 +304,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
TextFinderMatch match = new TextFinderMatch(-1, 0); TextFinderMatch match = new TextFinderMatch(-1, 0);
while (true) { while (true) {
cancellationToken.ThrowIfCancellationRequested();
match = textFinder.Find(fileContentForFinder, match.Position + 1); match = textFinder.Find(fileContentForFinder, match.Position + 1);
if (match.Position < 0) if (match.Position < 0)
break; break;
@ -307,6 +320,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (expr.Expression != null) { if (expr.Expression != null) {
Point position = GetPosition(fileContent, match.ResolvePosition); Point position = GetPosition(fileContent, match.ResolvePosition);
repeatResolve: repeatResolve:
cancellationToken.ThrowIfCancellationRequested();
// TODO: Optimize by re-using the same resolver if multiple expressions were // TODO: Optimize by re-using the same resolver if multiple expressions were
// found in this file (the resolver should parse all methods at once) // found in this file (the resolver should parse all methods at once)
ResolveResult rr = ParserService.Resolve(expr, position.Y, position.X, fileName, fileContent); ResolveResult rr = ParserService.Resolve(expr, position.Y, position.X, fileName, fileContent);

Loading…
Cancel
Save