dart-lang / dart-pad

An online Dart editor with support for console, web, and Flutter apps
https://dartpad.dev
BSD 3-Clause "New" or "Revised" License
1.71k stars 554 forks source link

dartpad: Implement external and abstract variables #1614

Closed eernstg closed 3 years ago

eernstg commented 4 years ago

Cf. the implementation plan, the addition of external and abstract variables to Dart may require some updates.

https://github.com/codemirror/CodeMirror/blob/master/mode/dart/dart.js already recognizes external and abstract as keywords, so this might be working already.

devoncarew commented 4 years ago

Note: I believe this is mostly updating the codemirror syntax highlighting. @eernstg, is there some good sample code to test against? The files in https://github.com/dart-lang/sdk/tree/master/tests/language/external_abstract_fields?

domesticmouse commented 4 years ago

I tried abstract_fields_test.dart and external_fields_test.dart in dartpad.dev and they both appear to be rendering in CodeMirror as I'd expect.

If we need to make a change to CodeMirror's Dart parsing, we need to be aware that CodeMirror has a monthly release cadence (on the 20th, give or take), and I try to keep codemirror.dart updated on a timely basis.

devoncarew commented 4 years ago

I believe that if you see abstract and external highlighting as you'd expect in those files, then we're good w/o any codemirror updates (the VS Code and github grammer - https://github.com/dart-lang/dart-syntax-highlight/tree/master/grammars - did not need updating).

domesticmouse commented 4 years ago

Here's the abstract sample:

Screen Shot 2020-08-19 at 1 47 52 pm

And the external sample:

Screen Shot 2020-08-19 at 1 48 35 pm
eernstg commented 4 years ago

is there some good sample code to test against? The files in https://github.com/dart-lang/sdk/tree/master/tests/language/external_abstract_fields?

Exactly. Looks like it does work already!

domesticmouse commented 4 years ago

@eernstg is this safe to close, or do you want to wait on a null safety release with these features included?

eernstg commented 4 years ago

Depends on whether there is more dartpad specific work to do: The underlying tools (analyzer and compiler) have their own implementation tasks (https://github.com/dart-lang/sdk/issues/41940, https://github.com/dart-lang/sdk/issues/42718), and they are closed, so it seems likely that the only remaining work for dartpad is syntax highlighting.

domesticmouse commented 4 years ago

Assigning this to @RedBrogdon to bundle testing this with the next null safety update.

leafpetersen commented 4 years ago

Any updates on this?

franklinyow commented 3 years ago

Any update? Thx

franklinyow commented 3 years ago

@RedBrogdon What is the current status?

mit-mit commented 3 years ago

From https://github.com/dart-lang/dart-pad/issues/1614#issuecomment-675835503, it looks like this is already working?

RedBrogdon commented 3 years ago

AFAICT, abstract variables are working just fine:

https://nullsafety.dartpad.dev/e5ace6215b5779c9b41ae5a136a9c1fd

External variables are highlighted correctly and cause no analyzer errors, but will not compile. This code, for example:

external int something;
external String toString();

void main() {
}

Produces this error when compiled:

Error compiling to JavaScript:
main.dart:1:14:
Error: Only external js-interop functions are supported.
external int something;
             ^
main.dart:2:17:
Error: Only external js-interop functions are supported.
external String toString();
                ^
main.dart:1:14:
Error: Only external js-interop functions are supported.
external int something;
             ^
Error: Compilation failed.
leafpetersen commented 3 years ago

@RedBrogdon Great, thanks! The external behavior is WAI I believe.