|
|
@ -18,7 +18,7 @@ using ICSharpCode.SharpDevelop.Editor; |
|
|
|
using ICSharpCode.SharpDevelop.Gui; |
|
|
|
using ICSharpCode.SharpDevelop.Gui; |
|
|
|
using ICSharpCode.SharpDevelop.Project; |
|
|
|
using ICSharpCode.SharpDevelop.Project; |
|
|
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.SharpDevelop |
|
|
|
namespace ICSharpCode.SharpDevelop.Parser |
|
|
|
{ |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Stores the compilation units for files.
|
|
|
|
/// Stores the compilation units for files.
|
|
|
@ -259,7 +259,7 @@ namespace ICSharpCode.SharpDevelop |
|
|
|
else |
|
|
|
else |
|
|
|
snapshot = GetParseableFileContent(viewContent.PrimaryFileName); |
|
|
|
snapshot = GetParseableFileContent(viewContent.PrimaryFileName); |
|
|
|
|
|
|
|
|
|
|
|
lastParseRun = BeginParse(fileName, snapshot).ContinueWith( |
|
|
|
lastParseRun = ParseAsync(fileName, snapshot).ContinueWith( |
|
|
|
delegate(Task<IParsedFile> backgroundTask) { |
|
|
|
delegate(Task<IParsedFile> backgroundTask) { |
|
|
|
IParsedFile parseInfo = backgroundTask.Result; |
|
|
|
IParsedFile parseInfo = backgroundTask.Result; |
|
|
|
RaiseParserUpdateStepFinished(new ParserUpdateStepEventArgs(fileName, snapshot, parseInfo)); |
|
|
|
RaiseParserUpdateStepFinished(new ParserUpdateStepEventArgs(fileName, snapshot, parseInfo)); |
|
|
@ -532,6 +532,7 @@ namespace ICSharpCode.SharpDevelop |
|
|
|
|
|
|
|
|
|
|
|
public Task<IParsedFile> BeginParse(ITextSource fileContent) |
|
|
|
public Task<IParsedFile> BeginParse(ITextSource fileContent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
// TODO: don't use background task if fileContent was specified and up-to-date parse info is available
|
|
|
|
return System.Threading.Tasks.Task.Factory.StartNew( |
|
|
|
return System.Threading.Tasks.Task.Factory.StartNew( |
|
|
|
delegate { |
|
|
|
delegate { |
|
|
|
try { |
|
|
|
try { |
|
|
@ -545,40 +546,38 @@ namespace ICSharpCode.SharpDevelop |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static FileEntry GetFileEntry(string fileName, bool createOnDemand) |
|
|
|
static FileEntry GetFileEntry(FileName fileName, bool createOnDemand) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fileName == null) |
|
|
|
if (fileName == null) |
|
|
|
throw new ArgumentNullException("fileName"); |
|
|
|
throw new ArgumentNullException("fileName"); |
|
|
|
FileName f = new FileName(fileName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileEntry entry; |
|
|
|
FileEntry entry; |
|
|
|
lock (syncLock) { |
|
|
|
lock (syncLock) { |
|
|
|
if (!fileEntryDict.TryGetValue(f, out entry)) { |
|
|
|
if (!fileEntryDict.TryGetValue(fileName, out entry)) { |
|
|
|
if (!createOnDemand) |
|
|
|
if (!createOnDemand) |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
entry = new FileEntry(f); |
|
|
|
entry = new FileEntry(fileName); |
|
|
|
fileEntryDict.Add(f, entry); |
|
|
|
fileEntryDict.Add(fileName, entry); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return entry; |
|
|
|
return entry; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Removes all parse information stored for the specified file.
|
|
|
|
/// Removes all parse information (both IParsedFile and ParseInformation) for the specified file.
|
|
|
|
/// This method is thread-safe.
|
|
|
|
/// This method is thread-safe.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static void ClearParseInformation(string fileName) |
|
|
|
public static void ClearParseInformation(FileName fileName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fileName == null) |
|
|
|
if (fileName == null) |
|
|
|
throw new ArgumentNullException("fileName"); |
|
|
|
throw new ArgumentNullException("fileName"); |
|
|
|
|
|
|
|
|
|
|
|
FileName f = new FileName(fileName); |
|
|
|
LoggingService.Info("ClearParseInformation: " + fileName); |
|
|
|
LoggingService.Info("ClearParseInformation: " + f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileEntry entry; |
|
|
|
FileEntry entry; |
|
|
|
lock (syncLock) { |
|
|
|
lock (syncLock) { |
|
|
|
if (fileEntryDict.TryGetValue(f, out entry)) { |
|
|
|
if (fileEntryDict.TryGetValue(fileName, out entry)) { |
|
|
|
fileEntryDict.Remove(f); |
|
|
|
fileEntryDict.Remove(fileName); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (entry != null) |
|
|
|
if (entry != null) |
|
|
@ -586,141 +585,166 @@ namespace ICSharpCode.SharpDevelop |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets parse information for the specified file.
|
|
|
|
/// This is the old method returning potentially-stale parse information.
|
|
|
|
/// Blocks if the file wasn't parsed yet, but may return an old parsed version.
|
|
|
|
/// Use Parse()/ParseFile() instead if you need fresh parse info; otherwise use GetExistingParsedFile().
|
|
|
|
/// This method is thread-safe. This method involves waiting for the main thread, so using it while
|
|
|
|
|
|
|
|
/// holding a lock can lead to deadlocks. You might want to use <see cref="GetExistingParseInformation"/> instead.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Returns the ParseInformation for the specified file, or null if the file cannot be parsed.
|
|
|
|
[Obsolete("Use Parse()/ParseFile() instead if you need fresh parse info; otherwise use GetExistingParsedFile().")] |
|
|
|
/// The returned ParseInformation might be stale (re-parse is not forced).</returns>
|
|
|
|
public static ParseInformation GetParseInformation(string fileName) |
|
|
|
public static IParsedFile GetParseInformation(string fileName) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(fileName)) |
|
|
|
if (string.IsNullOrEmpty(fileName)) |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
return GetFileEntry(fileName, true).GetParseInformation(null); |
|
|
|
return ParseFile(FileName.Create(fileName)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets parse information for the specified file.
|
|
|
|
/// Gets full parse information for the specified file, if it is available.
|
|
|
|
/// This method is thread-safe.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Returns the ParseInformation for the specified file, or null if the file has not been parsed already.</returns>
|
|
|
|
/// <returns>
|
|
|
|
public static IParsedFile GetExistingParseInformation(string fileName) |
|
|
|
/// Returns the ParseInformation for the specified file,
|
|
|
|
|
|
|
|
/// or null if it is not in the parse information cache.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// If only the IParsedFile is available (non-full parse information), this method
|
|
|
|
|
|
|
|
/// returns null.
|
|
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This method is thread-safe.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// The ParserService may drop elements from the cache at any moment,
|
|
|
|
|
|
|
|
/// only IParsedFile will be stored for a longer time.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static ParseInformation GetCachedParseInformation(FileName fileName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(fileName)) |
|
|
|
if (string.IsNullOrEmpty(fileName)) |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
FileEntry entry = GetFileEntry(fileName, false); |
|
|
|
FileEntry entry = GetFileEntry(fileName, false); |
|
|
|
if (entry != null) |
|
|
|
if (entry != null) |
|
|
|
return entry.GetExistingParseInformation(null); |
|
|
|
return entry.GetCachedParseInformation(null); |
|
|
|
else |
|
|
|
else |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets parse information for the specified file in the context of the
|
|
|
|
/// Gets parse information for the specified file.
|
|
|
|
/// specified project content.
|
|
|
|
|
|
|
|
/// This method is thread-safe.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Returns the ParseInformation for the specified file, or null if the file has not been parsed for that project content.</returns>
|
|
|
|
/// <returns>
|
|
|
|
public static IParsedFile GetExistingParseInformation(IProjectContent content, string fileName) |
|
|
|
/// Returns the IParsedFile for the specified file,
|
|
|
|
|
|
|
|
/// or null if the file has not been parsed yet.
|
|
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
|
|
/// <remarks>This method is thread-safe.</remarks>
|
|
|
|
|
|
|
|
public static IParsedFile GetExistingParsedFile(FileName fileName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(fileName)) |
|
|
|
if (string.IsNullOrEmpty(fileName)) |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
FileEntry entry = GetFileEntry(fileName, false); |
|
|
|
FileEntry entry = GetFileEntry(fileName, false); |
|
|
|
if (entry != null) |
|
|
|
if (entry != null) |
|
|
|
return entry.GetExistingParseInformation(content); |
|
|
|
return entry.GetExistingParsedFile(null); |
|
|
|
else |
|
|
|
else |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets parse information for the specified file.
|
|
|
|
/// Gets parse information for the specified file in the context of the
|
|
|
|
/// Blocks until a recent copy of the parse information is available.
|
|
|
|
/// specified project content.
|
|
|
|
/// This method is thread-safe. This method involves waiting for the main thread, so using it while
|
|
|
|
|
|
|
|
/// holding a lock can lead to deadlocks. You might want to use the overload taking ITextBuffer instead.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Returns the ParseInformation for the specified file, or null if the file cannot be parsed.
|
|
|
|
/// <param name="parentProjectContent">
|
|
|
|
/// The returned ParseInformation will not be stale (re-parse is forced if required).</returns>
|
|
|
|
/// Project content to use as a parent project for the parse run.
|
|
|
|
public static IParsedFile ParseFile(string fileName) |
|
|
|
/// Specifying the project content explicitly can be useful when a file is used in multiple projects.
|
|
|
|
|
|
|
|
/// </param>
|
|
|
|
|
|
|
|
/// <param name="fileName">Name of the file.</param>
|
|
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
|
|
/// Returns the IParsedFile for the specified file,
|
|
|
|
|
|
|
|
/// or null if the file has not been parsed for that project content.
|
|
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
|
|
/// <remarks>This method is thread-safe.</remarks>
|
|
|
|
|
|
|
|
public static IParsedFile GetExistingParsedFile(IProjectContent parentProjectContent, FileName fileName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return GetFileEntry(fileName, true).ParseFile(null, null); |
|
|
|
if (string.IsNullOrEmpty(fileName)) |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
FileEntry entry = GetFileEntry(fileName, false); |
|
|
|
|
|
|
|
if (entry != null) |
|
|
|
|
|
|
|
return entry.GetExistingParsedFile(parentProjectContent); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets parse information for the specified file.
|
|
|
|
/// Parses the specified file.
|
|
|
|
/// The fileContent is taken as a hint - if a newer version than it is already available, that will be used instead.
|
|
|
|
/// Produces full parse information.
|
|
|
|
/// This method is thread-safe.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Returns the ParseInformation for the specified file, or null if the file cannot be parsed.
|
|
|
|
/// <param name="fileName">Name of the file to parse</param>
|
|
|
|
/// The returned ParseInformation will not be stale (re-parse is forced if required).</returns>
|
|
|
|
/// <param name="fileContent">Optional: Content of the file to parse.
|
|
|
|
public static IParsedFile ParseFile(string fileName, ITextSource fileContent) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (fileContent == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("fileContent"); |
|
|
|
|
|
|
|
return GetFileEntry(fileName, true).ParseFile(null, fileContent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Gets parse information for the specified file.
|
|
|
|
|
|
|
|
/// The fileContent is taken as a hint - if a newer version than it is already available, that will be used instead.
|
|
|
|
/// The fileContent is taken as a hint - if a newer version than it is already available, that will be used instead.
|
|
|
|
/// This method is thread-safe.
|
|
|
|
/// </param>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>
|
|
|
|
/// <returns>Returns the ParseInformation for the specified file, or null if the file cannot be parsed.
|
|
|
|
/// Returns the ParseInformation for the specified file, or null if the file cannot be parsed.
|
|
|
|
/// The returned ParseInformation will not be stale (re-parse is forced if required).</returns>
|
|
|
|
/// For files currently open in an editor, this method does not necessary reparse, but may return
|
|
|
|
public static IParsedFile ParseFile(IProjectContent parentProjectContent, string fileName, ITextSource fileContent) |
|
|
|
/// an existing cached parse information (but only if it's still up-to-date).
|
|
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// This method is thread-safe. This parser being used may involve locking or waiting for the main thread,
|
|
|
|
|
|
|
|
/// so using this method while holding a lock can lead to deadlocks.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static ParseInformation Parse(FileName fileName, ITextSource fileContent = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fileContent == null) |
|
|
|
return GetFileEntry(fileName, true).Parse(null, fileContent); |
|
|
|
throw new ArgumentNullException("fileContent"); |
|
|
|
|
|
|
|
return GetFileEntry(fileName, true).ParseFile(parentProjectContent, fileContent); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Begins an asynchronous reparse.
|
|
|
|
/// Asynchronous version of <see cref="Parse(FileName, ITextSource)"/>.
|
|
|
|
/// This method is thread-safe. The returned task might wait for the main thread to be ready, beware of deadlocks.
|
|
|
|
|
|
|
|
/// You might want to use the overload taking ITextBuffer instead.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="fileName">Name of the file to parse</param>
|
|
|
|
|
|
|
|
/// <param name="fileContent">Optional: Content of the file to parse.
|
|
|
|
|
|
|
|
/// The fileContent is taken as a hint - if a newer version than it is already available, that will be used instead.
|
|
|
|
|
|
|
|
/// </param>
|
|
|
|
/// <returns>
|
|
|
|
/// <returns>
|
|
|
|
/// Returns a task that will make the parse result available.
|
|
|
|
/// Returns the ParseInformation for the specified file, or null if the file cannot be parsed.
|
|
|
|
|
|
|
|
/// For files currently open in an editor, this method does not necessary reparse, but may return
|
|
|
|
|
|
|
|
/// an existing cached parse information (but only if it's still up-to-date).
|
|
|
|
/// </returns>
|
|
|
|
/// </returns>
|
|
|
|
/// <remarks>
|
|
|
|
/// <remarks>
|
|
|
|
/// EnqueueForParsing has been renamed to BeginParse and now provides a future (Task<ParseInformation>)
|
|
|
|
/// This method is thread-safe. This parser being used may involve locking or waiting for the main thread,
|
|
|
|
/// to allow waiting for the result. However, to avoid deadlocks, this should not be done by any
|
|
|
|
/// so using this method while holding a lock can lead to deadlocks.
|
|
|
|
/// thread the parser might be waiting for (especially the main thread).
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Unlike BeginParse().Wait(), ParseFile() is safe to call from the main thread.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
/// </remarks>
|
|
|
|
public static Task<IParsedFile> BeginParse(string fileName) |
|
|
|
public static Task<ParseInformation> ParseAsync(FileName fileName, ITextSource fileContent = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return GetFileEntry(fileName, true).BeginParse(null); |
|
|
|
if (fileContent == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("fileContent"); |
|
|
|
|
|
|
|
// create snapshot (in case someone passes a mutable document to BeginParse)
|
|
|
|
|
|
|
|
return GetFileEntry(fileName, true).BeginParse(fileContent.CreateSnapshot()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Begins an asynchronous reparse.
|
|
|
|
/// Parses the specified file.
|
|
|
|
/// This method is thread-safe.
|
|
|
|
/// This method does not request full parse information
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="parentProjectContent">
|
|
|
|
|
|
|
|
/// Project content to use as a parent project for the parse run.
|
|
|
|
|
|
|
|
/// Specifying the project content explicitly can be useful when a file is used in multiple projects.
|
|
|
|
|
|
|
|
/// </param>
|
|
|
|
|
|
|
|
/// <param name="fileName">Name of the file to parse</param>
|
|
|
|
|
|
|
|
/// <param name="fileContent">Optional: Content of the file to parse.
|
|
|
|
|
|
|
|
/// The fileContent is taken as a hint - if a newer version than it is already available, that will be used instead.
|
|
|
|
|
|
|
|
/// </param>
|
|
|
|
/// <returns>
|
|
|
|
/// <returns>
|
|
|
|
/// Returns a task that will make the parse result available.
|
|
|
|
/// Returns the ParseInformation for the specified file, or null if the file cannot be parsed.
|
|
|
|
|
|
|
|
/// For files currently open in an editor, this method does not necessary reparse, but may return
|
|
|
|
|
|
|
|
/// an existing cached parse information (but only if it's still up-to-date).
|
|
|
|
/// </returns>
|
|
|
|
/// </returns>
|
|
|
|
/// <remarks>
|
|
|
|
/// <remarks>
|
|
|
|
/// EnqueueForParsing has been renamed to BeginParse and now provides a future (Task<ParseInformation>)
|
|
|
|
/// This method is thread-safe. This parser being used may involve locking or waiting for the main thread,
|
|
|
|
/// to allow waiting for the result. However, to avoid deadlocks, this should not be done by any
|
|
|
|
/// so using this method while holding a lock can lead to deadlocks.
|
|
|
|
/// thread the parser might be waiting for (especially the main thread).
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Unlike BeginParse().Wait(), ParseFile() is safe to call from the main thread.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
/// </remarks>
|
|
|
|
public static Task<IParsedFile> BeginParse(string fileName, ITextSource fileContent) |
|
|
|
public static IParsedFile ParseFile(IProjectContent parentProjectContent, FileName fileName, ITextSource fileContent = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fileContent == null) |
|
|
|
return GetFileEntry(fileName, true).Parse(parentProjectContent, fileContent); |
|
|
|
throw new ArgumentNullException("fileContent"); |
|
|
|
|
|
|
|
// create snapshot (in case someone passes a mutable document to BeginParse)
|
|
|
|
|
|
|
|
return GetFileEntry(fileName, true).BeginParse(fileContent.CreateSnapshot()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Parses the current view content.
|
|
|
|
/// Parses the current view content.
|
|
|
|
/// This method can only be called from the main thread.
|
|
|
|
/// This method can only be called from the main thread.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static IParsedFile ParseCurrentViewContent() |
|
|
|
public static ParseInformation ParseCurrentViewContent() |
|
|
|
{ |
|
|
|
{ |
|
|
|
WorkbenchSingleton.AssertMainThread(); |
|
|
|
WorkbenchSingleton.AssertMainThread(); |
|
|
|
IViewContent viewContent = WorkbenchSingleton.Workbench.ActiveViewContent; |
|
|
|
IViewContent viewContent = WorkbenchSingleton.Workbench.ActiveViewContent; |
|
|
@ -734,7 +758,7 @@ namespace ICSharpCode.SharpDevelop |
|
|
|
/// Parses the specified view content.
|
|
|
|
/// Parses the specified view content.
|
|
|
|
/// This method can only be called from the main thread.
|
|
|
|
/// This method can only be called from the main thread.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static IParsedFile ParseViewContent(IViewContent viewContent) |
|
|
|
public static ParseInformation ParseViewContent(IViewContent viewContent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (viewContent == null) |
|
|
|
if (viewContent == null) |
|
|
|
throw new ArgumentNullException("viewContent"); |
|
|
|
throw new ArgumentNullException("viewContent"); |
|
|
@ -748,59 +772,6 @@ namespace ICSharpCode.SharpDevelop |
|
|
|
return ParseFile(viewContent.PrimaryFileName); |
|
|
|
return ParseFile(viewContent.PrimaryFileName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Parses the current view content.
|
|
|
|
|
|
|
|
/// This method can only be called from the main thread.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// EnqueueForParsing has been renamed to BeginParse and now provides a future (Task<ParseInformation>)
|
|
|
|
|
|
|
|
/// to allow waiting for the result. However, to avoid deadlocks, this should not be done by any
|
|
|
|
|
|
|
|
/// thread the parser might be waiting for (especially the main thread).
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Unlike BeginParse().Wait(), ParseFile() is safe to call from the main thread.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static Task<IParsedFile> BeginParseCurrentViewContent() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
WorkbenchSingleton.AssertMainThread(); |
|
|
|
|
|
|
|
IViewContent viewContent = WorkbenchSingleton.Workbench.ActiveViewContent; |
|
|
|
|
|
|
|
if (viewContent != null) |
|
|
|
|
|
|
|
return BeginParseViewContent(viewContent); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return NullTask(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Begins parsing the specified view content.
|
|
|
|
|
|
|
|
/// This method can only be called from the main thread.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
|
|
/// EnqueueForParsing has been renamed to BeginParse and now provides a future (Task<ParseInformation>)
|
|
|
|
|
|
|
|
/// to allow waiting for the result. However, to avoid deadlocks, this should not be done by any
|
|
|
|
|
|
|
|
/// thread the parser might be waiting for (especially the main thread).
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Unlike BeginParse().Wait(), ParseFile() is safe to call from the main thread.
|
|
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public static Task<IParsedFile> BeginParseViewContent(IViewContent viewContent) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (viewContent == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("viewContent"); |
|
|
|
|
|
|
|
WorkbenchSingleton.AssertMainThread(); |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(viewContent.PrimaryFileName)) |
|
|
|
|
|
|
|
return NullTask(); |
|
|
|
|
|
|
|
IEditable editable = viewContent as IEditable; |
|
|
|
|
|
|
|
if (editable != null) |
|
|
|
|
|
|
|
return BeginParse(viewContent.PrimaryFileName, editable.CreateSnapshot()); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return BeginParse(viewContent.PrimaryFileName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Task<IParsedFile> NullTask() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var tcs = new TaskCompletionSource<IParsedFile>(); |
|
|
|
|
|
|
|
tcs.SetResult(null); |
|
|
|
|
|
|
|
return tcs.Task; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the parser instance that is responsible for the specified file.
|
|
|
|
/// Gets the parser instance that is responsible for the specified file.
|
|
|
|
/// Will create a new IParser instance on demand.
|
|
|
|
/// Will create a new IParser instance on demand.
|
|
|
@ -815,11 +786,10 @@ namespace ICSharpCode.SharpDevelop |
|
|
|
/// Registers a compilation unit in the parser service.
|
|
|
|
/// Registers a compilation unit in the parser service.
|
|
|
|
/// Does not fire the OnParseInformationUpdated event, please use this for unit tests only!
|
|
|
|
/// Does not fire the OnParseInformationUpdated event, please use this for unit tests only!
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static IParsedFile RegisterParseInformation(string fileName, IParsedFile cu) |
|
|
|
public static void RegisterParseInformation(string fileName, IParsedFile cu) |
|
|
|
{ |
|
|
|
{ |
|
|
|
FileEntry entry = GetFileEntry(fileName, true); |
|
|
|
FileEntry entry = GetFileEntry(fileName, true); |
|
|
|
entry.RegisterParseInformation(cu); |
|
|
|
entry.RegisterParseInformation(cu); |
|
|
|
return cu; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|