Skip to content

SCM: Support past commit message navigation#107619

Merged
joaomoreno merged 51 commits intomasterfrom
merogge/hist
Oct 20, 2020
Merged

SCM: Support past commit message navigation#107619
joaomoreno merged 51 commits intomasterfrom
merogge/hist

Conversation

@meganrogge
Copy link
Collaborator

This PR addresses this feature request

@meganrogge meganrogge added the verification-needed Verification of issue is requested label Sep 28, 2020
@meganrogge meganrogge added this to the October 2020 milestone Sep 28, 2020
@joaomoreno joaomoreno removed the verification-needed Verification of issue is requested label Sep 30, 2020
@joaomoreno
Copy link
Member

joaomoreno commented Sep 30, 2020

@meganrogge We add verification-needed on feature requests that don't end up on an endgame test plan. @mjbvz can clarify that a little bit since we're currently in endgame.

Copy link
Member

@joaomoreno joaomoreno left a comment

Choose a reason for hiding this comment

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

At first glance, there is quite some work to do here.

The SCMInput's API should really not change much, adding 3 methods to it seems like an overkill. Could we reuse the HistoryNavigator here?

Also, that addition of build/monaco/api.js seems a mistake, let's remove it.

@joaomoreno joaomoreno marked this pull request as draft September 30, 2020 11:24
@meganrogge meganrogge added verification-needed Verification of issue is requested and removed verification-needed Verification of issue is requested labels Sep 30, 2020
@meganrogge meganrogge force-pushed the merogge/hist branch 6 times, most recently from b7374d0 to 63a04ce Compare October 1, 2020 22:11
@meganrogge
Copy link
Collaborator Author

@joaomoreno There are a few issues with the new approach:

  1. If we only save the current value when the arrows are pressed, then on window reload,
    text typed but not yet committed will not be saved (unless we use the saveCurrent method).

  2. I haven't found a way using the historyNavigator to replace / delete a value. I need this so that the current element can be replaced with a new value and so that there isn't a backlog of uncommitted messages.

For example, let's say I have 3 messages successfully committed.

message 1
message 2
message 3

and I can navigate between them. so i'm typing message 4 when I want to reference
message 2. I go up to message 2, return to message 4, successfully commit it.

then what will be in the history at that time is:

message 1
message 2
message 3
message 4 (before looking up at message 2)
message 4 completed

or I return to message 4 and change it completely to hello.

what i'll see in the history if I go back through it is:

message 1
message 2
message 3
message 4
hello

even though message 4 was not a successful commit

I'm not sure how to solve this. what I'd want to see is:

message 1
message 2
message 3
hello

do you agree this would be the expectation?

also, on the first pass through it's doing a strange thing with the order. on the way back down it's resolved and appears to store them in the correct order when debugged.

@joaomoreno
Copy link
Member

If we only save the current value when the arrows are pressed, then on window reload,
text typed but not yet committed will not be saved (unless we use the saveCurrent method).

We'd save the value when (1) the inbox box changes in interesting ways (the fromKeyboard story), (2) when navigating back in history and (3) when the workbench unloads. Here's how you can do 3.

do you agree this would be the expectation?

Absolutely! You can always change the HistoryNavigator itself to support your use case. How about adding a remove() method? That way you can remove something at will.

@meganrogge
Copy link
Collaborator Author

@joaomoreno this is working now except:

  1. The ContextKey so that the cursor must be either on the first line (for up arrow) or last line (for down arrow) of the input box. I'm not sure how to do this despite looking at the links you sent me.
  2. Regarding save on window reload, is the intended functionality that the state is preserved only when I've typed something and haven't yet committed it? or should it also preserve where you are in the history navigation? if the former, that is working. if the latter, then I will need to somehow store the actual historyNavigator itself since otherwise its state gets reset in the constructor when it's defined with the stored history values on window reload. this.historyNavigator = new HistoryNavigator(JSON.parse(history), 50);

@joaomoreno
Copy link
Member

joaomoreno commented Oct 16, 2020

@meganrogge

  1. Yeah this isn't so clear to grasp at first. I've added a commit which sets these context keys. All you have to do now it hook those context keys into the when clauses of the keybindings.
  2. When the workbench comes up, the user should always be pointing to the last element in the history. Right now I don't really see that happening, following these steps: (1) type something, (2) press Up to see the previous message in history and (3) reload - the value I typed is gone. I expected to see the value I typed in step (1), as it is the last item in history.

A few other issues I see:

  • (1) Open the workbench, box is empty, (2) press Up to see the last message, (3) press Down to go back to empty -> 🐛 it doesn't
  • (2) Open the workbench, box is empty, (2) type anything, (3) press Up -> 🐛 nothing happens, it only works if I press Up twice

Idea: why not allowing the history to store the empty string as a value? Raising that restriction will let you fix issue (1) above and will let you just store strings, instead of storing strings and booleans in history.

@meganrogge meganrogge force-pushed the merogge/hist branch 2 times, most recently from d691539 to 3174834 Compare October 16, 2020 17:27
@meganrogge
Copy link
Collaborator Author

meganrogge commented Oct 16, 2020

@joaomoreno
Re issue 1, I had thought we wanted to model the search editor behavior. But after discussing this with Kai, I agree it should behave as you describe.
Both issues have been addressed.
The reason we need the boolean is because otherwise we don't know which element to delete

@meganrogge meganrogge force-pushed the merogge/hist branch 2 times, most recently from ae43d14 to 814f8e3 Compare October 17, 2020 19:24
@joaomoreno
Copy link
Member

joaomoreno commented Oct 19, 2020

@meganrogge First off: this was a hard work item. Even I failed to grasp the complexity of the issue. As I reviewed it this time I decided to go ahead and finalize it by making some changes. You did a good job, but ultimately were hitting issues of the current HistoryNavigator. Let me explain.

The current HistoryNavigator is weird. It lets the navigation go out of its bound, which is really nasty and misaligns with the fact that we want to store the current editing value as the last of the history. This is the reason why you couldn't simply store strings. It was also the source of bugs like having to press Up twice or going beyond the history array bounds accidentally.

I took the time to write a new HistoryNavigator2 which never lets the cursor go outside a history. It's implemented as a linked list, so capping its size is cheap. The caveat with it is that it doesn't remove duplicates, since I didn't think that was too important. But feel free to add that capability to HistoryNavigator2 if you think it is, should be pretty easy. Ultimately, it lets us just store strings, while keeping our code much smaller and easy to reason about. Please give it a look, try it out and let me know what you think.

Some notes on the work:

As you test this, remember to try it in a new workspace, since the storage in your test workspace contains the array of tuples, so the code will break, since it expects an array of strings.

Overall great work, you really pushed this forward! 👏

@meganrogge meganrogge marked this pull request as ready for review October 19, 2020 16:39
@meganrogge
Copy link
Collaborator Author

We currently have a precommit rule which prevents you from committing mistakes like this. How were you able to create these commits?

probably by using the --no-verify flag on occasion. I won't do that going forward.

@meganrogge
Copy link
Collaborator Author

@joaomoreno it's now working as expected. I'll wait for your final sign-off to merge it.

Copy link
Member

@joaomoreno joaomoreno left a comment

Choose a reason for hiding this comment

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

Your fix wasn't quite there yet. That change broke the save on reload functionality. The right fix here would be to call replaceLast on the history only if the user is currently typing their message (isAtEnd() === true). My bad! 🙈 I've pushed those changes.

I've tested it more and feels great, what do you think? Merging this in! 💪 Further fixes can land in master directly, if necessary.

fireworks

this.storageService.onWillSaveState(e => {
if (e.reason === WillSaveStateReason.SHUTDOWN) {
this.historyNavigator.replaceLast(this._value);
this.historyNavigator.replaceLast(this.historyNavigator.last());
Copy link
Member

@joaomoreno joaomoreno Oct 20, 2020

Choose a reason for hiding this comment

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

No I don't think this is correct. This code does nothing since it ends up doing this.tail.value = this.tail.value...

Plus it breaks functionality: (1) type something in the commit box, (2) reload 🐛 message is not there.


constructor(history: readonly T[], private capacity: number = 10) {
if (history.length <= 1) {
if (history.length < 1) {
Copy link
Member

@joaomoreno joaomoreno Oct 20, 2020

Choose a reason for hiding this comment

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

Yup, my bad! 👍

@joaomoreno joaomoreno merged commit 4af4249 into master Oct 20, 2020
@joaomoreno joaomoreno deleted the merogge/hist branch October 20, 2020 08:04
jmannanc pushed a commit to jmannanc/vscode that referenced this pull request Oct 26, 2020
* logging prior commit messages

* Logging prior commit messages

* Logging prior commit messages

* now works in forward and backward directions

* reset index on empty input

* cleaning up code

* introduce historyNavigator, working but not persisting on window reload

* introduce historyNavigator, working but not persisting on window reload

* add history

* saves search entries on window reload but doesn't save last typed message in input box

* save input

* change where the save occurs

* working

* add remove last method

* now replaces most recent input

* remove check for null value

* now at least lets you see most recent commit

* before adding objects

* add scmi value class

* add scmi value class

* new commit

* fix removal / insertion order

* change function modifiers

* working correctly

* change conditional

* undo inadvertant changes

* Update README.md

* fix tricky bug

* working and removed unnecessary conditional

* fix another bug

* make elements private again

* change order of save

* now working as expected, about to add context keys

* hook up context keys

* save on shutdown

* improve variable name

* disable show prior/next commit when there's no history and ensure that input is last in history

* formatting

* add new history navigator

* fix bad ==

* rename scm input history methods

* adopt HistoryNavigator2 in SCMInput

* remove unnecessary method

* revert history.ts

* 💄

* change size of history required to be valid

* revert change

* on reload, display latest input

* remove rogue console.log

* fix issue with saving uncommitted message

Co-authored-by: João Moreno <[email protected]>
@meganrogge meganrogge linked an issue Oct 29, 2020 that may be closed by this pull request
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCM: Support past commit messages navigation

2 participants