Browse Source

Keep ITextEditor in the IDE (comment out the copy in ICSharpCode.Editor)

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
5633492481
  1. 2
      src/Libraries/NRefactory/ICSharpCode.Editor/ITextEditor.cs
  2. 14
      src/Libraries/NRefactory/ICSharpCode.NRefactory/Documentation/XmlDocumentationProvider.cs
  3. 8
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  4. 10
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs
  5. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedEvent.cs
  6. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedField.cs
  7. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedMethod.cs
  8. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedProperty.cs
  9. 2
      src/Main/Base/Project/Src/Editor/ITextEditor.cs
  10. 2
      src/Main/Base/Project/Src/Editor/Search/ProvidedDocumentInformation.cs
  11. 2
      src/Main/Base/Project/Src/Gui/Dialogs/ExtractInterfaceDialog.Designer.cs
  12. 256
      src/Main/Base/Project/Src/Services/ParserService/AssemblyParserService.cs

2
src/Libraries/NRefactory/ICSharpCode.Editor/ITextEditor.cs

@ -7,6 +7,7 @@ using System.Threading.Tasks; @@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace ICSharpCode.Editor
{
/*
/// <summary>
/// Interface for text editors.
/// </summary>
@ -64,6 +65,7 @@ namespace ICSharpCode.Editor @@ -64,6 +65,7 @@ namespace ICSharpCode.Editor
/// </remarks>
// Task<bool> ShowLinkedElements(IEnumerable<LinkedElement> linkedElements);
}
*/
/// <summary>
/// Represents the caret in a text editor.

14
src/Libraries/NRefactory/ICSharpCode.NRefactory/Documentation/XmlDocumentationProvider.cs

@ -90,7 +90,8 @@ namespace ICSharpCode.NRefactory.Documentation @@ -90,7 +90,8 @@ namespace ICSharpCode.NRefactory.Documentation
if (fileName == null)
throw new ArgumentNullException("fileName");
using (XmlTextReader xmlReader = new XmlTextReader(fileName)) {
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) {
using (XmlTextReader xmlReader = new XmlTextReader(fs)) {
xmlReader.XmlResolver = null; // no DTD resolving
xmlReader.MoveToContent();
if (string.IsNullOrEmpty(xmlReader.GetAttribute("redirect"))) {
@ -100,16 +101,19 @@ namespace ICSharpCode.NRefactory.Documentation @@ -100,16 +101,19 @@ namespace ICSharpCode.NRefactory.Documentation
string redirectionTarget = GetRedirectionTarget(xmlReader.GetAttribute("redirect"));
if (redirectionTarget != null) {
Debug.WriteLine("XmlDoc " + fileName + " is redirecting to " + redirectionTarget);
using (XmlTextReader redirectedXmlReader = new XmlTextReader(redirectionTarget)) {
using (FileStream redirectedFs = new FileStream(redirectionTarget, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) {
using (XmlTextReader redirectedXmlReader = new XmlTextReader(redirectedFs)) {
this.fileName = redirectionTarget;
ReadXmlDoc(redirectedXmlReader);
}
}
} else {
throw new XmlException("XmlDoc " + fileName + " is redirecting to " + xmlReader.GetAttribute("redirect") + ", but that file was not found.");
}
}
}
}
}
private XmlDocumentationProvider(string fileName, DateTime lastWriteDate, IndexEntry[] index)
{
@ -138,7 +142,11 @@ namespace ICSharpCode.NRefactory.Documentation @@ -138,7 +142,11 @@ namespace ICSharpCode.NRefactory.Documentation
return dir + Path.DirectorySeparatorChar;
}
internal static string LookupLocalizedXmlDoc(string fileName)
/// <summary>
/// Given the assembly file name, looks up the XML documentation file name.
/// Returns null if no XML documentation file is found.
/// </summary>
public static string LookupLocalizedXmlDoc(string fileName)
{
string xmlFileName = Path.ChangeExtension(fileName, ".xml");
string currentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;

8
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -8,6 +8,7 @@ using System.Diagnostics; @@ -8,6 +8,7 @@ using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using Mono.Cecil;
@ -44,6 +45,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -44,6 +45,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </summary>
public IInterningProvider InterningProvider { get; set; }
/// <summary>
/// Gets/Sets the cancellation token used by the cecil loader.
/// </summary>
public CancellationToken CancellationToken { get; set; }
/// <summary>
/// Gets a value indicating whether this instance stores references to the cecil objects.
/// </summary>
@ -91,6 +97,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -91,6 +97,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
List<CecilTypeDefinition> types = new List<CecilTypeDefinition>();
foreach (ModuleDefinition module in assemblyDefinition.Modules) {
foreach (TypeDefinition td in module.Types) {
this.CancellationToken.ThrowIfCancellationRequested();
if (this.IncludeInternalMembers || (td.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public) {
string name = td.FullName;
if (name.Length == 0 || name[0] == '<')
@ -719,6 +726,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -719,6 +726,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
public void Init(CecilLoader loader)
{
loader.CancellationToken.ThrowIfCancellationRequested();
InitModifiers();
if (typeDefinition.HasGenericParameters) {

10
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs

@ -265,7 +265,15 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -265,7 +265,15 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
public virtual string Documentation {
get { return null; }
get {
// To save memory, we don't store the documentation provider within the type,
// but use our the project content as a documentation provider:
IDocumentationProvider provider = projectContent as IDocumentationProvider;
if (provider != null)
return provider.GetDocumentation(this);
else
return null;
}
}
public Accessibility Accessibility {

4
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedEvent.cs

@ -33,6 +33,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -33,6 +33,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return memberDefinition; }
}
public override string Documentation {
get { return memberDefinition.Documentation; }
}
public override int GetHashCode()
{
int hashCode = 0;

4
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedField.cs

@ -33,6 +33,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -33,6 +33,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return memberDefinition; }
}
public override string Documentation {
get { return memberDefinition.Documentation; }
}
public override int GetHashCode()
{
int hashCode = 0;

4
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedMethod.cs

@ -33,6 +33,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -33,6 +33,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return memberDefinition; }
}
public override string Documentation {
get { return memberDefinition.Documentation; }
}
public override int GetHashCode()
{
int hashCode = 0;

4
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedProperty.cs

@ -33,6 +33,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -33,6 +33,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return memberDefinition; }
}
public override string Documentation {
get { return memberDefinition.Documentation; }
}
public override int GetHashCode()
{
int hashCode = 0;

2
src/Main/Base/Project/Src/Editor/ITextEditor.cs

@ -19,7 +19,6 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -19,7 +19,6 @@ namespace ICSharpCode.SharpDevelop.Editor
}
}
/*
/// <summary>
/// Interface for text editors.
/// </summary>
@ -120,7 +119,6 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -120,7 +119,6 @@ namespace ICSharpCode.SharpDevelop.Editor
/// </summary>
IEnumerable<ICompletionItem> GetSnippets();
}
*/
public interface ITextEditorOptions : INotifyPropertyChanged
{

2
src/Main/Base/Project/Src/Editor/Search/ProvidedDocumentInformation.cs

@ -47,7 +47,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search @@ -47,7 +47,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
}
set {
if (textEditor != null) {
textEditor.Caret.Position = document.OffsetToPosition(value + 1);
textEditor.Caret.Location = document.GetLocation(value);
} else {
currentOffset = value;
}

2
src/Main/Base/Project/Src/Gui/Dialogs/ExtractInterfaceDialog.Designer.cs generated

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
namespace ICSharpCode.SharpDevelop.Gui
{
/*
partial class ExtractInterfaceDialog : System.Windows.Forms.Form
{
/// <summary>
@ -267,4 +268,5 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -267,4 +268,5 @@ namespace ICSharpCode.SharpDevelop.Gui
private System.Windows.Forms.TextBox txtInterfaceName;
private System.Windows.Forms.Label lblInterfaceName;
}
*/
}

256
src/Main/Base/Project/Src/Services/ParserService/AssemblyParserService.cs

@ -3,10 +3,15 @@ @@ -3,10 +3,15 @@
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using System.IO;
//using RegistryContentPair = System.Collections.Generic.KeyValuePair<ICSharpCode.SharpDevelop.Dom.ProjectContentRegistry, ICSharpCode.SharpDevelop.Dom.IProjectContent>;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.NRefactory.Documentation;
using ICSharpCode.NRefactory.TypeSystem;
using Mono.Cecil;
namespace ICSharpCode.SharpDevelop
{
@ -15,151 +20,172 @@ namespace ICSharpCode.SharpDevelop @@ -15,151 +20,172 @@ namespace ICSharpCode.SharpDevelop
/// </summary>
public static class AssemblyParserService
{
/*
static IList<ProjectContentRegistryDescriptor> registries;
static ProjectContentRegistry defaultProjectContentRegistry = new ProjectContentRegistry();
static string domPersistencePath;
#region Get Assembly By File Name
sealed class LoadedAssembly
{
public readonly Task<IProjectContent> ProjectContent;
public readonly DateTime AssemblyFileLastWriteTime;
internal static void Initialize()
public LoadedAssembly(Task<IProjectContent> projectContent, DateTime assemblyFileLastWriteTime)
{
if (registries == null) {
registries = AddInTree.BuildItems<ProjectContentRegistryDescriptor>("/Workspace/ProjectContentRegistry", null, false);
if (!string.IsNullOrEmpty(domPersistencePath)) {
Directory.CreateDirectory(domPersistencePath);
defaultProjectContentRegistry.ActivatePersistence(domPersistencePath);
}
this.ProjectContent = projectContent;
this.AssemblyFileLastWriteTime = assemblyFileLastWriteTime;
}
}
/// <summary>
/// Gets/Sets the cache directory used for DOM persistence.
/// </summary>
public static string DomPersistencePath {
get {
return domPersistencePath;
}
set {
if (registries != null)
throw new InvalidOperationException("Cannot set DomPersistencePath after ParserService was initialized");
domPersistencePath = value;
}
static Dictionary<FileName, WeakReference> projectContentDictionary = new Dictionary<FileName, WeakReference>();
[ThreadStatic] static Dictionary<FileName, LoadedAssembly> up2dateProjectContents;
public static IProjectContent GetAssembly(FileName fileName, CancellationToken cancellationToken = default(CancellationToken))
{
bool isNewTask;
LoadedAssembly asm = GetLoadedAssembly(fileName, cancellationToken, out isNewTask);
if (isNewTask)
asm.ProjectContent.RunSynchronously();
return asm.ProjectContent.Result;
}
public static ProjectContentRegistry DefaultProjectContentRegistry {
get {
return defaultProjectContentRegistry;
public static Task<IProjectContent> GetAssemblyAsync(FileName fileName, CancellationToken cancellationToken = default(CancellationToken))
{
bool isNewTask;
LoadedAssembly asm = GetLoadedAssembly(fileName, cancellationToken, out isNewTask);
if (isNewTask)
asm.ProjectContent.Start();
return asm.ProjectContent;
}
/// <summary>
/// "using (AssemblyParserService.AvoidRedundantChecks())"
/// Within the using block, the AssemblyParserService will only check once per assembly if the
/// existing cached project content (if any) is up to date.
/// Any additional accesses will return that cached project content without causing an update check.
/// This applies only to the thread that called AvoidRedundantChecks() - other threads will
/// perform update checks as usual.
/// </summary>
public static IDisposable AvoidRedundantChecks()
{
if (up2dateProjectContents != null)
return null;
up2dateProjectContents = new Dictionary<FileName, LoadedAssembly>();
return new CallbackOnDispose(delegate { up2dateProjectContents = null; });
}
public static ProjectContentRegistry GetRegistryForReference(ReferenceProjectItem item)
static LoadedAssembly GetLoadedAssembly(FileName fileName, CancellationToken cancellationToken, out bool isNewTask)
{
if (item is ProjectReferenceProjectItem || item.Project == null) {
return defaultProjectContentRegistry;
}
foreach (ProjectContentRegistryDescriptor registry in registries) {
if (registry.UseRegistryForProject(item.Project)) {
ProjectContentRegistry r = registry.Registry;
if (r != null) {
return r;
} else {
return defaultProjectContentRegistry; // fallback when registry class not found
isNewTask = false;
LoadedAssembly asm;
if (up2dateProjectContents != null) {
if (up2dateProjectContents.TryGetValue(fileName, out asm))
return asm;
}
DateTime lastWriteTime = File.GetLastWriteTimeUtc(fileName);
lock (projectContentDictionary) {
WeakReference wr;
if (projectContentDictionary.TryGetValue(fileName, out wr)) {
asm = (LoadedAssembly)wr.Target;
if (asm != null && asm.AssemblyFileLastWriteTime == lastWriteTime) {
return asm;
}
} else {
wr = null;
}
var task = new Task<IProjectContent>(() => LoadAssembly(fileName, cancellationToken), cancellationToken);
task.Wait();
isNewTask = true;
asm = new LoadedAssembly(task, lastWriteTime);
if (wr != null) {
wr.Target = asm;
} else {
wr = new WeakReference(asm);
projectContentDictionary.Add(fileName, wr);
}
return asm;
}
return defaultProjectContentRegistry;
}
#endregion
public static IProjectContent GetExistingProjectContentForReference(ReferenceProjectItem item)
#region Load Assembly + XML documentation
static IProjectContent LoadAssembly(string fileName, CancellationToken cancellationToken)
{
if (item is ProjectReferenceProjectItem) {
if (((ProjectReferenceProjectItem)item).ReferencedProject == null)
var param = new ReaderParameters();
param.AssemblyResolver = new DummyAssemblyResolver();
AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(fileName, param);
CecilLoader l = new CecilLoader();
string xmlDocFile = FindXmlDocumentation(fileName, asm.MainModule.Runtime);
if (xmlDocFile != null) {
try {
l.DocumentationProvider = new XmlDocumentationProvider(xmlDocFile);
} catch (XmlException ex) {
LoggingService.Warn("Ignoring error while reading xml doc from " + xmlDocFile, ex);
} catch (IOException ex) {
LoggingService.Warn("Ignoring error while reading xml doc from " + xmlDocFile, ex);
} catch (UnauthorizedAccessException ex) {
LoggingService.Warn("Ignoring error while reading xml doc from " + xmlDocFile, ex);
}
}
l.InterningProvider = new SimpleInterningProvider();
l.CancellationToken = cancellationToken;
return l.LoadAssembly(asm);
}
// used to prevent Cecil from loading referenced assemblies
sealed class DummyAssemblyResolver : IAssemblyResolver
{
public AssemblyDefinition Resolve(AssemblyNameReference name)
{
return null;
}
return ParserService.GetProjectContent(((ProjectReferenceProjectItem)item).ReferencedProject);
}
return GetRegistryForReference(item).GetExistingProjectContent(item.FileName);
}
public static IProjectContent GetProjectContentForReference(ReferenceProjectItem item)
{
if (item is ProjectReferenceProjectItem) {
if (((ProjectReferenceProjectItem)item).ReferencedProject == null)
public AssemblyDefinition Resolve(string fullName)
{
return null;
}
return ParserService.GetProjectContent(((ProjectReferenceProjectItem)item).ReferencedProject);
}
return GetRegistryForReference(item).GetProjectContentForReference(item.Include, item.FileName);
}
/// <summary>
/// Refreshes the project content for the specified reference if required.
/// This method does nothing if the reference is not an assembly reference, is not loaded or already is up-to-date.
/// </summary>
public static void RefreshProjectContentForReference(ReferenceProjectItem item)
public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
{
if (item is ProjectReferenceProjectItem) {
return;
}
ProjectContentRegistry registry = GetRegistryForReference(item);
registry.RunLocked(
delegate {
IProjectContent rpc = GetExistingProjectContentForReference(item);
if (rpc == null) {
LoggingService.Debug("RefreshProjectContentForReference: not refreshing (rpc==null) " + item.FileName);
return;
}
if (rpc.IsUpToDate) {
LoggingService.Debug("RefreshProjectContentForReference: not refreshing (rpc.IsUpToDate) " + item.FileName);
return;
}
LoggingService.Debug("RefreshProjectContentForReference " + item.FileName);
HashSet<IProject> projectsToRefresh = new HashSet<IProject>();
HashSet<IProjectContent> unloadedReferenceContents = new HashSet<IProjectContent>();
UnloadReferencedContent(projectsToRefresh, unloadedReferenceContents, registry, rpc);
foreach (IProject p in projectsToRefresh) {
ParserService.Reparse(p, true, false);
}
});
return null;
}
static void UnloadReferencedContent(HashSet<IProject> projectsToRefresh, HashSet<IProjectContent> unloadedReferenceContents, ProjectContentRegistry referencedContentRegistry, IProjectContent referencedContent)
public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters)
{
LoggingService.Debug("Unload referenced content " + referencedContent);
List<RegistryContentPair> otherContentsToUnload = new List<RegistryContentPair>();
foreach (ProjectContentRegistryDescriptor registry in registries) {
if (registry.IsRegistryLoaded) {
foreach (IProjectContent pc in registry.Registry.GetLoadedProjectContents()) {
if (pc.ReferencedContents.Contains(referencedContent)) {
if (unloadedReferenceContents.Add(pc)) {
LoggingService.Debug("Mark dependent content for unloading " + pc);
otherContentsToUnload.Add(new RegistryContentPair(registry.Registry, pc));
}
}
}
}
}
foreach (IProjectContent pc in ParserService.AllProjectContents) {
IProject project = (IProject)pc.Project;
if (projectsToRefresh.Contains(project))
continue;
if (pc.ReferencedContents.Remove(referencedContent)) {
LoggingService.Debug("UnloadReferencedContent: Mark project for reparsing " + project.Name);
projectsToRefresh.Add(project);
return null;
}
}
foreach (RegistryContentPair pair in otherContentsToUnload) {
UnloadReferencedContent(projectsToRefresh, unloadedReferenceContents, pair.Key, pair.Value);
}
static readonly string referenceAssembliesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Reference Assemblies\Microsoft\\Framework");
static readonly string frameworkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework");
referencedContentRegistry.UnloadProjectContent(referencedContent);
static string FindXmlDocumentation(string assemblyFileName, TargetRuntime runtime)
{
string fileName;
switch (runtime) {
case TargetRuntime.Net_1_0:
fileName = LookupLocalizedXmlDoc(Path.Combine(frameworkPath, "v1.0.3705", assemblyFileName));
break;
case TargetRuntime.Net_1_1:
fileName = LookupLocalizedXmlDoc(Path.Combine(frameworkPath, "v1.1.4322", assemblyFileName));
break;
case TargetRuntime.Net_2_0:
fileName = LookupLocalizedXmlDoc(Path.Combine(frameworkPath, "v2.0.50727", assemblyFileName))
?? LookupLocalizedXmlDoc(Path.Combine(referenceAssembliesPath, "v3.5"))
?? LookupLocalizedXmlDoc(Path.Combine(referenceAssembliesPath, "v3.0"))
?? LookupLocalizedXmlDoc(Path.Combine(referenceAssembliesPath, @".NETFramework\v3.5\Profile\Client"));
break;
case TargetRuntime.Net_4_0:
default:
fileName = LookupLocalizedXmlDoc(Path.Combine(referenceAssembliesPath, @".NETFramework\v4.0", assemblyFileName))
?? LookupLocalizedXmlDoc(Path.Combine(frameworkPath, "v4.0.30319", assemblyFileName));
break;
}
return fileName;
}
static string LookupLocalizedXmlDoc(string fileName)
{
return XmlDocumentationProvider.LookupLocalizedXmlDoc(fileName);
}
*/
#endregion
}
}

Loading…
Cancel
Save