How do I check if a Virtualfile or PsiFile is a scratch file

I have an RunConfigurationProducer wired which sets up a run configuration based on file type selected.

I am unable to find the module for the scratch file. It always returns null



protected boolean setupConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context, Ref sourceElement) {

   Module
module = context.getModule();
// null module for all scratch files
}


This I assume is because a scratch file does not belong to any single module. Hence, I need to skip the configuration setup besed on whether the file selected is a scratch file (assuming a single file has been selected).

protected boolean setupConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context, Ref sourceElement) {

    PsiFile file = context.getPsiLocation().getContainingFile();    
    VirtualFile virtualFile = file.getVirtualFile()
    
   // If the file selected is a scratch file need to return false
}


How do I find out if the selected file is a scratch file ?

2 comments
Comment actions Permalink

Why do you care about scratch files specifically? There can be many other similar plugins. Why don't you simply return false for every file where the module is null?

0
Comment actions Permalink

I was going to do that itself, however, I was wondering if there was any other way to handle it because I saw the issue on scratch files. Didn't realise other plugins could cause the same problems.

Thanks for the input, I will use the 'null check on module' approach.

0

Please sign in to leave a comment.