Skip to content

[analyzer_plugin]: setContextRoots event never received #56475

@rrousselGit

Description

@rrousselGit

Hello!

TL;DR, in certain situation, the setContextRoots event is never received by plugins.
I'm not sure what exactly triggers it, so I made a reproduction repository. It is composed of:

  • the analyzer_plugin.
    It is the bare minimum for a plugin, with no logic in it besides extending ServerPlugin.
  • many packages (some using analyzer_plugin, some not).
    They are composed if nothing but pubspec.yamls and maybe a pubspec_overrides.yaml
  • The packages that uses the analyzer_plugin do so through a path dependency

The reproduction repository is here: https://github.com/rrousselGit/analyzer_plugin_bug_repro

Steps to reproduce:

  • Clone this repository
  • Do a global search of path: /Users/remirousselet/dev/rrousselGit/fake_riverpod/packages/custom_lint and replace it with an absolute path that points to packages/custom_lint
  • Run dart pub get everywhere (the IDE should suggest it)
  • Enable analyzer logs
  • Restart the analyzer server

In the logs, you will see some requests made to the analyzer plugin. Such as:

1723714208683:PluginReq:{"id"::"14","method"::"plugin.versionCheck","params"::{"byteStorePath"::"/Users/remirousselet/.dartServer/.analysis-driver","sdkPath"::"/Users/remirousselet/dev/flutter/bin/cache/dart-sdk","version"::"1.0.0-alpha.0"}}:file::///Users/remirousselet/.dartServer/.plugin_manager/12c93ced09bb72bc715613b8b9aeae4c/analyzer_plugin/bin/plugin.dart::
1723714208690:PluginRes:{"id"::"14","requestTime"::1723714208686,"result"::{"isCompatible"::true,"name"::"Custom Lint","version"::"1.0.0-alpha.0","interestingFiles"::["*.dart"]}}:file::///Users/remirousselet/.dartServer/.plugin_manager/12c93ced09bb72bc715613b8b9aeae4c/analyzer_plugin/bin/plugin.dart::

But there's never a analysis.setContextRoots request sent by default.

Note:
If you restart the analyzer server while the plugin is running, and override
ServerPlugin.handleAnalysisSetContextRoots to log somewhere in a while,
you will see that the method is invoked right before shutdown is invoked.

It is hard to see in the analyzer logs, because the request appears in the log right
before the log file is cleared.


Dart SDK version: 3.5.0 (stable) (Tue Jul 30 02:17:59 2024 -0700) on "macos_arm64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestdevexp-pluginlegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions