-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Upgrade to CodeMirror 6. #2595
Upgrade to CodeMirror 6. #2595
Conversation
7b456c9
to
20b242d
Compare
I was looking to add functions from the pg macros to the list of highlighted functions, such as |
No, you can't really do that in a reliable way. Generally CodeMirror 6 is designed to be non-contextual in its parsing. |
97c81e9
to
faa4fec
Compare
I should point out that since the elements for selecting the theme, keymap, and such are part of the pg-codemirror-editor package, the strings used for those are not translatable unfortunately. That could be done by adding a translation method for that package, but would require translations for that package. |
71afbdc
to
d9ca88c
Compare
d9ca88c
to
dc65c8d
Compare
418f76d
to
80b7c19
Compare
GitHub says this has no conflicts, but I just did:
and I get merge conflicts.
|
Trying again with just
and that of course works. I am not sure why my local git says that there is a conflict merging this with |
I don't find anything there. |
Oh I see it's at https://github.com/openwebwork/pg-codemirror-editor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is loading and working as far as I can tell. The auto-completion works. The controls for collapsing and expanding blocks work (slightly differently as compared with the hotfix we merged earlier today, as expected). I'm not sure what more to test.
80b7c19
to
5a6c460
Compare
Sorry for the mistake in my initial comment. I corrected it. |
For testing, just try opening many problems and checking that syntax highlighting looks right. Test auto completion and such. Note that there is different auto completion depending on where you are. For instance, if you are in the general perl code portion of a problem, versus in a PGML or PG text block. And it is even more fine grained than that. For instance, if you are in a PGML niceTables construct there is different auto completion. If you are inside I think that general testing of this will take time. I have tested with a considerable number of problems of mine as well as problems in the OPL. As more of use start to test and edit problems with this, we will probably see more issues that things need to be tweaked for, as well as potential improvements that can be made. One thing that I know still needs some work is how indentation works at various points. When you hit |
5a6c460
to
9882881
Compare
I think I must have had a stale version of @drgrice1's branch when I was trying to merge locally before. It's working for me now. I loaded lots of problems and could see no issues with syntax highlighting. Auto-completion: I like to use |
There is an auto completion snippet for To see why I don't think it is beneficial, let me first explain auto completion in a little more detail. An auto completion snippet is defined by a template with one or more slots to be filled. When you activate a snippet the cursor starts in the first slot. After typing what you want in that slot you can hit "tab" to switch to the next slot. Now the snippet for I designed all of the snippets in the same way with a slot at the end, so you can always tab to the end after typing inside. If that isn't good enough for you on this, then we can add starred variants for those things that support stars, but I think it could be a bit tedious to have all of those in the general auto completion snippet list. Also note that the slots can have initial text in them that is replaced as soon as you type in that slot. That is what happens with the space in the first slot above, but I did this in a more meaningful way with the image snippet. It is defined as |
I'm good with this at any time. I will continue to make small observations here as long as this PR remains open. These comments do not necessarily belong here as opposed to the other repos associated with code mirror now. The autocomplete for And I'm not sure how others feel, but lately I've been doing like
Typing the quotes when you do it the "normal" way got too irritating for me. More generally, the various PG commands could auto-complete with positions for arguments. For example, I noticed some commands that I frequently use from Some commands (like Thanks for adding starred variants. One of them that may be particularly important is the one for layout table. Without that, it would be more likely that people would be using a regular table for layout purposes and go against accessibility principles for that. |
I think the auto completion is using the same list as syntax highlighting which is incomplete. I've been working on making the list more complete, I forgot about |
Note that I just took the list of PG variables and operators from the old CodeMirror 5 code. We can add whatever we need there. PG has changed quite a bit from when the lists in the CodeMirror 5 code were created. The auto completion for PG methods is quite different than the auto completion snippets for PGML elements. The PG methods use the If either of you would like to help, the PG variables and operators are defined in the To fill in other parts of the puzzle, the auto completions (and indentation) for PGML are defined in the Of course that is all in the |
I should note that is a bit tedious to bubble up changes to the Note that the way CodeMirror usually does it, the Lezer parser is usually in one project, and then the language another. If I had gone with that there would be three projects. |
I have already started updating the list of keywords, I just wanted to go though all the |
Here is my start at adding new matching. I got a bit lost in the weeds, there are lots of older out dated macros we probably shouldn't match, but I'm not quite sure which ones are which. I still need to go through the |
You are going to need to look in the |
Thanks, I've updated that. |
I told you that I took the lists from the current CodeMirror 5 PG.js file, but I did modify the lists some already. One of the things that we don't want to do is to promote usage of deprecated methods and variables. As such I removed the Also, I noticed that you added I noticed that you added |
I should add that we can add auto completion for |
I just noticed that you also added |
I am not sure that it is beneficial to add I am not sure that SRAND($psvn);
$var = random(0, 2);
SRAND($problemSeed); |
Updated, the last commit on this branch. I have gone though the last few directories. There are lots of macros I'm not familiar with and a lot just seem outdated or specialized so I didn't include what I though clearly fell into that category. I probably included stuff that could be left out as well. I put comments to state which directory I was looking in and pulling macros from. https://github.com/somiaj/codemirror-lang-pg/tree/update-pg-strings Please just list any macros you see there that you think shouldn't be, or if you happen to notice anything I missed. I can probably make a PR for this, though want to give time for people to look it over (@drgrice1 You are welcome to just take that commit, modify if you like and apply it directly if you would prefer that over a PR). |
@somiaj: I merged your branch with the pg operators update. Thanks for working on that. |
cc31785
to
cf2977f
Compare
I added auto completions for PG methods like @Alex-Jordan suggested. By default all of them have the template
|
cf2977f
to
4448034
Compare
Some features of this change are improved syntax highlighting and the addition of autocompletion. To see available autocompletions at the current cursor location, you can type Ctrl-Space. In many cases, autocompletions are offered automatically when certain things have been typed. CodeMirror 6 can not be used via script tags. So a PGProblemEditor package has been created for this. The repository for that is https://github.com/openwebwork/pg-problem-editor. An initial package has been published in npm at https://www.npmjs.com/package/@openwebwork/pg-codemirror-editor. The real work is done in the codemirror-lang-pg package that adds support for the PG language in CodeMirror 6. The repository for that package is https://github.com/openwebwork/codemirror-lang-pg, and the npm package at https://www.npmjs.com/package/@openwebwork/codemirror-lang-pg. The pg-problem-editor package is designed so that it can be used by webwork2, the standalone renderer, and possible others that want a PG problem editor. It may need a few tweaks to make it work for webwork3 in the future, but should also work for that. The codemirror-lang-pg package consists of a base PG parser that is largely derived from the codemirror-lang-perl package (at https://github.com/drgrice1/codemirror-lang-perl and https://www.npmjs.com/package/codemirror-lang-perl) with a modifications specific to the perl available in a PG problem. The main differences are that its escape sequence is ~~, much of what can not be used in the safe compartment has been stripped out, and there are special blocks for PGML, PG text, and LaTeX image code. Then there are two other parsers. Those are the PGML and PG text parsers. Those parsers run on the contents of the PGML and PG text blocks found by the base PG parser. Note that the PGML parser is actually a javascript implementation of the parser in PGML.pl with some modifications to track position and things needed to associate the parsed tree with the original code. Note that the configuration of theme, keymaps, and such are now part of the pg-codemirror-editor, and are shown in a panel of the editor instead of below as before. Emacs and Vim keymaps are available, but at this point there is not a Sublime keymap for CodeMirror 6. The themes that are available include a basic default theme (that is part of the pg-problem-editor package and just adds some syntax highlighting that is missing from the CodeMirror 6 default), the OndDark theme that is the only other theme provided by the CodeMirror 6 developers directly, the themes in the thememirror package, and the themes from https://github.com/craftzdog/cm6-themes which are in several separate npm packages. Note that both thememirror and craftzdog/cm6-themes provide a solarized light theme, and that is why there are two of those. They are slightly different though. I am sure that there is a lot more work to do on this, and there are other things available with CodeMirror 6 that could probably be implemented. In any case, this is a good start.
…ievement notifications. The new codemirror-lang-mt package is used for this, and support for that language has been added to the pg-codemirror-editor.
4448034
to
58c7d73
Compare
Should that be I've marked this as approved and still so. @somiaj, do you have any hesitation at this point against just merging this? |
That isn't Perl. That is the format for CodeMirror 6's auto completion snippet template. It should be what it is. That means that if you use the snippet it will show |
Oh I see. I was thinking the braces alone were the markers for that. But I see that makes no sense given the dollar sigil in other places. |
It doesn't seem to be that a bold statement is needed before an italic statement. If an italic statement does not have anything before it on the line, then it works. Somehow, a bold statement before it also makes it work. I will look into it. |
Some features of this change are improved syntax highlighting and the addition of autocompletion. To see available autocompletions at the current cursor location, you can type Ctrl-Space. In many cases, autocompletions are offered automatically when certain things have been typed.
CodeMirror 6 can not be used via script tags. So a PGProblemEditor package has been created for this. The repository for that is https://github.com/openwebwork/pg-codemirror-editor. An initial package has been published in npm at
https://www.npmjs.com/package/@openwebwork/pg-codemirror-editor. The real work is done in the codemirror-lang-pg package that adds support for the PG language in CodeMirror 6. The repository for that package is https://github.com/openwebwork/codemirror-lang-pg, and the npm package at https://www.npmjs.com/package/@openwebwork/codemirror-lang-pg.
The pg-problem-editor package is designed so that it can be used by webwork2, the standalone renderer, and possible others that want a PG problem editor. It may need a few tweaks to make it work for webwork3 in the future, but should also work for that.
The codemirror-lang-pg package consists of a base PG parser that is largely derived from the codemirror-lang-perl package (at https://github.com/drgrice1/codemirror-lang-perl and https://www.npmjs.com/package/codemirror-lang-perl) with a modifications specific to the perl available in a PG problem. The main differences are that its escape sequence is ~~, much of what can not be used in the safe compartment has been stripped out, and there are special blocks for PGML, PG text, and LaTeX image code. Then there are two other parsers. Those are the PGML and PG text parsers. Those parsers run on the contents of the PGML and PG text blocks found by the base PG parser. Note that the PGML parser is actually a javascript implementation of the parser in PGML.pl with some modifications to track position and things needed to associate the parsed tree with the original code.
Note that the configuration of theme, keymaps, and such are now part of the pg-codemirror-editor, and are shown in a panel of the editor instead of below as before.
Emacs and Vim keymaps are available, but at this point there is not a Sublime keymap for CodeMirror 6.
The themes that are available include a basic default theme (that is part of the pg-problem-editor package and just adds some syntax highlighting that is missing from the CodeMirror 6 default), the OndDark theme that is the only other theme provided by the CodeMirror 6 developers directly, the themes in the thememirror package, and the themes from https://github.com/craftzdog/cm6-themes which are in several separate npm packages. Note that both thememirror and craftzdog/cm6-themes provide a solarized light theme, and that is why there are two of those. They are slightly different though.
I am sure that there is a lot more work to do on this, and there are other things available with CodeMirror 6 that could probably be implemented. In any case, this is a good start.