Skip to content

Conversation

@Hixie
Copy link
Contributor

@Hixie Hixie commented Jul 28, 2022

  • Enable asserst when running analyze_snippet_code.dart

  • Revamp analyze_snippet_code.dart to actually analyze all code snippets.

  • Add a full example for SliverOpacity.

  • Export src/cupertino/debug.dart which we somehow had missed.

  • Fix a zillion minor errors in API docs and especially API sample code.

@flutter-dashboard flutter-dashboard bot added a: animation Animation APIs a: text input Entering text in a text field or keyboard related problems d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Jul 28, 2022
Comment on lines 21 to 24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two newlinews here? lol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. fixed.

Comment on lines 2713 to 2721
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in ScrollPhysics you added ... without a newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the leading/trailing blank lines here

Comment on lines 2686 to 2696
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in ScrollPhysics you added ... without a newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: ellipsis

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: not not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add num?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add num?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added, but i wouldn't encourage anyone to write code using num.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add const and extension ?

This regexp will not match top level functions or mutable variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added extension, though hopefully no examples even use that.

const is intentionally not here because it's used when showing examples of Widgets, which are expressions.

Top-level functions are handled by _maybeFunctionDeclarationRegExp.

Mutable variables are hard to recognize. We never use var because of the analysis options. Generally they end up being treated as statements, which seems to work for our current examples.

Comment on lines 430 to 587
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we can refactor this to:

Suggested change
if (line.startsWith('// // ignore_for_file: ')) {
final _Line newLine = _Line(
line: lineNumber,
indent: 3,
code: line.substring(3),
);
ignorePreambleLinesOnly.add(newLine);
preambleLines.add(newLine);
} else {
preambleLines.add(_Line(line: lineNumber, indent: 3, code: line.substring(3)));
}
final _Line newLine = _Line(line: lineNumber, indent: 3, code: line.substring(3));
if (line.startsWith('// ignore_for_file: ')) {
ignorePreambleLinesOnly.add(newLine);
}
preambleLines.add(newLine);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call!

Comment on lines +912 to +1040
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (preamble.isNotEmpty)
...preamble,
if (preamble.isNotEmpty)
const _Line.generated(), // blank line
if (preamble.isNotEmpty) ...[
...preamble,
const _Line.generated(), // blank line
],

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i considered doing that but isn't that less efficient? now you're building a list just to inject it back into another list, rather than just evaluating a boolean variable twice.

Comment on lines 934 to 1067
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use collection-if and collection-for:

final List<_Line> codeLines = <_Line>[
  if (prefix != null) _Line.generated(code: prefix),
  for (int i = 0; i < code.length; ++i)
    _Line(
      code: code[i],
      line: firstLine.line + i,
      indent: firstLine.indent,
    ),
  if (postfix != null) _Line.generated(code: postfix),
];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary wrap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@Hixie
Copy link
Contributor Author

Hixie commented Jul 28, 2022

(tests are failing because I haven't landed the engine part yet)

@Hixie
Copy link
Contributor Author

Hixie commented Aug 1, 2022

PR updated per comments, thanks for the reviews!

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning this up!!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect that the alignment here will be off when these are rendered with a variable-width font on https://api.flutter.dev/?

Screen Shot 2022-08-01 at 5 10 15 PM

(or does dartdoc have a special feature that I am not aware off and these will continue to render with a fixed-width font even without the ```?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same concern for many other places in this PR...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The four space indent triggers monospace font.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ... special cased somehow? Otherwise, shouldn't this be

Suggested change
/// ...
/// // ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I read the doc in analyze_snippet_code.dart, I see that it is special cased. I would argue that that isn't necessary and instead the ... should just be added as a comment. Has the added benefit that if I copy this snippet into my own code, I don't get a bunch of analyzer warnings on this line. Everywhere else (e.g. // continuing from previous example...) these are also used in comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, seems reasonable, i'll remove this feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Or more to the point, make it require // .... The feature itself is still useful, it adds an ignore.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should somewhere document what strings with special meaning you can use so we can point people to it in code reviews. I wonder, what would be a good place for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that they are documented in analyze_snippet_code.dart.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, they are... ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically this bullet point continues the sentence started by "Such snippets:", though admittedly by this point in the text the reader has probably forgotten this. :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should give these control comments a common prefix. It would indicate to the reader that these comments are actually load-bearing. Also, if I want to author a new example and look at an existing one it would give me something to search for to understand what other control comments are available.

On the other hand, it my hinder the reading flow of these examples...

Just a thought, not feeling super-strongly about this either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i feel super constrained here because the most important result is that the examples flow well for the developers.
on the other hand, these load-bearing comments are so magical, ugh.

I've added a message to the snippet analyzer's output that just points right at the docs, FWIW. Dunno how much it'll help.

@Hixie Hixie force-pushed the snippets branch 3 times, most recently from 4b573c0 to 1e667aa Compare August 3, 2022 23:09
@Hixie
Copy link
Contributor Author

Hixie commented Aug 3, 2022

Landed fixes for the dev/bots/test tests.

@Hixie
Copy link
Contributor Author

Hixie commented Aug 3, 2022

This depends on flutter/engine#35146 rolling into the framework.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RSLGTM when checks are happy.

@Hixie
Copy link
Contributor Author

Hixie commented Aug 8, 2022

Now blocked on flutter/engine#35235

@Hixie Hixie force-pushed the snippets branch 2 times, most recently from d4f1fc3 to 4fc72cc Compare August 8, 2022 22:09
@Hixie Hixie added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 8, 2022
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 8, 2022

  • The status or check suite Linux analyze has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 8, 2022
@Hixie Hixie force-pushed the snippets branch 5 times, most recently from 0c2b01d to 9cf960d Compare August 10, 2022 19:31
* Enable asserst when running analyze_snippet_code.dart

* Revamp analyze_snippet_code.dart to actually analyze _all_ code snippets.

* Add a full example for SliverOpacity.

* Export src/cupertino/debug.dart which we somehow had missed.

* Fix a zillion minor errors in API docs and especially API sample code.
@Hixie Hixie added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 10, 2022
@auto-submit auto-submit bot merged commit 7ded3d9 into flutter:master Aug 10, 2022
@Hixie Hixie deleted the snippets branch August 10, 2022 22:23
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: animation Animation APIs a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App c: contributor-productivity Team-specific productivity, code health, technical debt. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants