How to admit the plugin to run during 'inpect'

27 views
Skip to first unread message

taodongl

unread,
Jun 1, 2017, 3:25:44 AM6/1/17
to resharper-plugins
Hello,

Because 'ElementProblemAnalyzer' always analyze file instantly. and it only analyzes `one file or one element`.

I want to compare  Resources.resx to Resources.de.resx and check if their keys are the same.

So I think 'ElementProblemAnalyzer' isn't reasonable for this scenario, right?

I want to only collect information of resource files during performing `Inspect` -> `Code Issues in Solution`. 

Can it be implemented?


taodongl

unread,
Jun 3, 2017, 9:27:17 AM6/3/17
to resharper-plugins
it seems that the below enum is my want:

namespace JetBrains.ReSharper.Feature.Services.Daemon
{
  public enum DaemonProcessKind
  {
    VISIBLE_DOCUMENT,
    SOLUTION_ANALYSIS,
    INCREMENTAL_SOLUTION_ANALYSIS,
    GLOBAL_WARNINGS,
    OTHER,
  }
}



在 2017年6月1日星期四 UTC+8下午3:25:44,taodongl写道:

Matt Ellis

unread,
Jun 5, 2017, 6:59:25 AM6/5/17
to resharper-plugins
This enum describes the type of daemon process that is currently being run for the current file. 

VISIBLE_DOCUMENT is for documents that are currently open, and SOLUTION_ANALYSIS is only used if Solution Wide Error Analysis is enabled. GLOBAL_WARNINGS is used as a final stage after everything else is done.

If you need to compare the contents in one file against other files, you're probably better off creating an implementation of ICache. This will be called for all files when the solution is first opened. You can then scan the file, create a cache object and have it written to disk, to make subsequent solution opens quicker. When the file changes, your ICache implementation will be called again, and you can update your cached information. You can see an example of ICache in the AngualrJS extension.

Then you can implement a standard daemon or ElementProblemAnalyzer for .resx files (I'm not sure if EPA is supported in .resx, to be honest) that can get an instance of your cache (via solution.GetComponent<>(), or via constructor injection, etc.) and lookup whatever it needs in your cache.

You might also want to look at ISolutionResourceCache, which is a solution component that ReSharper maintains with a mapping of resource items to source files.

Regards
Matt

taodongl

unread,
Jun 6, 2017, 11:05:18 PM6/6/17
to resharper-plugins
When should I consider to use ICache? 
I had intended to do like below: get all resource files whose name are same from IProject and extract all of IResxDataTagDeclaration to parse.
Is the action lower performance than ICache?

        public IEnumerable<IDaemonStageProcess> CreateProcess(IDaemonProcess process, IContextBoundSettingsStore settings, DaemonProcessKind processKind)
        {
            if (processKind == DaemonProcessKind.VISIBLE_DOCUMENT)
                return EmptyList<IDaemonStageProcess>.InstanceList;
            // check the cultureInfo of current file
            var lang = process.SourceFile.GetCultureName();
            if (!lang.IsEmpty())
                return EmptyList<IDaemonStageProcess>.InstanceList;
            var project = process.SourceFile.GetProject();
            var directory = process.SourceFile.GetLocation().Directory.FullPath;
            var files = System.IO.Directory.EnumerateFiles(directory,
                $"{process.SourceFile.GetNameWithoutCulture()}.*.{process.SourceFile.LanguageType.Name}", SearchOption.TopDirectoryOnly);
            var items = files.ToList<string, IPsiSourceFile>(f => {
                var fsp = FileSystemPath.CreateByCanonicalPath(f);
                var item = project.GetPsiSourceFileInProject(fsp);
                return item;
            });
            items.Add(process.SourceFile);
            var psiFiles = items.SelectNotNull(f => f.GetPsiFiles<ResxLanguage>()).SelectMany(x => x).OfType<IResxFile>();
            return new List<IDaemonStageProcess>(){ CreateProcess(process, settings, processKind, psiFiles) };
        }



在 2017年6月5日星期一 UTC+8下午6:59:25,Matt Ellis写道:
Reply all
Reply to author
Forward
0 new messages