AvaloniaUI / AvaloniaVS

Visual Studio Extension for Avalonia
MIT License
412 stars 77 forks source link

[DevTools] Copy Selector replace Clr Namespace with xmlns #448

Closed workgroupengineering closed 2 months ago

workgroupengineering commented 5 months ago

Is your feature request related to a problem? Please describe.

Speed up writing a Style Selector. When Copy Selector using [DevTools] treeview context menu, it put text like this in clipboard:

FluentAvalonia.UI.Controls.NavigationView#NavView.Store /template/ Avalonia.Controls.ScrollViewer#FooterItemsScrollViewer

Describe the solution you'd like

When Copy Selector using [DevTools] treeview context menu it put text like this in clipboard:

ui|NavigationView#NavView.Store /template/ ScrollViewer#FooterItemsScrollViewer

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

maxkatz6 commented 5 months ago

Probably better to just ignore namespace, so IDE can autocomplete it. As otherwise we don't really have this information in runtime, I don't think so.

workgroupengineering commented 5 months ago

As otherwise we don't really have this information in runtime, I don't think so.

IAvaloniaXamlIlXmlNamespaceInfoProvider can be used. But at the moment I haven't found a way to access the TopLevel's IServiceProvider through the DevTools. @maxkatz6 Do you have any idea how to do it?

maxkatz6 commented 5 months ago

IAvaloniaXamlIlXmlNamespaceInfoProvider

It will tell namespace information only for current XAML file. Not where this control was defined.

workgroupengineering commented 5 months ago

It will tell namespace information only for current XAML file. Not where this control was defined.

I think that's right.

I was thinking that instead of IAvaloniaXamlIlXmlNamespaceInfoProvider when the DevTools is referenced, a Source Generator creates a class that maps the namespaces for each xaml/axaml.

kekekeks commented 5 months ago

It would have to be saved for every single control, since devtools has no way to know where a control was defined.

workgroupengineering commented 5 months ago

It would have to be saved for every single control, since devtools has no way to know where a control was defined. You don't need every check, but only for every xaml/axaml.

I would like to define an interface similar to this:

interface IDevToolsNamespaceInfoProvider
{
     string? GetXmlNamespaceFromType(Type type);
}

The source generator will implement this interface for each axaml.

When Copy Selector is activated, the first parent that implements the interface IDevToolsNamespaceInfoProvider will be searched.

I just know it's not perfect. It cannot retrieve the namespace of second-level dependencies, but this solution is simple to implement.

another possibility could be to using reference assemblies where there would be additional metadata with information on namspaces. This solution would also solve the problem of retrieving third-party control dependency information because the reference assemblies would be distributed in the nuget package.

maxkatz6 commented 5 months ago

How would it help with situation, when selector is copied into another file with different namespaces? That's why I think it might be the easiest to skip them and allow IDE extension to handle that.

maxkatz6 commented 5 months ago

The source generator will implement this interface for each axaml.

Cecil task has some information, which could be aggregated and loosely used in devtools. I.e. emit an extra class that would return an enumerable of all IAvaloniaXamlIlXmlNamespaceInfoProvider in the assembly. Or you actually already can do it via reflection to get all types with IAvaloniaXamlIlXmlNamespaceInfoProvider. Since dev tools are usually used in Debug with no trimming.

But again, it might not worth the time spent on it: image

workgroupengineering commented 5 months ago

Can someone move this issue to Avalonia VS?

timunie commented 5 months ago

@workgroupengineering transferred as requested