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

feat: adding option for interpreting to exact cursor position or next command during interpret to point #875

Merged
merged 4 commits into from
Sep 14, 2024

Conversation

Durbatuluk1701
Copy link
Contributor

This PR adds a "interpret to next point" that will take the current cursor position and if it is part of a tactic then it will interpret through the completion of that tactic.

This should fix #870

Some test cases have also been added to test the function to find the end of the next tactic.

I am not sure if we want this to be the default behavior for continuous mode or should be an option that can be enabled.

@Durbatuluk1701
Copy link
Contributor Author

Another possibility I have considered is that the getNextPosition function could be utilized in continuous mode to help prevent repeatedly sending interpretToPoint requests that won't change the proof state since they are mid tactic.

For example (where | represents a cursor):
ta|c1. tac2 transitioning to tac|1. tac2
Should not need a new interpretToPoint request as no proof state change would occur.

@rtetley
Copy link
Collaborator

rtetley commented Aug 26, 2024

I like this ! However I wonder if finding the correct position should be done on the server side rather. What do you think @gares ?

@rtetley
Copy link
Collaborator

rtetley commented Aug 26, 2024

Also I think it should be an option maybe other users can give their sentiment about this ?

Copy link
Collaborator

@gares gares left a comment

Choose a reason for hiding this comment

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

I love it too, thanks!

The lang server knows the end of sentences, it should compute what next means.

@SkySkimmer
Copy link
Contributor

This PR adds a "interpret to next point" that will take the current cursor position and if it is part of a tactic then it will interpret through the completion of that tactic.

Is it actually tactic specific? I guess it probably works for any command (eg Definition foo1 |:= 1. Definition foo2 := 2.)

@Durbatuluk1701
Copy link
Contributor Author

This PR adds a "interpret to next point" that will take the current cursor position and if it is part of a tactic then it will interpret through the completion of that tactic.

Is it actually tactic specific? I guess it probably works for any command (eg Definition foo1 |:= 1. Definition foo2 := 2.)

You are correct it isn't tactic specific. I think my wording is definitely wrong, but I think any solution that would fix #870 would probably need to be general/work for any command and not tactic specific.

@Durbatuluk1701
Copy link
Contributor Author

I love it too, thanks!

The lang server knows the end of sentences, it should compute what next means.

Sounds good, I can start working on that.

One point of clarification, do we want a separate "interpretToNextPoint" sort of command (that would be utilized by continuous mode), or to modify the existing "interpretToPoint" functionality to interpret to the next command?

I think the primary difference would be how using "interpretToPoint" works when in manual mode.

@rtetley
Copy link
Collaborator

rtetley commented Sep 2, 2024

I love it too, thanks!
The lang server knows the end of sentences, it should compute what next means.

Sounds good, I can start working on that.

One point of clarification, do we want a separate "interpretToNextPoint" sort of command (that would be utilized by continuous mode), or to modify the existing "interpretToPoint" functionality to interpret to the next command?

I think the primary difference would be how using "interpretToPoint" works when in manual mode.

Yes I think we should create a interpretToNextPoint function in the server. We then create a boolean server setting that can be toggled from the front end. Depending on that setting a vscoq/interpretToPoint request calls one or the other.

@Durbatuluk1701 Durbatuluk1701 force-pushed the cursor-nav-improvements branch 2 times, most recently from b02cc22 to 6191e97 Compare September 9, 2024 01:40
@Durbatuluk1701 Durbatuluk1701 changed the title Modifying continuous mode to interpret to the next tactic Adding option for interpreting to exact cursor position or next command during interpret to point Sep 9, 2024
@Durbatuluk1701
Copy link
Contributor Author

Pushed some changes to make it so that the computation occurs on the server side and an option for configuring it.

I was a little confused on all the times that id_of_pos was being called and when some of those should have the next_pos switch hard-coded to false vs. when it should be propagated from above, so a keen eye reviewing some of those would be helpful.

I additionally encountered a corner case that I don't think has been addressed in the previous discussion in regard to a case with bullets like:

Lemma test : forall {A} (x y : A), x = x /\ y = y.
Proof.
  intros.
  split.
  - eauto.
  - eauto.
Qed.

Specifically for bullets, do we want -| eauto. to interpret to:

  1. -| eauto. (bullets break up commands)
  2. split.| \n - eauto. (bullets don't break up commands, roll back before any bullets)
  3. - eauto.| (bullets don't break up commands, roll forward after the bullet)

I currently have it set up to do option 1.

@TheoWinterhalter
Copy link

Option 1 is how I use interpret to point most of the time so it would be my favoured option as well.

Copy link
Collaborator

@rtetley rtetley left a comment

Choose a reason for hiding this comment

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

I think this approach will make the code more readable and avoid possible regressions due to too many API changes and unnecessary boolean flags.

language-server/vscoqtop/lspManager.ml Outdated Show resolved Hide resolved
language-server/vscoqtop/lspManager.ml Outdated Show resolved Hide resolved
@Durbatuluk1701
Copy link
Contributor Author

I think this approach will make the code more readable and avoid possible regressions due to too many API changes and unnecessary boolean flags.

Much cleaner approach indeed! Thank you for your help

@rtetley
Copy link
Collaborator

rtetley commented Sep 9, 2024

Yup ! Thanks a lot ! This is good for me ! @gares I'll let you take care of it as you requested the changes !

@gares
Copy link
Collaborator

gares commented Sep 11, 2024

I think we can improve further and kill that regexp.

Instead of computing the position of the next sentence on the RawDocument, we can do so on the (parsed) Document.
Here for example we do something similar, see the call to find_sentence_after.

let get_next_range st pos =
match id_of_pos st pos with
| None -> None
| Some id ->
match Document.get_sentence st.document id with
| None -> None
| Some { stop } ->
match Document.find_sentence_after st.document (stop+1) with

I think the easiest would be keep just one coqtopInterpretToPoint with a boolean flag and then call Dm.DocumentManager.interpret_to_position or a new Dm.DocumentManager.interpret_to_next_position. The two functions would be almost identical (but they are 2 lines each) and the latter would call a new id_of_sentence_after_pos that should look like get_next_range (the code I link above).

WDYT @rtetley , am I missing something? I don't have the time to try this solution out, but looks simpler.

@rtetley
Copy link
Collaborator

rtetley commented Sep 11, 2024

The problem is that all the other functions in the interpretToPoint function rely on the position, such as mk_proof_view_event, etc.... So you at least have to propagate the new position. Your solution would be fine as long as Dm.DocumentManager.interpret_to_next_position also returns the value of next_pos, and the we use that for the rest of the functions.

@gares
Copy link
Collaborator

gares commented Sep 11, 2024

So you at least have to propagate the new position. Your solution would be fine as long as Dm.DocumentManager.interpret_to_next_position also returns the value of next_pos, and the we use that for the rest of the functions.

Right, I missed that piece. But it still looks cleaner that the current code, no?

@rtetley
Copy link
Collaborator

rtetley commented Sep 11, 2024

So you at least have to propagate the new position. Your solution would be fine as long as Dm.DocumentManager.interpret_to_next_position also returns the value of next_pos, and the we use that for the rest of the functions.

Right, I missed that piece. But it still looks cleaner that the current code, no?

Agreed, its definitely an improvement !

@gares
Copy link
Collaborator

gares commented Sep 12, 2024

Look better to me. @rtetley would it be possible to make the boolean argument optional in the protocol so to be backwards compatible?

Comment on lines 26 to 29
type t = {
textDocument : VersionedTextDocumentIdentifier.t;
position : Position.t;
to_next_point : bool
} [@@deriving yojson]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Look better to me. @rtetley would it be possible to make the boolean argument optional in the protocol so to be backwards compatible?

I believe it is enough to make to_next_point an option. i.e.:

Suggested change
type t = {
textDocument : VersionedTextDocumentIdentifier.t;
position : Position.t;
to_next_point : bool
} [@@deriving yojson]
type t = {
textDocument : VersionedTextDocumentIdentifier.t;
position : Position.t;
to_next_point : bool option;
} [@@deriving yojson]

Copy link
Collaborator

@rtetley rtetley Sep 12, 2024

Choose a reason for hiding this comment

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

But I guess there is a larger question here, and I feel kinda silly because I am the one that suggested making this part of the protocol instead of the server options. Are we going to use both versions simultaneously ? If it makes sense to sometimes use the to_next_point: true version and false version in the same editing session we should keep it that way. Otherwise we can revert to making it a server option. What do you think @gares ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see no use case of using both behaviors at the same time :-/

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well I think then we should revert to making it an option in the server that gets sent through the configuration request ! Sorry @Durbatuluk1701 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All good, I think the iterations has made this an overall better solution for sure

@rtetley rtetley changed the title Adding option for interpreting to exact cursor position or next command during interpret to point feat: adding option for interpreting to exact cursor position or next command during interpret to point Sep 13, 2024
@rtetley
Copy link
Collaborator

rtetley commented Sep 13, 2024

@gares I can't merge this since you asked for the changes !

@rtetley rtetley merged commit e2fd089 into coq-community:main Sep 14, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

improvement for vim navigation
5 participants