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

Highlight the background of the statement sent to REPL #1382

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

aqjune
Copy link
Contributor

@aqjune aqjune commented Feb 5, 2024

This patch highlights the background of the statement that was sent to REPL.

To set the color, ocaml.repl.evalTextBackgroundColor is newly added as a configuration.

Modifying any character in the editor before or in the selected region will remove the highlighted background.

This patch highlights the background of the statement that was sent to REPL.

To set the color, ocaml.repl.evalTextBackgroundColor is newly added as a configuration.

To remove the highlighted background, selecting an empty range and sending it to REPL works.
@aqjune
Copy link
Contributor Author

aqjune commented Feb 19, 2024

ping

Copy link
Collaborator

@mnxn mnxn left a comment

Choose a reason for hiding this comment

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

To remove the highlighted background, selecting an empty range and sending it to REPL works.

This seems a bit unintuitive since doing Shift+Enter without a selection will select the entire line. That means removing the highlight specifically requires selecting whitespace or doing Shift+Enter on a blank line.

Keeping this functionality is fine, but I think there should also be an additional command to remove the highlighting.

package.json Outdated Show resolved Hide resolved
src/repl.ml Outdated Show resolved Hide resolved
@aqjune
Copy link
Contributor Author

aqjune commented Feb 20, 2024

Hi, thanks for your comments! I could not manage to find a time for addressing your comments today. I will reflect them tomorrow.

@@ -199,4 +251,22 @@ let register extension instance =
Extension_instance.close_repl instance)
()
in
Vscode.ExtensionContext.subscribe extension ~disposable;
let disposable =
Vscode.Workspace.onDidChangeTextDocument () ~listener:(fun event ->
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 added this onDidChangeTextDocument that unsets the highlighted color if there is any update inside or before the evaluated region.

@aqjune
Copy link
Contributor Author

aqjune commented Feb 27, 2024

Hi, sorry for my delay. I reflected the comments so far.

@smorimoto
Copy link
Collaborator

Could you please add a change log entry?

Copy link
Collaborator

@ulugbekna ulugbekna left a comment

Choose a reason for hiding this comment

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

Frankly, I'm not sure it's useful to color the background for the current behavior of the REPL since the text sent is based either on the selection which is already colored or the current line if selection is empty. The sent text is also visible in the REPL. Do you have cases when such background would be useful?

do others have opinion on this?

src/repl.ml Outdated
Comment on lines 169 to 170
let prevEvalTextDecorationType : TextEditorDecorationType.t option ref =
ref None
Copy link
Collaborator

Choose a reason for hiding this comment

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

to my knowledge, we don't put mutable state in a module but put it in ExtensionContext, possibly within a record that's related to repl functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your comments. I addressed this and two following comments in the newest commit.

src/repl.ml Outdated
let prevEvalTextDecorationType : TextEditorDecorationType.t option ref =
ref None

let prevEvalTextDecorationRange : Range.t option ref = ref None
Copy link
Collaborator

Choose a reason for hiding this comment

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

camelCase is used only for vscode bindings (only symbols defined at src-bindings/)

src/repl.ml Outdated
Comment on lines 263 to 266
let h = List.hd poss in
match h with
| None -> ()
| Some h ->
Copy link
Collaborator

@ulugbekna ulugbekna Mar 3, 2024

Choose a reason for hiding this comment

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

this could be directly a pattern match on the list

match poss with 
| [] -> ()
| h::_ -> ...

@aqjune
Copy link
Contributor Author

aqjune commented Mar 3, 2024

Frankly, I'm not sure it's useful to color the background for the current behavior of the REPL since the text sent is based either on the selection which is already colored or the current line if selection is empty. The sent text is also visible in the REPL. Do you have cases when such background would be useful?

Yes, I felt this feature was necessary when I was evaluating the text in REPL which is taking a long time.
While the text is evaluating, I cannot unselect the text and edit the .ml program because it makes me lose which text I was evaluating before.
Evaluating the sent text typically prints lots of information to show the progress on REPL, hiding the latest sentence that was evaluated.

Specifically, I am using vscode-ocaml-platform to write an OCaml program that uses HOL Light (https://github.com/jrh13/hol-light/).
OCaml programmer can use HOL Light to define a mathematical theorem and prove it step-by-step.
An HOL Light program is supposed to run on OCaml REPL rather than compile it as a binary because the user needs to interact with the proof state after each step.
This is computation intensive, and evaluating one sentence can easily take several minutes. Therefore evaluating a sentence and writing a code in parallel is important for saving time. It is also important to not lose which statement I had executed before.

An Emacs plugin called ProofGeneral has a similar feature. It is an editor for a language called Coq, which is similar to OCaml but for more mathematical purpose.
https://www.youtube.com/watch?v=l6zqLJQCnzo shows how the evaluated text is colored as blue. A small difference between this plug in and our case is that it highlights the text up from the very beginning of the file, but this is because in ProofGeneral a program must be sequentially evaluated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants