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

Experiment with using the monaco text editor (and / or codemirror 6) with dartpad #2743

Open
devoncarew opened this issue Dec 4, 2023 · 7 comments
Labels
type-enhancement A request for a change that isn't a bug

Comments

@devoncarew
Copy link
Member

We should experiment with using the monaco text editor (https://microsoft.github.io/monaco-editor/) with dartpad, esp. if we think it could help reduce maintenance costs here (rolling codemirror, ...). It would give us a look and feel similar to other flutter development environments, and may make it easier to do more sophisticated UIs for code completion, quick fixes, ...

At a first attempt at using it in a flutter hello world app, I ran into bootstrapping issues. Monaco uses require.js for its module system, which doesn't seem to work well with the module system used by DDC. The release build of dartpad would be compiled w/ dart2js (so may not have this issue?) but our dev cycle for developing dartpad won't work well w/o DDC.

It looks like DDC may move off of using require.js (#2695). That may solve the issue for us?

@ditman - do you have familiarity w/ the module systems / issues we may be running into when trying to use monaco? Any solutions or workarounds come to mind?

@modulovalue
Copy link

modulovalue commented Dec 7, 2023

FYI:

Both migrated away from Monaco.

Codemirror appears to win when it comes to code size and mobile support.

Quote:

CodeMirror improved Replit's performance by a lot and by extension our retention. In fact, after releasing it to mobile in July[1] our weekly retention rate on mobile increased by a whopping 70%. That said, solve a lot of mobile usability issues so it's not all due to performance. On desktop however, it's a different story, we made sure to just have parity with Monaco and it still improved retention by %25, almost all due to performance!

@parlough
Copy link
Member

parlough commented Dec 7, 2023

Good point! I'm all for a better mobile experience. I think CodeMirror 6 is great, but there potentially are some extra development costs with it that will need to be considered. Particularly how there is currently no Dart support for Lezer or CodeMirror.

Due to CodeMirror 6's leaner nature, it could be even less work than Monaco. Definitely worth exploring at least.

Looking at the Java support, it doesn't seem like too much work. The hardest/most tedious part would be writing the lezer grammar. I wonder if we can just generate at least some of it from Dart's antlr grammar? Here's the Java lezer grammar as a reference.

As for the bindings, I'll have to look at what CodeMirror's API looks like. Looks like you can pick and choose what you need, which is nice.

@modulovalue
Copy link

We have a basic tree sitter grammar for Dart here: https://github.com/UserNobody14/tree-sitter-dart.
There appears to be a basic tree sitter to lezer conversion tool here https://github.com/lezer-parser/import-tree-sitter.

@devoncarew
Copy link
Member Author

I think that an easy-to-integrate codemirror 6 wrapper, w/ dart mode support, would be more than enough for this project.

If we do use codemirror 6, it would be nice to start with a lightweight package:web based wrapper, instead of the current (fairly comprehensive) wrapper that we have in package:codemirror.

@ditman
Copy link
Member

ditman commented Dec 7, 2023

Monaco uses require.js for its module system, which doesn't seem to work well with the module system used by DDC.

@devoncarew this has been a running issue for a while. As you said, requireJS is being actively removed right now (check with @Markzipan) and I did some hacks in the past for it to "remove/hide" requireJS after it loads, so this might be a race condition between the monaco JS and flutter's? If you still want to pursue this, try to make monaco load after flutter has fully initialized maybe? It may also be monaco detecting require.js slightly differently, and still finding remnants of our usage :)

@modulovalue
Copy link

@devoncarew what does "dart mode support" entail?

That is, is it only about syntax highlighting, and token-based highlighting would be enough, or are there other features that you want/need to support, that would require code-mirror to have access to the whole parse tree?

@devoncarew
Copy link
Member Author

I was just thinking about syntax highlighting - the current level of dart support from codemirror 5.

I'm not really familiar enough w/ codemirror 6 to know what benefits we might get w/ a full parse tree for dart, but I suspect that most or all dart uses of codemirror would use it for syntax highlighting (and then rely on some analysis server integration for more sophisticated features).

@devoncarew devoncarew changed the title Experiment with using the monaco text editor with dartpad Experiment with using the monaco text editor (and or codemirror 6) with dartpad Dec 27, 2023
@devoncarew devoncarew changed the title Experiment with using the monaco text editor (and or codemirror 6) with dartpad Experiment with using the monaco text editor (and / or codemirror 6) with dartpad Jan 3, 2024
@johnpryan johnpryan added the type-enhancement A request for a change that isn't a bug label Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants