diff --git a/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs b/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs index ca8b8c20..6b1d9f09 100644 --- a/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs +++ b/AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs @@ -559,15 +559,17 @@ private void RebuildMetadata(string assemblyPath) string intermediateOutputPath = GetIntermediateOutputPath(storage); if (metadata.CompletionMetadata == null || metadata.NeedInvalidation) { - CreateCompletionMetadataAsync(intermediateOutputPath, metadata).FireAndForget(); + CreateCompletionMetadataAsync(intermediateOutputPath, assemblyPath, metadata).FireAndForget(); } } } private static Dictionary> _metadataCache; + private static readonly MetadataReader _metadataReader = new(new DnlibMetadataProvider()); private static async Task CreateCompletionMetadataAsync( string intermediateOutputPath, + string xamlAssemblyPath, XamlBufferMetadata target) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); @@ -592,8 +594,7 @@ private static async Task CreateCompletionMetadataAsync( { metadataLoad = Task.Run(() => { - var metadataReader = new MetadataReader(new DnlibMetadataProvider()); - return metadataReader.GetForTargetAssembly(new AvaloniaCompilationAssemblyProvider(intermediateOutputPath)); + return _metadataReader.GetForTargetAssembly(new AvaloniaCompilationAssemblyProvider(intermediateOutputPath, xamlAssemblyPath)); }); _metadataCache[intermediateOutputPath] = metadataLoad; } diff --git a/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs b/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs index a3388649..6dfa35d3 100644 --- a/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs +++ b/CompletionEngine/Avalonia.Ide.CompletionEngine.DnlibMetadataProvider/DnlibMetadataProvider.cs @@ -9,7 +9,6 @@ namespace Avalonia.Ide.CompletionEngine.DnlibMetadataProvider; public class DnlibMetadataProvider : IMetadataProvider { - public IMetadataReaderSession GetMetadata(IEnumerable paths) { return new DnlibMetadataProviderSession(paths.ToArray()); 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; } } }