| 2 | import { IAmDisposable, Sdks, WorkspaceConfig } from "./interfaces"; |
| 3 | |
| 4 | export class WorkspaceContext implements IAmDisposable { |
| 5 | public readonly workspaceTypeDescription: string; |
| 6 | public readonly events = new WorkspaceEvents(); |
| 7 | // TODO: Move things from Sdks to this class that aren't related to the SDKs. |
| 8 | constructor( |
| 9 | public readonly sdks: Sdks, |
| 10 | public readonly config: WorkspaceConfig, |
| 11 | public readonly hasAnyFlutterProjects: boolean, |
| 12 | public readonly hasAnyWebProjects: boolean, |
| 13 | public readonly hasAnyStandardDartProjects: boolean, |
| 14 | public readonly hasProjectsInFuchsiaTree: boolean, |
| 15 | public readonly firstFlutterProject: string | undefined, |
| 16 | ) { |
| 17 | this.workspaceTypeDescription = this.buildWorkspaceTypeDescription(); |
| 18 | } |
| 19 | |
| 20 | get shouldLoadFlutterExtension() { return this.hasAnyFlutterProjects; } |
| 21 | |
| 22 | /// Used only for display (for ex stats), not behaviour. |
| 23 | private buildWorkspaceTypeDescription(): string { |
| 24 | const types: string[] = []; |
| 25 | // Don't re-order these, else stats won't easily combine as we could have |
| 26 | // Dart, Flutter and also Flutter, Dart. |
| 27 | if (this.hasAnyStandardDartProjects) |
| 28 | types.push("Dart"); |
| 29 | if (this.hasAnyFlutterProjects) |
| 30 | types.push("Flutter"); |
| 31 | if (this.hasProjectsInFuchsiaTree) |
| 32 | types.push("Fuchsia"); |
| 33 | |
| 34 | // If we didn't detect any projects, record as unknown, but include info |
| 35 | // on the type of SDK we had found. |
| 36 | if (types.length === 0) { |
| 37 | if (this.sdks?.dartSdkIsFromFlutter) |
| 38 | types.push("Unknown (Flutter SDK)"); |
| 39 | else if (this.sdks?.dart) |
| 40 | types.push("Unknown (Dart SDK)"); |
| 41 | else |
| 42 | types.push("Unknown (No SDK)"); |
| 43 | } |
| 44 | |
| 45 | return types.join(", "); |
| 46 | } |
| 47 | |
| 48 | public dispose(): void { |
| 49 | this.events.dispose(); |
| 50 | } |
| 51 | |
| 52 | // TODO: Since this class is passed around, we may need to make it update itself |
| 53 | // (eg. if the last Flutter project is removed from the multi-root workspace)? |
| 54 | } |
| 55 | |
| 56 | class WorkspaceEvents implements IAmDisposable { |
| 57 | public readonly onPackageMapChange = new EventEmitter<void>(); |
nothing calls this directly
no outgoing calls
no test coverage detected