AvaloniaVSCode
AvaloniaVSCode copied to clipboard
AssemblyName is not supported by auto-completion
Describe the bug
If AssemblyName is set in the project file, XAML auto-completion will always show "Build the project" item.
To Reproduce
- Create a new project (in any way you like)
- Make sure XAML completion works.
- Add
AssemblyNameproperty to the .csproj file. - XAML completion will only show "Build the project"
Avalonia for VS Code
0e1f108 (custom build)
Avalonia version
11.0.13
VS Code version
1.95.1
Relevant log output
2024-11-02 14:31:10.123 [info] [Trace - 2:31:10 PM] Sending request 'textDocument/completion - (25)'.
2024-11-02 14:31:10.127 [info] [Trace - 2:31:10 PM] Received response 'textDocument/completion - (25)' in 5ms.
Additional context
This is caused by this code. The DLL path is hardcoded here to use the project name. SolutionParser should be improved to additionally output AssemblyName property value.
https://github.com/AvaloniaUI/AvaloniaVSCode/blob/0e1f108300b3a28f86ba2af5379c4e3f10398ac8/src/AvaloniaLSP/AvaloniaLanguageServer/Models/ProjectInfo.cs#L52-L65
Use case for AssemblyName: project name is the full name with namespace, while AssemblyName is set to a user-friendly name for the EXE file.
I spent hours until I found this issue. It should be fixed. I Add some code to deal with OutDir and AssemblyName:
using System.Xml.Linq;
public string AssemblyPath()
{
string? path = string.Empty;
XDocument project = XDocument.Load(ProjectPath);
XElement? outDirElement = project.Descendants("PropertyGroup").Descendants("OutDir").FirstOrDefault();
string outDir = outDirElement?.Value ?? Path.Combine("bin", "Debug");
string debugPath = Path.Combine(ProjectDirectory, outDir);
XElement? assemblyNameElement = project.Descendants("PropertyGroup").Descendants("AssemblyName").FirstOrDefault();
string assemblyName = assemblyNameElement?.Value ?? Path.GetFileNameWithoutExtension(ProjectPath);
if (Directory.Exists(debugPath))
{
path = Directory.GetFiles(debugPath, assemblyName + ".dll", SearchOption.AllDirectories).FirstOrDefault();
}
return path ?? string.Empty;
}
I use NetBeauty to group all dll files into a sub directory, then the auto-completion failed again.
Can be fixed by add some code in src\AvaloniaVS\CompletionEngine\Avalonia.Ide.CompletionEngine\AssemblyMetadata\DepsJsonAssemblyListLoader.cs, ParseFile():
foreach (var l in TransformDeps(deps.RootElement.GetProperty("targets").GetProperty(target)))
{
var localPath = Path.Combine(dir, l.DllName);
if (File.Exists(localPath))
{
yield return localPath;
continue;
}
// Begin
foreach (var subDir in new[] { "libraries", "libs", "lib" })
{
localPath = Path.Combine(dir, subDir, l.DllName);
if (File.Exists(localPath))
{
yield return localPath;
continue;
}
}
// End
foreach (var nugetPath in nugetDirs)
I've been trying to figure out what the problem for weeks. I was already thinking of switching back from VSCode to Visual Studio just to be able to support application development. What's also strange is that while сode completion didn't work, previewer saw the binaries perfectly and displayed them.
Some autocompletion bug fixes were added in this fork, https://marketplace.visualstudio.com/items?itemName=lextudio.vscode-axaml