@@ -11,6 +11,7 @@ import 'package:process/process.dart';
11
11
import 'package:yaml/yaml.dart' ;
12
12
13
13
import 'constants.dart' ;
14
+ import 'sdk.dart' ;
14
15
15
16
/// The supported kinds of projects.
16
17
enum ProjectKind {
@@ -71,14 +72,15 @@ Future<ProjectKind> inferProjectKind(Root root, FileSystem fileSystem) async {
71
72
/// root's 'paths'.
72
73
Future <CallToolResult > runCommandInRoots (
73
74
CallToolRequest request, {
74
- FutureOr <String > Function (Root , FileSystem ) commandForRoot =
75
+ FutureOr <String > Function (Root , FileSystem , Sdk ) commandForRoot =
75
76
defaultCommandForRoot,
76
77
List <String > arguments = const [],
77
78
required String commandDescription,
78
79
required FileSystem fileSystem,
79
80
required ProcessManager processManager,
80
81
required List <Root > knownRoots,
81
82
List <String > defaultPaths = const < String > [],
83
+ required Sdk sdk,
82
84
}) async {
83
85
var rootConfigs =
84
86
(request.arguments? [ParameterNames .roots] as List ? )
@@ -103,6 +105,7 @@ Future<CallToolResult> runCommandInRoots(
103
105
processManager: processManager,
104
106
knownRoots: knownRoots,
105
107
defaultPaths: defaultPaths,
108
+ sdk: sdk,
106
109
);
107
110
if (result.isError == true ) return result;
108
111
outputs.addAll (result.content);
@@ -134,14 +137,15 @@ Future<CallToolResult> runCommandInRoots(
134
137
Future <CallToolResult > runCommandInRoot (
135
138
CallToolRequest request, {
136
139
Map <String , Object ?>? rootConfig,
137
- FutureOr <String > Function (Root , FileSystem ) commandForRoot =
140
+ FutureOr <String > Function (Root , FileSystem , Sdk ) commandForRoot =
138
141
defaultCommandForRoot,
139
142
List <String > arguments = const [],
140
143
required String commandDescription,
141
144
required FileSystem fileSystem,
142
145
required ProcessManager processManager,
143
146
required List <Root > knownRoots,
144
147
List <String > defaultPaths = const < String > [],
148
+ required Sdk sdk,
145
149
}) async {
146
150
rootConfig ?? = request.arguments;
147
151
final rootUriString = rootConfig? [ParameterNames .root] as String ? ;
@@ -185,7 +189,7 @@ Future<CallToolResult> runCommandInRoot(
185
189
final projectRoot = fileSystem.directory (rootUri);
186
190
187
191
final commandWithPaths = < String > [
188
- await commandForRoot (root, fileSystem),
192
+ await commandForRoot (root, fileSystem, sdk ),
189
193
...arguments,
190
194
];
191
195
final paths =
@@ -240,18 +244,21 @@ Future<CallToolResult> runCommandInRoot(
240
244
/// Returns 'dart' or 'flutter' based on the pubspec contents.
241
245
///
242
246
/// Throws an [ArgumentError] if there is no pubspec.
243
- Future <String > defaultCommandForRoot (Root root, FileSystem fileSystem) async =>
244
- switch (await inferProjectKind (root, fileSystem)) {
245
- ProjectKind .dart => 'dart' ,
246
- ProjectKind .flutter => 'flutter' ,
247
- ProjectKind .unknown =>
248
- throw ArgumentError .value (
249
- root.uri,
250
- 'root.uri' ,
251
- 'Unknown project kind at root ${root .uri }. All projects must have a '
252
- 'pubspec.' ,
253
- ),
254
- };
247
+ Future <String > defaultCommandForRoot (
248
+ Root root,
249
+ FileSystem fileSystem,
250
+ Sdk sdk,
251
+ ) async => switch (await inferProjectKind (root, fileSystem)) {
252
+ ProjectKind .dart => sdk.dartExecutablePath,
253
+ ProjectKind .flutter => sdk.flutterExecutablePath,
254
+ ProjectKind .unknown =>
255
+ throw ArgumentError .value (
256
+ root.uri,
257
+ 'root.uri' ,
258
+ 'Unknown project kind at root ${root .uri }. All projects must have a '
259
+ 'pubspec.' ,
260
+ ),
261
+ };
255
262
256
263
/// Returns whether or not [rootUri] is an allowed root, either exactly matching
257
264
/// or under on of the [knownRoots] .
0 commit comments