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

Add CodeLens links for Flutter DartPad samples #2232

Merged
merged 2 commits into from
Jan 27, 2020

Conversation

DanTup
Copy link
Member

@DanTup DanTup commented Jan 24, 2020

This adds CodeLens links for Flutter files that have {@tool dartpad snippets that open the interactive online samples:

Screenshot 2020-01-24 at 15 13 12

Screenshot 2020-01-24 at 15 13 24

It has some assumptions/caveats:

  • Only works for files inside (Flutter SDK)/packages/flutter/lib/src/material/app_bar.dart
  • Assumes the leaf-most folder name is the package (eg. in the above, "material") and that the name from the Outline node is the classname, and uses these in the URL as ${sample.libraryName}/${sample.className}-class.html
  • Always links to https://api.flutter.dev regardless of your Flutter branch/channel
  • Assumes there's an element with the ID #${sample.libraryName}.${sample.className}.1 at the correct location (this jumps down the page - if this assumption becomes invalid, you'll end up at the top of the docs page for that class)

@devoncarew I think these are the same for the IntelliJ version too (except the last one - though you might wish to add) but shout if anything seems wrong here.

Fixes #2151.

@DanTup DanTup added is enhancement in flutter Relates to running Flutter apps in editor Relates to code editing or language features labels Jan 24, 2020
@DanTup DanTup added this to the v3.8.0 milestone Jan 24, 2020
@devoncarew
Copy link
Contributor

Great!

I think these are the same for the IntelliJ version too (except the last one - though you might wish to add) but shout if anything seems wrong here.

Yup, this is what IntelliJ is doing (modulo the last item). I elected to not try and link to a specific anchor - it was unclear to me how stable that would be going forward. Linking to package+class seems stable (w/ the caveat that for most cases the user will need to scroll a bit to see the actual dartpad instance on the page).

@DanTup DanTup changed the title Add CodeLens links for Flutter DatPad samples Add CodeLens links for Flutter DartPad samples Jan 24, 2020
@DanTup
Copy link
Member Author

DanTup commented Jan 24, 2020

I elected to not try and link to a specific anchor - it was unclear to me how stable that would be going forward

Yeah, I did consider leaving it out, but it seems fairly stable (they're used in the IDs for flutter create --sample and always ascend from 1) and if they change it just reverts to not scrolling anyway (there are no errors, it just doesn't scroll down anywhere). I also thought it felt a bit weird given the text on the code lens if we didn't scroll (since then it's just like "open API docs" and it might raise questions about why we only do it for some specific set of classes).

@DanTup DanTup merged commit 6033fbd into master Jan 27, 2020
@DanTup DanTup deleted the add-flutter-sample-code-lens branch January 27, 2020 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features in flutter Relates to running Flutter apps is enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace "Open Widget Sample" with in-line Code-Lens links
2 participants