Skip to content

Break pub tools out into their own support mixin #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kenzieschmoll
Copy link
Contributor

This refactors the pub support to be part of its own support mixin instead of being part of the Dart CLI tools mixin. This is because once #81 is resolved, this tool won't necessarily be using the Dart CLI or the Flutter CLI, but may use either.

This PR pulls out a utility method runCommandInRoots from the Dart CLI support mixin for reuse.

Copy link

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

@kenzieschmoll kenzieschmoll added the dart_tooling_mcp_server: pub tools Issues related to Pub MCP server tools label Apr 23, 2025
import '../utils/process_manager.dart';

// TODO: migrate the analyze files tool to use this mixin and run the
// `dart analyze` command instead of the analyzer package.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is old and can be removed

// TODO: migrate the analyze files tool to use this mixin and run the
// `dart analyze` command instead of the analyzer package.

/// Mix this in to any MCPServer to add support for running Dart CLI commands
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment

implements ProcessManagerSupport {
@override
FutureOr<InitializeResult> initialize(InitializeRequest request) {
if (request.capabilities.roots == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't necessarily have to do this now, but I do think we should trend more in the direction of just logging a warning, and then not registering the pub tools. See the analyzer support mixin for an example.

Note that warnings have to be logged after initialization completes.

Basically the goal is to still allow the functionality that does work instead of failing initialization entirely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, on second look this does not require roots anyways (unless we wanted to make "roots" be optional, and by default run commands in all known roots, but this doesn't actually list the roots today).


final paths = (rootConfig['paths'] as List?)?.cast<String>();
if (paths != null) {
command.addAll(paths);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should modify the input parameter like this - generally that isn't idiomatic dart style.

I would just copy the input list and then add the paths to the copy.

/// Helper to run a command in multiple project roots.
///
/// [defaultPaths] may be specified if one or more path arguments are required
/// for the command (e.g. `dart format <default paths>`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would mention here a bit more about the expected argument structure and the implicit handling of paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants