Browse Source

Fixed code navigation to work correctly after jumping to another location (e.g. using "Goto definition").

FileService: Position change resulting from call to JumpToFilePosition is now logged in NavigationService.
NavigationService: Make suspend/resume statements incremental as suggested to support this.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3668 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Christian Hornung 17 years ago
parent
commit
1358578da4
  1. 38
      src/Main/Base/Project/Src/Services/File/FileService.cs
  2. 19
      src/Main/Base/Project/Src/Services/NavigationService/NavigationService.cs

38
src/Main/Base/Project/Src/Services/File/FileService.cs

@ -470,22 +470,38 @@ namespace ICSharpCode.SharpDevelop @@ -470,22 +470,38 @@ namespace ICSharpCode.SharpDevelop
public static IViewContent JumpToFilePosition(string fileName, int line, int column)
{
LoggingService.InfoFormatted("FileService\n\tJumping to File Position: [{0} : {1}x{2}]", fileName, line, column);
NavigationService.SuspendLogging();
if (fileName == null || fileName.Length == 0) {
return null;
}
IViewContent content = OpenFile(fileName);
if (content is IPositionable) {
// TODO: enable jumping to a particular view
content.WorkbenchWindow.ActiveViewContent = content;
((IPositionable)content).JumpTo(Math.Max(0, line), Math.Max(0, column));
}
LoggingService.InfoFormatted("FileService\n\tJumped to File Position: [{0} : {1}x{2}]", fileName, line, column);
NavigationService.ResumeLogging();
return content;
NavigationService.SuspendLogging();
bool loggingResumed = false;
try {
IViewContent content = OpenFile(fileName);
if (content is IPositionable) {
// TODO: enable jumping to a particular view
content.WorkbenchWindow.ActiveViewContent = content;
NavigationService.ResumeLogging();
loggingResumed = true;
((IPositionable)content).JumpTo(Math.Max(0, line), Math.Max(0, column));
} else {
NavigationService.ResumeLogging();
loggingResumed = true;
NavigationService.Log(content);
}
LoggingService.InfoFormatted("FileService\n\tJumped to File Position: [{0} : {1}x{2}]", fileName, line, column);
return content;
} finally {
if (!loggingResumed) {
NavigationService.ResumeLogging();
}
}
}
/// <summary>

19
src/Main/Base/Project/Src/Services/NavigationService/NavigationService.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.SharpDevelop @@ -45,7 +45,7 @@ namespace ICSharpCode.SharpDevelop
#region Private members
static LinkedList<INavigationPoint> history = new LinkedList<INavigationPoint>();
static LinkedListNode<INavigationPoint> currentNode;
static bool loggingSuspended;
static int loggingSuspendedCount;
static bool serviceInitialized;
#endregion
@ -138,7 +138,7 @@ namespace ICSharpCode.SharpDevelop @@ -138,7 +138,7 @@ namespace ICSharpCode.SharpDevelop
/// logging is suspended.
/// </summary>
public static bool IsLogging {
get { return !loggingSuspended;}
get { return loggingSuspendedCount == 0;}
}
#endregion
@ -180,7 +180,7 @@ namespace ICSharpCode.SharpDevelop @@ -180,7 +180,7 @@ namespace ICSharpCode.SharpDevelop
/// <param name="pointToLog">The point to store.</param>
public static void Log(INavigationPoint pointToLog)
{
if (loggingSuspended) {
if (loggingSuspendedCount > 0) {
return;
}
LogInternal(pointToLog);
@ -347,10 +347,15 @@ namespace ICSharpCode.SharpDevelop @@ -347,10 +347,15 @@ namespace ICSharpCode.SharpDevelop
/// Suspends logging of navigation so that we don't log intermediate points
/// while opening a file, for example.
/// </summary>
/// <remarks>
/// Suspend/resume statements are incremental, i.e. you must call
/// <see cref="ResumeLogging"/> once for each time you call
/// <see cref="SuspendLogging"/> to resume logging.
/// </remarks>
public static void SuspendLogging()
{
LoggingService.Debug("NavigationService -- suspend logging");
loggingSuspended = true;
System.Threading.Interlocked.Increment(ref loggingSuspendedCount);
}
/// <summary>
@ -359,8 +364,10 @@ namespace ICSharpCode.SharpDevelop @@ -359,8 +364,10 @@ namespace ICSharpCode.SharpDevelop
public static void ResumeLogging()
{
LoggingService.Debug("NavigationService -- resume logging");
loggingSuspended = false;
// ENH: possible enhancement: use int instead of bool so resume statements are incremental rather than definitive.
if (System.Threading.Interlocked.Decrement(ref loggingSuspendedCount) < 0) {
System.Threading.Interlocked.Increment(ref loggingSuspendedCount);
LoggingService.Warn("NavigationService -- ResumeLogging called without corresponding SuspendLogging");
}
}
#endregion

Loading…
Cancel
Save