MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / scanWorkspace

Method scanWorkspace

src/extension/sdk/utils.ts:305–545  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

303 }
304
305 public async scanWorkspace(): Promise<WorkspaceContext> {
306 this.logger.info("Searching for SDKs...");
307
308 const pathOverride = process.env.DART_PATH_OVERRIDE || "";
309 const normalPath = process.env.PATH || "";
310 const paths = (pathOverride + path.delimiter + normalPath).split(path.delimiter).filter((p) => p);
311
312 // Some paths to search after PATH as a final resort.
313 const fallbackSdkSearchPaths = [
314 process.env.FLUTTER_ROOT,
315 isLinux ? "~/snap/flutter/common/flutter" : undefined,
316 "~/flutter-sdk",
317 "/google/flutter",
318 "/opt/flutter", // https://github.com/Dart-Code/Dart-Code/issues/5174
319 ];
320
321 this.logger.info("Environment PATH:");
322 for (const p of paths)
323 this.logger.info(` ${p}`);
324
325 // If we are running the analyzer remotely over SSH, we only support an analyzer, since none
326 // of the other SDKs will work remotely. Also, there is no need to validate the sdk path,
327 // since that file will exist on a remote machine.
328 if (config.analyzerSshHost) {
329 return new WorkspaceContext({
330 dart: config.sdkPath,
331 dartSdkIsFromFlutter: false,
332 flutter: undefined,
333 isPreReleaseSdk: false,
334 }, {}, false, false, false, false, undefined);
335 }
336
337 // TODO: This has gotten very messy and needs tidying up...
338
339 let firstFlutterProject: string | undefined;
340 let hasAnyFlutterProject = false;
341 let hasAnyWebProject = false;
342 let hasAnyStandardDartProject = false;
343
344 const possibleProjects = await getAllProjectFolders(this.logger, getExcludedFolders, { searchDepth: config.projectSearchDepth });
345
346 // Scan through them all to figure out what type of projects we have.
347 for (const folder of possibleProjects) {
348 const hasPubspecFile = hasPubspec(folder);
349 const refsFlutter = hasPubspecFile && projectReferencesFlutter(folder);
350 const refsWeb = false; // hasPubspecFile && referencesWeb(folder);
351 const hasFlutterCreateProjectTriggerFile =
352 fs.existsSync(path.join(folder, FLUTTER_CREATE_PROJECT_TRIGGER_FILE));
353
354 // Special case to detect the Flutter repo root, so we always consider it a Flutter project and will use the local SDK
355 const isFlutterRepo = fs.existsSync(path.join(folder, "bin/flutter")) && fs.existsSync(path.join(folder, "bin/cache/dart-sdk"));
356
357 // Since we just blocked on a lot of sync FS, yield.
358 await resolvedPromise;
359
360 const isSomethingFlutter = refsFlutter || hasFlutterCreateProjectTriggerFile || isFlutterRepo;
361
362 const kind = isSomethingFlutter ? "Flutter" : "non-Flutter";

Callers 1

activateFunction · 0.95

Calls 14

findFlutterSdkMethod · 0.95
warnIfBadConfigSdkMethod · 0.95
findDartSdkMethod · 0.95
getAllProjectFoldersFunction · 0.90
hasPubspecFunction · 0.90
projectReferencesFlutterFunction · 0.90
getDartWorkspaceFoldersFunction · 0.90
fsPathFunction · 0.90
ensureFlutterInitializedFunction · 0.90
isDartSdkFromFlutterFunction · 0.90

Tested by

no test coverage detected