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

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

Closed
workgroupengineering opened this issue Feb 9, 2024 · 10 comments · Fixed by #470
Closed

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

workgroupengineering opened this issue Feb 9, 2024 · 10 comments · Fixed by #470

Comments

@workgroupengineering
Copy link
Contributor

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
Copy link
Member

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
Copy link
Contributor Author

workgroupengineering commented Feb 10, 2024

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
Copy link
Member

IAvaloniaXamlIlXmlNamespaceInfoProvider

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

@workgroupengineering
Copy link
Contributor Author

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
Copy link
Member

kekekeks commented Feb 11, 2024

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

@workgroupengineering
Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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
Copy link
Contributor Author

Can someone move this issue to Avalonia VS?

@timunie
Copy link

timunie commented Feb 13, 2024

@workgroupengineering transferred as requested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants