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
public static IViewContent JumpToFilePosition(string fileName, int line, int column) 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); LoggingService.InfoFormatted("FileService\n\tJumping to File Position: [{0} : {1}x{2}]", fileName, line, column);
NavigationService.SuspendLogging();
if (fileName == null || fileName.Length == 0) { if (fileName == null || fileName.Length == 0) {
return null; 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.SuspendLogging();
NavigationService.ResumeLogging(); bool loggingResumed = false;
return content; 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> /// <summary>

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

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

Loading…
Cancel
Save