Browse Source

Fix SD-1736: When a file is in multiple projects, ParserService should return the ParseInformation for the project that does not link to the file.

pull/2/head
Daniel Grunwald 16 years ago
parent
commit
f25bb57203
  1. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs
  2. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
  3. 2
      src/AddIns/VersionControl/SubversionAddIn/Src/Commands/AutostartCommands.cs
  4. 11
      src/Main/Base/Project/Src/Project/Solution/Solution.cs
  5. 7
      src/Main/Base/Project/Src/Services/ParserService/ParseInformationEventArgs.cs
  6. 23
      src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
  7. 15
      src/Main/Core/Project/Src/Services/FileUtility/FileNameEventHandler.cs
  8. 4
      src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs

@ -33,6 +33,8 @@ namespace ICSharpCode.XamlBinding @@ -33,6 +33,8 @@ namespace ICSharpCode.XamlBinding
{
if (this.editor == null || !FileUtility.IsEqualFileName(this.editor.FileName, e.FileName))
return;
if (!e.IsPrimaryParseInfoForFile)
return;
var cu = e.NewCompilationUnit as XamlCompilationUnit;

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs

@ -507,7 +507,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -507,7 +507,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
void ParserServiceParseInformationUpdated(object sender, ParseInformationEventArgs e)
{
if (e.FileName != this.FileName)
if (e.FileName != this.FileName || !e.IsPrimaryParseInfoForFile)
return;
this.VerifyAccess();
// When parse information is updated quickly in succession, only do a single update

2
src/AddIns/VersionControl/SubversionAddIn/Src/Commands/AutostartCommands.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.Svn.Commands @@ -28,7 +28,7 @@ namespace ICSharpCode.Svn.Commands
ProjectService.SolutionCreated += SolutionCreated;
ProjectService.ProjectCreated += ProjectCreated;
FileUtility.FileSaved += new FileNameEventHandler(FileSaved);
FileUtility.FileSaved += FileSaved;
AbstractProjectBrowserTreeNode.OnNewNode += TreeNodeCreated;
}

11
src/Main/Base/Project/Src/Project/Solution/Solution.cs

@ -42,12 +42,17 @@ namespace ICSharpCode.SharpDevelop.Project @@ -42,12 +42,17 @@ namespace ICSharpCode.SharpDevelop.Project
return currentProject;
// Try all project's in the solution.
IProject linkedProject = null;
foreach (IProject project in Projects) {
if (project.IsFileInProject(fileName)) {
return project;
FileProjectItem file = project.FindFile(fileName);
if (file != null) {
if (file.IsLink)
linkedProject = project;
else
return project; // prefer projects with non-links over projects with links
}
}
return null;
return linkedProject;
}
[Browsable(false)]

7
src/Main/Base/Project/Src/Services/ParserService/ParseInformationEventArgs.cs

@ -48,7 +48,11 @@ namespace ICSharpCode.SharpDevelop @@ -48,7 +48,11 @@ namespace ICSharpCode.SharpDevelop
}
}
public ParseInformationEventArgs(FileName fileName, IProjectContent projectContent, ICompilationUnit oldCompilationUnit, ParseInformation newParseInformation)
public bool IsPrimaryParseInfoForFile {
get; private set;
}
public ParseInformationEventArgs(FileName fileName, IProjectContent projectContent, ICompilationUnit oldCompilationUnit, ParseInformation newParseInformation, bool isPrimaryParseInfoForFile)
{
if (fileName == null)
throw new ArgumentNullException("fileName");
@ -58,6 +62,7 @@ namespace ICSharpCode.SharpDevelop @@ -58,6 +62,7 @@ namespace ICSharpCode.SharpDevelop
this.projectContent = projectContent;
this.oldCompilationUnit = oldCompilationUnit;
this.newParseInformation = newParseInformation;
this.IsPrimaryParseInfoForFile = isPrimaryParseInfoForFile;
}
}

23
src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

@ -97,13 +97,22 @@ namespace ICSharpCode.SharpDevelop @@ -97,13 +97,22 @@ namespace ICSharpCode.SharpDevelop
static List<IProjectContent> GetProjectContents(string fileName)
{
List<IProjectContent> result = new List<IProjectContent>();
List<IProjectContent> linkResults = new List<IProjectContent>();
lock (projectContents) {
foreach (KeyValuePair<IProject, IProjectContent> projectContent in projectContents) {
if (projectContent.Key.IsFileInProject(fileName)) {
result.Add(projectContent.Value);
FileProjectItem file = projectContent.Key.FindFile(fileName);
if (file != null) {
// Prefer normal files over linked files.
// The order matters because GetParseInformation() will return the ICompilationUnit
// for the first result.
if (file.IsLink)
linkResults.Add(projectContent.Value);
else
result.Add(projectContent.Value);
}
}
}
result.AddRange(linkResults);
if (result.Count == 0)
result.Add(DefaultProjectContent);
return result;
@ -467,14 +476,14 @@ namespace ICSharpCode.SharpDevelop @@ -467,14 +476,14 @@ namespace ICSharpCode.SharpDevelop
ICompilationUnit oldUnit = oldUnits.FirstOrDefault(o => o.ProjectContent == pc);
pc.UpdateCompilationUnit(oldUnit, newUnits[i], fileName);
ParseInformation newUnitParseInfo = (newUnits[i] == resultUnit) ? newParseInfo : new ParseInformation(newUnits[i]);
RaiseParseInformationUpdated(new ParseInformationEventArgs(fileName, pc, oldUnit, newUnitParseInfo));
RaiseParseInformationUpdated(new ParseInformationEventArgs(fileName, pc, oldUnit, newUnitParseInfo, newUnits[i] == resultUnit));
}
// remove all old units that don't exist anymore
foreach (ICompilationUnit oldUnit in oldUnits) {
if (!newUnits.Any(n => n.ProjectContent == oldUnit.ProjectContent)) {
oldUnit.ProjectContent.RemoveCompilationUnit(oldUnit);
RaiseParseInformationUpdated(new ParseInformationEventArgs(fileName, oldUnit.ProjectContent, oldUnit, null));
RaiseParseInformationUpdated(new ParseInformationEventArgs(fileName, oldUnit.ProjectContent, oldUnit, null, false));
}
}
@ -487,18 +496,22 @@ namespace ICSharpCode.SharpDevelop @@ -487,18 +496,22 @@ namespace ICSharpCode.SharpDevelop
public void Clear()
{
ParseInformation parseInfo;
ICompilationUnit[] oldUnits;
lock (this) {
// by setting the disposed flag, we'll cause all running ParseFile() calls to return null and not
// call into the parser anymore, so we can do the remainder of the clean-up work outside the lock
this.disposed = true;
parseInfo = this.parseInfo;
oldUnits = this.oldUnits;
this.oldUnits = null;
this.bufferVersion = null;
this.parseInfo = null;
}
foreach (ICompilationUnit oldUnit in oldUnits) {
oldUnit.ProjectContent.RemoveCompilationUnit(oldUnit);
RaiseParseInformationUpdated(new ParseInformationEventArgs(fileName, oldUnit.ProjectContent, oldUnit, null));
bool isPrimary = parseInfo != null && parseInfo.CompilationUnit == oldUnit;
RaiseParseInformationUpdated(new ParseInformationEventArgs(fileName, oldUnit.ProjectContent, oldUnit, null, isPrimary));
}
}

15
src/Main/Core/Project/Src/Services/FileUtility/FileNameEventHandler.cs

@ -5,24 +5,27 @@ using System; @@ -5,24 +5,27 @@ using System;
namespace ICSharpCode.Core
{
public delegate void FileNameEventHandler(object sender, FileNameEventArgs e);
/// <summary>
/// Description of FileEventHandler.
/// EventArgs with a file name.
/// </summary>
public class FileNameEventArgs : System.EventArgs
{
string fileName;
FileName fileName;
public string FileName {
public FileName FileName {
get {
return fileName;
}
}
public FileNameEventArgs(string fileName)
public FileNameEventArgs(FileName fileName)
{
this.fileName = fileName;
}
public FileNameEventArgs(string fileName)
{
this.fileName = FileName.Create(fileName);
}
}
}

4
src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

@ -682,7 +682,7 @@ namespace ICSharpCode.Core @@ -682,7 +682,7 @@ namespace ICSharpCode.Core
}
}
public static event FileNameEventHandler FileLoaded;
public static event FileNameEventHandler FileSaved;
public static event EventHandler<FileNameEventArgs> FileLoaded;
public static event EventHandler<FileNameEventArgs> FileSaved;
}
}

Loading…
Cancel
Save