Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): Allow using references for load test assembly dependecies #480

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions tests/CompletionEngineTests/XamlCompletionTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Avalonia.Ide.CompletionEngine;
using Avalonia.Ide.CompletionEngine.AssemblyMetadata;
using Avalonia.Ide.CompletionEngine.DnlibMetadataProvider;
Expand All @@ -21,16 +22,49 @@ public FolderAssemblyProvider(string path)

public IEnumerable<string> GetAssemblies()
{
if (Path.GetDirectoryName(_path) is not { } directory)
HashSet<string> result = new()
{
_path
};

if (Path.GetDirectoryName(_path) is { } directory)
{
return Array.Empty<string>();
}

var depsPath = Path.Combine(directory,
Path.GetFileNameWithoutExtension(_path) + ".deps.json");
if (File.Exists(depsPath))
return DepsJsonAssemblyListLoader.ParseFile(depsPath);
return Directory.GetFiles(directory).Where(f => f.EndsWith(".dll") || f.EndsWith(".exe"));
// Calculate Referernce path
var segments = directory.Split('\\', '/');
var avaloniaPathBuilder = new StringBuilder(1024);
foreach (var segment in segments)
{
if (string.Equals(segment, "bin", StringComparison.OrdinalIgnoreCase))
{
avaloniaPathBuilder.Append("obj");
}
else
{
avaloniaPathBuilder.Append(segment);
}
avaloniaPathBuilder.Append(Path.DirectorySeparatorChar);
}
avaloniaPathBuilder.Append("Avalonia");
avaloniaPathBuilder.Append(Path.DirectorySeparatorChar);

var referencePath = Path.Combine(avaloniaPathBuilder.ToString(), "references");
var depsPath = Path.Combine(directory,
Path.GetFileNameWithoutExtension(_path) + ".deps.json");

var files = File.Exists(referencePath)
? File.ReadAllLines(referencePath)
: (File.Exists(depsPath)
? DepsJsonAssemblyListLoader.ParseFile(depsPath)
: Directory.GetFiles(directory).Where(f => f.EndsWith(".dll") || f.EndsWith(".exe"))
);

foreach (var file in files)
{
result.Add(file);
}
}
return result;
}
}

Expand Down