From 8f8e946d06b498623dace5132e22399b1f3afa1b Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Tue, 30 Jan 2024 19:00:44 +0100 Subject: [PATCH 1/3] fix: Intellisense does not show internal member --- .../Views/AvaloniaDesigner.xaml.cs | 5 +++-- .../DnlibMetadataProvider.cs | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs b/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs index 06973bae..6454c91c 100644 --- a/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs +++ b/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs @@ -554,7 +554,7 @@ private void RebuildMetadata(string assemblyPath) string intermediateOutputPath = GetIntermediateOutputPath(storage); if (metadata.CompletionMetadata == null || metadata.NeedInvalidation) { - CreateCompletionMetadataAsync(intermediateOutputPath, metadata).FireAndForget(); + CreateCompletionMetadataAsync(intermediateOutputPath, assemblyPath, metadata).FireAndForget(); } } } @@ -563,6 +563,7 @@ private void RebuildMetadata(string assemblyPath) private static async Task CreateCompletionMetadataAsync( string intermediateOutputPath, + string xamlAssemblyPath, XamlBufferMetadata target) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); @@ -587,7 +588,7 @@ private static async Task CreateCompletionMetadataAsync( { metadataLoad = Task.Run(() => { - var metadataReader = new MetadataReader(new DnlibMetadataProvider()); + var metadataReader = new MetadataReader(new DnlibMetadataProvider(xamlAssemblyPath)); return metadataReader.GetForTargetAssembly(new AvaloniaCompilationAssemblyProvider(intermediateOutputPath)); }); _metadataCache[intermediateOutputPath] = metadataLoad; diff --git a/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs b/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs index 1726a5a3..684fba5a 100644 --- a/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs +++ b/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs @@ -9,10 +9,27 @@ namespace Avalonia.Ide.CompletionEngine.DnlibMetadataProvider; public class DnlibMetadataProvider : IMetadataProvider { + private readonly string? _xamlAssemblyPath; + + public DnlibMetadataProvider() : this(null) + { + + } + + public DnlibMetadataProvider(string? xamlAssemblyPath) + { + _xamlAssemblyPath = xamlAssemblyPath; + } public IMetadataReaderSession GetMetadata(IEnumerable paths) { - return new DnlibMetadataProviderSession(paths.ToArray()); + var list = new List(); + if (!string.IsNullOrWhiteSpace(_xamlAssemblyPath)) + { + list.Add(_xamlAssemblyPath); + } + list.AddRange(paths); + return new DnlibMetadataProviderSession(list.ToArray()); } } From 549bc9fb34ddaedbcf6ffc001e1091d723225312 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Fri, 29 Mar 2024 11:24:09 +0100 Subject: [PATCH 2/3] fix: Address review --- AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs | 4 ++-- .../AvaloniaCompilationAssemblyProvider.cs | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs b/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs index b8595418..6b1d9f09 100644 --- a/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs +++ b/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs @@ -565,6 +565,7 @@ private void RebuildMetadata(string assemblyPath) } private static Dictionary> _metadataCache; + private static readonly MetadataReader _metadataReader = new(new DnlibMetadataProvider()); private static async Task CreateCompletionMetadataAsync( string intermediateOutputPath, @@ -593,8 +594,7 @@ private static async Task CreateCompletionMetadataAsync( { metadataLoad = Task.Run(() => { - var metadataReader = new MetadataReader(new DnlibMetadataProvider(xamlAssemblyPath)); - return metadataReader.GetForTargetAssembly(new AvaloniaCompilationAssemblyProvider(intermediateOutputPath)); + return _metadataReader.GetForTargetAssembly(new AvaloniaCompilationAssemblyProvider(intermediateOutputPath, xamlAssemblyPath)); }); _metadataCache[intermediateOutputPath] = metadataLoad; } diff --git a/CompletionEngine/Avalonia.Ide.CompletionEngine/AssemblyMetadata/AvaloniaCompilationAssemblyProvider.cs b/CompletionEngine/Avalonia.Ide.CompletionEngine/AssemblyMetadata/AvaloniaCompilationAssemblyProvider.cs index af12401d..05741c7f 100644 --- a/CompletionEngine/Avalonia.Ide.CompletionEngine/AssemblyMetadata/AvaloniaCompilationAssemblyProvider.cs +++ b/CompletionEngine/Avalonia.Ide.CompletionEngine/AssemblyMetadata/AvaloniaCompilationAssemblyProvider.cs @@ -7,6 +7,7 @@ namespace Avalonia.Ide.CompletionEngine.AssemblyMetadata public class AvaloniaCompilationAssemblyProvider : IAssemblyProvider { private readonly string _path; + private readonly string _xamlPrimaryAssemblyPath; /// /// Create a new instance of —an implementation of . @@ -22,12 +23,14 @@ public class AvaloniaCompilationAssemblyProvider : IAssemblyProvider /// - C:\Repos\RepoRoot\src\artifacts\obj\MyApp\debug_net8.0\Avalonia\references
/// See Artifacts output layout > Examples for more 'artifacts' path examples. /// + /// Promary XAML Assembly path /// is null or empty - public AvaloniaCompilationAssemblyProvider(string path) + public AvaloniaCompilationAssemblyProvider(string path, string xamlPrimaryAssemblyPath) { if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path)); _path = path; + _xamlPrimaryAssemblyPath = xamlPrimaryAssemblyPath; } /// @@ -37,9 +40,14 @@ public AvaloniaCompilationAssemblyProvider(string path) /// Failed to read the project's references file. public IEnumerable GetAssemblies() { + List result = new List(300); + if (!string.IsNullOrEmpty(_xamlPrimaryAssemblyPath)) + { + result.Add(_xamlPrimaryAssemblyPath); + } try { - return File.ReadAllText(_path).Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); + result.AddRange(File.ReadAllLines(_path)); } catch (Exception ex) when (ex is DirectoryNotFoundException || ex is FileNotFoundException) @@ -50,6 +58,7 @@ public IEnumerable GetAssemblies() { throw new IOException($"Failed to read file '{_path}'.", ex); } + return result; } } } From 4259920df4113deb068cb53d10eeb9fd6d94aae0 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Thu, 4 Apr 2024 17:26:46 +0200 Subject: [PATCH 3/3] fix: Address review --- .../DnlibMetadataProvider.cs | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs b/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs index 2e0ac25b..6dfa35d3 100644 --- a/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs +++ b/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs @@ -9,27 +9,9 @@ namespace Avalonia.Ide.CompletionEngine.DnlibMetadataProvider; public class DnlibMetadataProvider : IMetadataProvider { - private readonly string? _xamlAssemblyPath; - - public DnlibMetadataProvider() : this(null) - { - - } - - public DnlibMetadataProvider(string? xamlAssemblyPath) - { - _xamlAssemblyPath = xamlAssemblyPath; - } - public IMetadataReaderSession GetMetadata(IEnumerable paths) { - var list = new List(); - if (!string.IsNullOrWhiteSpace(_xamlAssemblyPath)) - { - list.Add(_xamlAssemblyPath); - } - list.AddRange(paths); - return new DnlibMetadataProviderSession(list.ToArray()); + return new DnlibMetadataProviderSession(paths.ToArray()); } }