Add new file extension as xml

54 views
Skip to first unread message

Dmitry Dolotovskikh

unread,
Jun 28, 2014, 5:16:29 PM6/28/14
to resharpe...@googlegroups.com
Hi

Some xml files in project have different extension then .xml. How can I add new extension to get it work in for ICache component?
This is my properties provider. It works well, but my cache component Buid() method never called.
public class SPXmlFilePropertiesProvider : IPsiSourceFilePropertiesProvider
{
public IPsiSourceFileProperties GetPsiProperties(IPsiSourceFileProperties prevProperties, IProject project,
            IProjectFile projectFile, IPsiSourceFile sourceFile)
        {
            if (CheclXmlFile(sourceFile) && project.IsApplicableFor(this))
            {
                return new SPXmlFileProperties(prevProperties, projectFile, sourceFile);
            }
            else
            {
                return prevProperties;
            }
        }

       // here I allow file with extension .feature be processed
       private static bool CheclXmlFile(IPsiSourceFile sourceFile)
        {
            string[] validXmlExtensions = {".feature"};

            return sourceFile.PrimaryPsiLanguage.Is<XmlLanguage>() || validXmlExtensions.Any(validXmlExtension => sourceFile.GetExtensionWithDot() == validXmlExtension);
        }

Thanks.

Dmitry Dolotovskikh

unread,
Jul 1, 2014, 7:38:27 AM7/1/14
to resharpe...@googlegroups.com
Thanks a lot. I implemented IFileExtensionMapping and can cache .feature files. Of course, I validate it as xml before cache.

On Tuesday, July 1, 2014 1:27:30 PM UTC+4, citizenmatt wrote:
I don’t think the .feature file extension is recognised by ReSharper, so it won’t build a PSI for it and you won’t see it in your cache. You should be able to verify this by checking the PrimaryPsiLanguage of the .feature file’s IPsiSourceFile. I suspect it would be UnknownLanguage.

ReSharper maintains a set of mappings between file extensions and project file types (and a mapping from project file type to a language service which provides the psi language type), based on the IFileExtensionMapping interface. There are two default implementations - one gets the list of file extensions from the hardcoded project file types themselves (e.g. the xml project file type supports “.xml” but also “.dbml” and “.discomap”). 

The second (VSProjectFileExtensionsMapping) will use Visual Studio’s config, such as explicit mappings from extension to editor (Tools -> Options -> Text Editor -> File Extension) and also from Visual Studio’s mappings of file extension to editor. So if VS has a mapping from .feature to the xml editor, ReSharper should treat the file as an xml file. It would appear that there isn’t a mapping here (I don’t have SharePoint installed in my VS) - what editor does VS open .feature files in? It’s also possible to extend the list of known editor guids to file type mappings by implementing the IVsEditorGuidToFileTypeConverter interface.

I think your best bet would be to implement IFileExtensionMapping or IVsEditorGuidToFileTypeConverter. 

What makes me a little nervous is that the .feature file extension is also used by SpecFlow, and those definitely aren’t xml files. It would be nice to be able to only recognise .feature files inside a Sharepoint project, but I’m not sure how to do that. You could *possibly* use IPsiModuleDecorator.OverrideSourceFiles to decorate .feature IPsiSourceFiles in Sharepoint projects to be recognised as xml files, but that’s not really what the API was intended for...

--
You received this message because you are subscribed to the Google Groups "resharper-plugins" group.
To unsubscribe from this group and stop receiving emails from it, send an email to resharper-plug...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matt Ellis

unread,
Jul 1, 2014, 5:27:30 AM7/1/14
to resharpe...@googlegroups.com
I don’t think the .feature file extension is recognised by ReSharper, so it won’t build a PSI for it and you won’t see it in your cache. You should be able to verify this by checking the PrimaryPsiLanguage of the .feature file’s IPsiSourceFile. I suspect it would be UnknownLanguage.

ReSharper maintains a set of mappings between file extensions and project file types (and a mapping from project file type to a language service which provides the psi language type), based on the IFileExtensionMapping interface. There are two default implementations - one gets the list of file extensions from the hardcoded project file types themselves (e.g. the xml project file type supports “.xml” but also “.dbml” and “.discomap”). 

The second (VSProjectFileExtensionsMapping) will use Visual Studio’s config, such as explicit mappings from extension to editor (Tools -> Options -> Text Editor -> File Extension) and also from Visual Studio’s mappings of file extension to editor. So if VS has a mapping from .feature to the xml editor, ReSharper should treat the file as an xml file. It would appear that there isn’t a mapping here (I don’t have SharePoint installed in my VS) - what editor does VS open .feature files in? It’s also possible to extend the list of known editor guids to file type mappings by implementing the IVsEditorGuidToFileTypeConverter interface.

I think your best bet would be to implement IFileExtensionMapping or IVsEditorGuidToFileTypeConverter. 

What makes me a little nervous is that the .feature file extension is also used by SpecFlow, and those definitely aren’t xml files. It would be nice to be able to only recognise .feature files inside a Sharepoint project, but I’m not sure how to do that. You could *possibly* use IPsiModuleDecorator.OverrideSourceFiles to decorate .feature IPsiSourceFiles in Sharepoint projects to be recognised as xml files, but that’s not really what the API was intended for...
On 28 Jun 2014, at 10:16 pm, Dmitry Dolotovskikh <dmitrydo...@gmail.com> wrote:

Dmitry Dolotovskikh

unread,
Feb 1, 2017, 4:56:15 PM2/1/17
to resharper-plugins
Hi

The new problem with .feature files. Some time when the project is loading R# does not fire my cache Build method for particular .feature files. For example, there are 3 .feature files in project, Build method is fired only for two from its and I don't know why. Next time, after project close and open again the Build method will be fired for all 3 files. In m my cache implementation the Load method always return null and  I suppose that Build method should be fired for each cached file. Am I wrong?

Matt Ellis

unread,
Feb 2, 2017, 9:19:33 AM2/2/17
to resharper-plugins
Hi Dmitry. Are you seeing this behaviour when the cache is up to date? Your Build method should only be called if the file has changed since the last time it was cached - we don't want to reparse files that are already cached and up to date.

Regards
Matt

Dmitry Dolotovskikh

unread,
Feb 2, 2017, 11:47:51 AM2/2/17
to resharper-plugins
Hi, Matt

I have this behaviour when open very old project. And I don't know about whether cache is up to date for that project. But it seems I understand my problem. I expected to have Build is called each time when project is loading because I store  small information from ".feature" file in memory structure (in the custom ICach implementation). So once Build method is not sutable for that I think Load method could be thing I'm looking for.

Dmitry Dolotovskikh

unread,
Feb 2, 2017, 5:53:24 PM2/2/17
to resharper-plugins
I use follow code (borrowed from SimpleCache.Load) in my Load method to iterate for all .project feature files:


And I've found out that not all .feature files are being iterated. Why?
















On Thursday, February 2, 2017 at 5:19:33 PM UTC+3, Matt Ellis wrote:

Auto Generated Inline Image 1

Matt Ellis

unread,
Feb 3, 2017, 7:21:26 AM2/3/17
to resharper-plugins
I would start by cleaning the caches, restarting VS and reloading the solution - as you're loading, keep track (logging, debugging, whatever) of what files are handled by Build (clean cache should be empty) and then on a subsequent reload of the solution, track what files are read from Load.

At the very least, you should get the same files listed here - everything you build a cache object for should end up in the cache. That is, Load should have a record for every file you returned a non-null object from Build in a previous run.

If there are .feature files missing from Build (on clean load), you should look at those files and see if there's a reason that they're not being passed to you - are you changing the PSI properties so that they're not part of the code model? Do they live in a folder that matches a generated folder mask? Are they not part of your project? That kind of thing.

Regards
Matt

Dmitry Dolotovskikh

unread,
Feb 15, 2017, 9:52:53 AM2/15/17
to resharper-plugins
Hi, Matt

"cleaning the caches, restarting VS and reloading the solution" - this is I missed out, because I thought that cache is stored inside solution folder and just only removed it and unpacked from zip again. And only after I made cleanup psi cache from Internal Tool (restarted VS and reloaded the solution) I got "managed workflow".
Reply all
Reply to author
Forward
0 new messages