TemplateChooserDialog and ITemplateScopePoint

9 views
Skip to first unread message

Alcaeus

unread,
Sep 18, 2017, 7:38:40 AM9/18/17
to resharper-plugins
Hi, 
How do I derive a list of ITemplateScopePoint suitable for the current project type? To then pass to TemplateChooserDialog? I would like the templates shown to be those for the current project type.

I found EnumerateRealScopePoints and tried
              _scopeManager.EnumerateRealScopePoints(new TemplateAcceptanceContext(project.ProjectFile)).ToList<ITemplateScopePoint>();
but the results were empty.

Previously I derived the scopepoints via IFileTemplatesSupport and Accept(project) but this approach is gone in 2017.2 

Thanks, D

Matt Ellis

unread,
Sep 18, 2017, 8:07:06 AM9/18/17
to resharper-plugins
This example is creating a context on the project file of the project, that is, the .csproj. So this probably isn't returning what you'd expect. However, it shouldn't return you an empty list - for example, there's the "Everywhere" scope point which is always returned, regardless of the context.

It does look like there's a small bug in the context, though. It will only return a project if you create it with a source file, or a ProjectFolderWithLocation. If you create it with an IProjectFile, GetProject returns null. So try creating with an instance of ProjectFolderWithLocation - new ProjectFolderWithLcoation(project) would probably do it. I've raised an issue - RSRP-466304.

Regards
Matt

Alcaeus

unread,
Sep 21, 2017, 4:34:16 PM9/21/17
to resharper-plugins
The following was good enough...thanks for the advice...

            var applicableFileTemplateScopes = _scopeManager.EnumerateRealScopePoints(new TemplateAcceptanceContext(new ProjectFolderWithLocation(associatedProject)));
            applicableFileTemplateScopes = applicableFileTemplateScopes.Distinct().Where(s => s is InLanguageSpecificProject).ToList();
Reply all
Reply to author
Forward
0 new messages