Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed VB code completion (loading of mscorlib.dll and Microsoft.Visua…

…lBasic.dll)

The VB code completion logic was relying on the special cases that I removed in commit 7c1c3b4.
With this fix, multi-targeting works with the assemblies implicitly referenced by the VB compiler.
  • Loading branch information...
commit 35a22b2121f91bd444073d94e5ceb93df44e604a 1 parent aa83bf1
@dgrunwald dgrunwald authored
View
27 src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooProject.cs
@@ -2,8 +2,11 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
+using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
+using System.Linq;
+using System.Threading;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
@@ -80,7 +83,6 @@ public override ItemType GetDefaultItemType(string fileName)
}
internal static IProjectContent BooCompilerPC;
- internal static IProjectContent BooUsefulPC;
protected override ParseProjectContent CreateProjectContent()
{
@@ -88,17 +90,8 @@ protected override ParseProjectContent CreateProjectContent()
ReferenceProjectItem booCompilerItem = new ReferenceProjectItem(this, typeof(Boo.Lang.Compiler.AbstractAstAttribute).Assembly.Location);
BooCompilerPC = AssemblyParserService.GetProjectContentForReference(booCompilerItem);
}
- if (BooUsefulPC == null) {
- ReferenceProjectItem booUsefulItem = new ReferenceProjectItem(this, typeof(Boo.Lang.Useful.Attributes.SingletonAttribute).Assembly.Location);
- BooUsefulPC = AssemblyParserService.GetRegistryForReference(booUsefulItem).GetProjectContentForReference("Boo.Lang.Useful", booUsefulItem.Include);
- }
+
ParseProjectContent pc = base.CreateProjectContent();
- ReferenceProjectItem systemItem = new ReferenceProjectItem(this, "System");
- pc.AddReferencedContent(AssemblyParserService.GetProjectContentForReference(systemItem));
- ReferenceProjectItem booLangItem = new ReferenceProjectItem(this, typeof(Boo.Lang.Builtins).Assembly.Location);
- pc.AddReferencedContent(AssemblyParserService.GetProjectContentForReference(booLangItem));
- ReferenceProjectItem booExtensionsItem = new ReferenceProjectItem(this, typeof(Boo.Lang.Extensions.PropertyAttribute).Assembly.Location);
- pc.AddReferencedContent(AssemblyParserService.GetProjectContentForReference(booExtensionsItem));
pc.DefaultImports = new DefaultUsing(pc);
pc.DefaultImports.Usings.Add("Boo.Lang");
pc.DefaultImports.Usings.Add("Boo.Lang.Builtins");
@@ -106,6 +99,18 @@ protected override ParseProjectContent CreateProjectContent()
return pc;
}
+ public override IEnumerable<ReferenceProjectItem> ResolveAssemblyReferences(CancellationToken cancellationToken)
+ {
+ ReferenceProjectItem[] additionalReferences = {
+ new ReferenceProjectItem(this, "System")
+ };
+ ReferenceProjectItem[] booReferences = {
+ new ReferenceProjectItem(this, "Boo.Lang") { FileName = typeof(Boo.Lang.Builtins).Assembly.Location },
+ new ReferenceProjectItem(this, "Boo.Extensions") { FileName = typeof(Boo.Lang.Extensions.PropertyAttribute).Assembly.Location }
+ };
+ return MSBuildInternals.ResolveAssemblyReferences(this, additionalReferences).Concat(booReferences);
+ }
+
public override IAmbience GetAmbience()
{
return new BooAmbience();
View
18 src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/VBNetProject.cs
@@ -2,9 +2,10 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
-using System.ComponentModel;
-using System.Linq;
+using System.Collections.Generic;
using System.IO;
+using System.Linq;
+using System.Threading;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
@@ -67,14 +68,19 @@ public VBNetProject(ProjectCreateInformation info)
protected override ParseProjectContent CreateProjectContent()
{
ParseProjectContent pc = base.CreateProjectContent();
- ReferenceProjectItem vbRef = new ReferenceProjectItem(this, "Microsoft.VisualBasic");
- if (vbRef != null) {
- pc.AddReferencedContent(AssemblyParserService.GetProjectContentForReference(vbRef));
- }
MyNamespaceBuilder.BuildNamespace(this, pc);
return pc;
}
+ public override IEnumerable<ReferenceProjectItem> ResolveAssemblyReferences(CancellationToken cancellationToken)
+ {
+ ReferenceProjectItem[] additionalItems = {
+ new ReferenceProjectItem(this, "mscorlib"),
+ new ReferenceProjectItem(this, "Microsoft.VisualBasic"),
+ };
+ return MSBuildInternals.ResolveAssemblyReferences(this, additionalItems);
+ }
+
void InitVB()
{
reparseReferencesSensitiveProperties.Add("TargetFrameworkVersion");
View
6 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/GacReferencePanel.cs
@@ -378,8 +378,7 @@ void ResolveVersionsWorker()
}
});
- string mscorlibPath;
- MSBuildInternals.ResolveAssemblyReferences(project, referenceItems.ToArray(), out mscorlibPath);
+ MSBuildInternals.ResolveAssemblyReferences(project, referenceItems.ToArray(), resolveOnlyAdditionalReferences: true, logErrorsToOutputPad: false);
WorkbenchSingleton.SafeThreadAsyncCall(
delegate {
@@ -423,8 +422,7 @@ void CreateReferenceToFrameworkTable()
}
});
- string mscorlibPath;
- MSBuildInternals.ResolveAssemblyReferences(project, referenceItems.ToArray(), out mscorlibPath);
+ MSBuildInternals.ResolveAssemblyReferences(project, referenceItems.ToArray(), resolveOnlyAdditionalReferences: true, logErrorsToOutputPad: false);
foreach (ReferenceProjectItem rpi in referenceItems) {
if (string.IsNullOrEmpty(rpi.Redist)) continue;
if (!redistNameToRequiredFramework.ContainsKey(rpi.Redist)) {
View
23 src/Main/Base/Project/Src/Project/AbstractProject.cs
@@ -7,7 +7,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
-using System.Linq;
+using System.Threading;
using System.Xml.Linq;
using ICSharpCode.Core;
@@ -525,6 +525,27 @@ public virtual void ResolveAssemblyReferences()
{
}
+ public virtual IEnumerable<ReferenceProjectItem> ResolveAssemblyReferences(CancellationToken cancellationToken)
+ {
+ ResolveAssemblyReferences();
+ List<ReferenceProjectItem> referenceItems = new List<ReferenceProjectItem>();
+ bool mscorlib = false;
+ foreach (ProjectItem item in this.Items) {
+ cancellationToken.ThrowIfCancellationRequested();
+ if (ItemType.ReferenceItemTypes.Contains(item.ItemType)) {
+ ReferenceProjectItem reference = item as ReferenceProjectItem;
+ if (reference != null) {
+ referenceItems.Add(reference);
+ mscorlib |= "mscorlib".Equals(reference.Include, StringComparison.OrdinalIgnoreCase);
+ }
+ }
+ }
+ if (!mscorlib) {
+ referenceItems.Add(new ReferenceProjectItem(this, "mscorlib") { FileName = typeof(object).Module.FullyQualifiedName });
+ }
+ return referenceItems;
+ }
+
public virtual void StartBuild(ProjectBuildOptions options, IBuildFeedbackSink feedbackSink)
{
feedbackSink.ReportError(new BuildError { ErrorText = "Building project " + Name + " is not supported.", IsWarning = true });
View
18 src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs
@@ -8,6 +8,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Threading;
using System.Xml;
using System.Xml.Linq;
using ICSharpCode.Core;
@@ -137,21 +138,14 @@ public void PerformUpdateOnProjectFile(Action action)
}
}
- volatile string mscorlibPath;
-
- /// <summary>
- /// Gets the path to mscorlib.
- /// This property is set only after ResolveAssemblyReferences() is called.
- /// </summary>
- public string MscorlibPath {
- get { return mscorlibPath; }
+ public override void ResolveAssemblyReferences()
+ {
+ MSBuildInternals.ResolveAssemblyReferences(this);
}
- public override void ResolveAssemblyReferences()
+ public override IEnumerable<ReferenceProjectItem> ResolveAssemblyReferences(CancellationToken cancellationToken)
{
- string mscorlib;
- MSBuildInternals.ResolveAssemblyReferences(this, null, out mscorlib);
- this.mscorlibPath = mscorlib;
+ return MSBuildInternals.ResolveAssemblyReferences(this);
}
#region CreateProjectItem
View
83 src/Main/Base/Project/Src/Project/MSBuildInternals.cs
@@ -162,7 +162,10 @@ internal static PropertyStorageLocations GetLocationFromCondition(string conditi
/// <param name="baseProject">The base project.</param>
/// <param name="referenceReplacements">A different set of references to use instead of those in the project.
/// Used by the GacReferencePanel.</param>
- internal static void ResolveAssemblyReferences(MSBuildBasedProject baseProject, ReferenceProjectItem[] referenceReplacements, out string mscorlibPath)
+ public static IList<ReferenceProjectItem> ResolveAssemblyReferences(
+ MSBuildBasedProject baseProject,
+ ReferenceProjectItem[] additionalReferences = null, bool resolveOnlyAdditionalReferences = false,
+ bool logErrorsToOutputPad = true)
{
ProjectInstance project = baseProject.CreateProjectInstance();
project.SetProperty("BuildingProject", "false");
@@ -173,30 +176,35 @@ where ItemType.ReferenceItemTypes.Contains(new ItemType(item.ItemType))
select item
).ToList();
- ReferenceProjectItem[] referenceProjectItems;
+ List<ReferenceProjectItem> referenceProjectItems;
- if (referenceReplacements == null) {
- // Remove the "Private" meta data.
- // This is necessary to detect the default value for "Private"
+ if (resolveOnlyAdditionalReferences) {
+ // Remove existing references from project
foreach (ProjectItemInstance reference in references) {
- reference.RemoveMetadata("Private");
+ project.RemoveItem(reference);
}
-
- referenceProjectItems = baseProject.Items.OfType<ReferenceProjectItem>().ToArray();
+ references.Clear();
+ referenceProjectItems = new List<ReferenceProjectItem>();
} else {
+ // Remove the "Private" meta data.
+ // This is necessary to detect the default value for "Private"
foreach (ProjectItemInstance reference in references) {
- project.RemoveItem(reference);
+ reference.RemoveMetadata("Private");
}
- foreach (ReferenceProjectItem item in referenceReplacements) {
- project.AddItem("Reference", item.Include);
+ referenceProjectItems = baseProject.Items.OfType<ReferenceProjectItem>().ToList();
+ }
+
+ if (additionalReferences != null) {
+ referenceProjectItems.AddRange(additionalReferences);
+ foreach (ReferenceProjectItem item in additionalReferences) {
+ references.Add(project.AddItem("Reference", item.Include));
}
- referenceProjectItems = referenceReplacements;
}
string[] targets = { "ResolveAssemblyReferences" };
BuildRequestData requestData = new BuildRequestData(project, targets, new HostServices());
List<ILogger> loggers = new List<ILogger>();
- if (referenceReplacements == null)
+ if (logErrorsToOutputPad)
loggers.Add(new SimpleErrorLogger());
lock (SolutionProjectCollectionLock) {
BuildParameters parameters = new BuildParameters(baseProject.MSBuildProjectCollection);
@@ -209,32 +217,37 @@ select item
LoggingService.Debug("Build for ResolveAssemblyReferences finished: " + result.OverallResult);
}
- var referenceDict = new Dictionary<string, ReferenceProjectItem>();
- foreach (ReferenceProjectItem item in referenceProjectItems) {
- // references could be duplicate, so we cannot use referenceDict.Add or reference.ToDictionary
- referenceDict[item.Include] = item;
- }
+ IEnumerable<ProjectItemInstance> resolvedAssemblyProjectItems = project.GetItems("_ResolveAssemblyReferenceResolvedFiles");
- mscorlibPath = null;
- foreach (ProjectItemInstance item in project.GetItems("_ResolveAssemblyReferenceResolvedFiles")) {
- DomAssemblyName assemblyName = new DomAssemblyName(item.GetMetadataValue("FusionName"));
- string fullPath = FileUtility.GetAbsolutePath(baseProject.Directory, item.GetMetadataValue("Identity"));
-
- string originalInclude = item.GetMetadataValue("OriginalItemSpec");
- ReferenceProjectItem reference;
- if (referenceDict.TryGetValue(originalInclude, out reference)) {
- reference.AssemblyName = new Dom.DomAssemblyName(item.GetMetadataValue("FusionName"));
- reference.FileName = fullPath;
- reference.Redist = item.GetMetadataValue("Redist");
- LoggingService.Debug("Got information about " + originalInclude + "; fullpath=" + fullPath);
- reference.DefaultCopyLocalValue = bool.Parse(item.GetMetadataValue("CopyLocal"));
- } else if (string.Equals(assemblyName.ShortName, "mscorlib", StringComparison.OrdinalIgnoreCase)) {
- LoggingService.Debug("Got information for mscorlib: " + fullPath);
- mscorlibPath = fullPath;
+ var query =
+ from msbuildItem in resolvedAssemblyProjectItems
+ let originalInclude = msbuildItem.GetMetadataValue("OriginalItemSpec")
+ join item in referenceProjectItems on originalInclude equals item.Include into referenceItems
+ select new {
+ OriginalInclude = originalInclude,
+ AssemblyName = new DomAssemblyName(msbuildItem.GetMetadataValue("FusionName")),
+ FullPath = FileUtility.GetAbsolutePath(baseProject.Directory, msbuildItem.GetMetadataValue("Identity")),
+ Redist = msbuildItem.GetMetadataValue("Redist"),
+ CopyLocal = bool.Parse(msbuildItem.GetMetadataValue("CopyLocal")),
+ ReferenceItems = referenceItems
+ };
+ List<ReferenceProjectItem> resolvedAssemblies = new List<ReferenceProjectItem>();
+ foreach (var assembly in query) {
+ LoggingService.Debug("Got information about " + assembly.OriginalInclude + "; fullpath=" + assembly.FullPath);
+ foreach (var referenceItem in assembly.ReferenceItems) {
+ referenceItem.AssemblyName = assembly.AssemblyName;
+ referenceItem.FileName = assembly.FullPath;
+ referenceItem.Redist = assembly.Redist;
+ referenceItem.DefaultCopyLocalValue = assembly.CopyLocal;
+ }
+ ReferenceProjectItem firstItem = assembly.ReferenceItems.FirstOrDefault();
+ if (firstItem != null) {
+ resolvedAssemblies.Add(firstItem);
} else {
- LoggingService.Warn("Unknown item " + originalInclude);
+ resolvedAssemblies.Add(new ReferenceProjectItem(baseProject, assembly.OriginalInclude) { FileName = assembly.FullPath });
}
}
+ return resolvedAssemblies;
}
sealed class SimpleErrorLogger : ILogger
View
33 src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs
@@ -57,27 +57,23 @@ internal void Initialize1(IProgressMonitor progressMonitor)
UpdateDefaultImports(items);
// TODO: Translate me
// progressMonitor.TaskName = "Resolving references for " + project.Name + "...";
- project.ResolveAssemblyReferences();
- MSBuildBasedProject msbuildProject = project as MSBuildBasedProject;
- if (msbuildProject != null) {
- string mscorlib = msbuildProject.MscorlibPath;
- if (string.IsNullOrEmpty(mscorlib)) {
- AddReferencedContent(AssemblyParserService.DefaultProjectContentRegistry.Mscorlib);
- } else {
- AddReferencedContent(AssemblyParserService.DefaultProjectContentRegistry.GetProjectContentForReference("mscorlib", mscorlib));
+ AbstractProject abstractProject = project as AbstractProject;
+ if (abstractProject != null) {
+ foreach (var reference in abstractProject.ResolveAssemblyReferences(progressMonitor.CancellationToken)) {
+ if (!initializing) return; // abort initialization
+ AddReference(reference, false, progressMonitor.CancellationToken);
}
} else {
+ project.ResolveAssemblyReferences();
AddReferencedContent(AssemblyParserService.DefaultProjectContentRegistry.Mscorlib);
- }
- foreach (ProjectItem item in items) {
- if (!initializing) return; // abort initialization
- progressMonitor.CancellationToken.ThrowIfCancellationRequested();
- if (ItemType.ReferenceItemTypes.Contains(item.ItemType)) {
- ReferenceProjectItem reference = item as ReferenceProjectItem;
- if (reference != null) {
- // TODO: Translate me
-// progressMonitor.TaskName = "Loading " + reference.ShortName + "...";
- AddReference(reference, false, progressMonitor.CancellationToken);
+ foreach (ProjectItem item in items) {
+ if (!initializing) return; // abort initialization
+ progressMonitor.CancellationToken.ThrowIfCancellationRequested();
+ if (ItemType.ReferenceItemTypes.Contains(item.ItemType)) {
+ ReferenceProjectItem reference = item as ReferenceProjectItem;
+ if (reference != null) {
+ AddReference(reference, false, progressMonitor.CancellationToken);
+ }
}
}
}
@@ -116,6 +112,7 @@ void UpdateReferenceInterDependencies()
void AddReference(ReferenceProjectItem reference, bool updateInterDependencies, CancellationToken cancellationToken)
{
try {
+ cancellationToken.ThrowIfCancellationRequested();
AddReferencedContent(AssemblyParserService.GetProjectContentForReference(reference));
if (updateInterDependencies) {
UpdateReferenceInterDependencies();
Please sign in to comment.
Something went wrong with that request. Please try again.