Skip to content
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

Flutter projects nested more than 2 levels deep do not force "Flutter mode", preventing launching/debugging apps #1549

Closed
galki opened this issue Mar 21, 2019 · 7 comments
Labels
in flutter Relates to running Flutter apps is enhancement
Milestone

Comments

@galki
Copy link

galki commented Mar 21, 2019

Folder structure

  • /monorepo_root
    • apps
      • app1
        • lib/main.dart
      • app2
        • lib/main.dart

Works

  1. File > Open Folder (app1)
  2. Start Debugging

Doesn't work

  1. File > Open Folder (monorepo_root)
  2. In Explorer right click on app1/lib/main.dart
  3. Select Start Debugging
lib/main.dart:1: Warning: Interpreting this as package URI, 'package:app1/main.dart'.
file:///C:/src/flutter/packages/flutter/lib/src/material/animated_icons.dart:9:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show Paint, Path, Canvas;
       ^
file:///C:/src/flutter/packages/flutter/lib/src/material/animated_icons.dart:10:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///C:/src/flutter/packages/flutter/lib/src/material/app.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui;
       ^
file:///C:/src/flutter/packages/flutter/lib/src/material/app_bar_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///C:/src/flutter/packages/flutter/lib/src/material/arc.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///C:/src/flutter/packages/flutter/lib/src/material/bottom_app_bar_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///C:/src/flutter/packages/flutter/lib/src/material/card_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///C:/src/flutter/packages/flutter/lib/src/material/chip_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
file:///C:/src/flutter/packages/flutter/lib/src/material/colors.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show Color;
       ^
file:///C:/src/flutter/packages/flutter/lib/src/material/dialog_theme.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' show lerpDouble;
       ^
Exited (sigint)
@DanTup
Copy link
Member

DanTup commented Mar 21, 2019

This is expected right now. When deciding whether to load the Flutter SDK or Dart SDK, we look two levels down to see if there's a Flutter project, and if not, we go into "Dart Mode".

If you can't open a folder closer to the apps, the best current fix is to click File -> Add Folder to Workspace and then select your app1/app2 folders which will show them in the Explorer tree as "Workspace Folders". Unfortunately, this means they will appear in two places in the tree - there is a request to fix that in VS Code at microsoft/vscode#45470 (please add a 👍 ).

We could scan further down the tree looking for Flutter projects at startup, but it would slow down startup (significantly for those opening large trees) and doing it this way also prevents you from having your own settings/launch configs within each of the apps folders.

@galki
Copy link
Author

galki commented Mar 21, 2019

Would be ideal if the level(s) scanned could be a configurable setting.

Rationale

  • common structure for monorepos (nrwl/nx, "app" and "lib" packages in Dart, etc)
  • all apps and libs end up down in the 3rd level
  • monorepos (common root folder) by definition don’t require workspace functionality

@DanTup
Copy link
Member

DanTup commented Mar 21, 2019

I've been trying to avoid encouraging people down this route because there are lots of other drawbacks with this. For example, you can't have per-project launch configs if your project is set up like this, or per-project settings. This means opening a project (app1) directly will behave very differently to opening monorepo_root.

VS Code supports multi-root workspaces which allow you to open multiple projects together while still treating them as "projects" and having their own VS Code settings, launch configs, etc. which is what the issue linked above is about trying to improve to handle the case of nested folders better.

I'll try and do some investigation into how other languages are handling this (probably next week now). I did start along this path once but it was not trivial (for example, when you tried to run things like pub get it'd run in your root folder, not a project). Some things have been improved since, but I'm sure there are still edge cases. I don't want to encourage people to work this way unless I'm sure it'll seamlessly support everything you'd get from having multi-root workspaces.

@DanTup DanTup changed the title Monorepo folder debugging doesn't work Flutter projects nested more than 2 levels deep do not force "Flutter mode", preventing launching/debugging apps Mar 21, 2019
@DanTup DanTup added this to the On Deck milestone Mar 21, 2019
@galki
Copy link
Author

galki commented Mar 22, 2019

Right, that also makes sense. Guess this is a "better safe than sorry" concern and the sacrifice from a monorepo perspective would be not seeing the actual folder structure. I'm not sure if forcing monorepo-wide settings on purpose would make a strong case where common/shared packaged exist but that's what I had in mind.

@galki
Copy link
Author

galki commented Mar 25, 2019

In my case I'm hosting the monorepo apps on Firebase in a single project. After doing some research I came to the conclusion that it's better to separate each app into its own Firebase project. In this light your advice makes much more sense so I'm fine with this issue being closed.

@DanTup
Copy link
Member

DanTup commented Mar 25, 2019

Thanks for the update! I'll keep this open because I think we should do a better job of guiding people here (the error when trying to run a Flutter project on the Dart VM is cryptic for one), even if it's just detecting the failure and linking them to a page/issue that describes the above.

@DanTup DanTup added is enhancement in debugger Relates to the debug adapter or process of launching a debug session labels Mar 25, 2019
@DanTup
Copy link
Member

DanTup commented Jul 18, 2019

In #1792 we started walking down the tree further (3 levels) when looking for projects. I think this solves the issue above (at least until someone comes along with a structure that has them 4 levels deep 😄).

@DanTup DanTup closed this as completed Jul 18, 2019
@DanTup DanTup modified the milestones: On Deck, v3.2.0 Jul 18, 2019
@DanTup DanTup added in flutter Relates to running Flutter apps and removed in debugger Relates to the debug adapter or process of launching a debug session labels Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in flutter Relates to running Flutter apps is enhancement
Projects
None yet
Development

No branches or pull requests

2 participants