Skip to content

File watcher wip #614

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

Closed
wants to merge 99 commits into from
Closed

File watcher wip #614

wants to merge 99 commits into from

Conversation

CKolkey
Copy link
Member

@CKolkey CKolkey commented Jul 15, 2023

Major changes:

Watcher

  • Adds a filesystem watcher, which keeps an eye on the .git/ folder. Any changes will refresh the internal state for the repo. The major advantage of this is that during things like a cherry pick, merge, or rebase, etc, the status buffer will always be correct. The filesystem watcher is debounced to prevent over-eager refreshing.

Repo

  • Adds #dispatch_refresh to refresh the repo state in an async context.
  • A semaphore is used to prevent both action-triggered refreshing and watcher-triggered refreshing from happening concurrently.
  • Add a table for invalidating diffs. Mostly used when staging/unstaging files.
  • index_stat added to capture timestamp of .git/index and not refresh repo state if the timestamp hasn't changed. Possibly dumb.

Status

  • status.refresh() no longer takes a table for which things to refresh. We can just refresh everything every time as it's always done in an async context.
  • Remove the refresh lock stuff, since the repo is what will always trigger a refresh, and that has a lock instead.
  • add M.update() calls to some of the status buffer actions to trigger a state refresh.
  • M.get_status() doesn't seem to be used anywhere.. Though now I'm wondering if it's not part of our "public api" :\

Other

  • Remove the responsibility of popup actions to call a.util.scheduler() and status.refresh(). The action's function is wrapped, and the scheduler/status functions are always invoked. The biggest disadvantage of this is you don't see the name of the function that ran, but in practice that wasn't used.

CKolkey added 30 commits July 13, 2023 14:56
single watcher on the .git/ dir, and run the callback fn whenever any
files are changed.
update functions now no longer need to be async - in fact, being async
breaks things. So, these calls can now just be sync calls.
CKolkey added 6 commits August 1, 2023 23:07
tracked are wrapped in operation() function, which sets value. The value
is only cleared after the status buffer finishes redrawing.

This is a little hacky, and everything works _fine_ without it, but it's
for the test suite. Async stuff is tough to test.
not return until the current operation (reset) is done
@CKolkey CKolkey requested a review from ten3roberts August 1, 2023 21:23
@CKolkey CKolkey marked this pull request as draft August 4, 2023 21:37
@CKolkey CKolkey mentioned this pull request Aug 27, 2023
@ofseed
Copy link
Contributor

ofseed commented Aug 31, 2023

Could this PR solve the problem of existing buffers not being refreshed after switching branches using neogit?

@CKolkey
Copy link
Member Author

CKolkey commented Aug 31, 2023

Could this PR solve the problem of existing buffers not being refreshed after switching branches using neogit?

Hm. Maybe? I actually already merged a version of this a few days ago, so you can tell me if it works how you expect or not :)

@ofseed
Copy link
Contributor

ofseed commented Sep 1, 2023

I tried switching branches or cherry-picking, but I still need to execute :e to refresh existing buffers.

What makes me most curious is that gitsigns will refresh the existing buffer signs after performing these operations, which may mean that gitsigns also has a relatively complete "file watcher"? I don't quite understand the difficulty of this matter. The "better file change detection" on the Neovim roadmap seems to have been around for many years.

@CKolkey
Copy link
Member Author

CKolkey commented Sep 1, 2023

Could you make a screen recording and open an issue? I cherry pick/change branches all the time and the status buffer is always right.

Also, will refresh the buffer too :)

@ofseed
Copy link
Contributor

ofseed commented Sep 1, 2023

Of course.

2023-09-01.19-13-38.mp4

@CKolkey
Copy link
Member Author

CKolkey commented Sep 1, 2023

Of course.

2023-09-01.19-13-38.mp4

Ohh! You mean the buffer. Thats not going to be managed by neogit, but you can add an autocmd on "FocusGained", "BufEnter", "CursorHold" events that runs silent! checktime % to have vim check if the file has been updated.

@ofseed
Copy link
Contributor

ofseed commented Sep 1, 2023

Thank you! That's very useful.

Some git integrations like fugitive, could reload the buffer after these commands are executed. If you are not interested in such a feature, I might implement it when I have free time.

@CKolkey
Copy link
Member Author

CKolkey commented Sep 1, 2023

You're welcome! If you want to, thats alright, but I'm hesitant to start messing with users open buffers. I kinda want to draw a line that starts at the status buffer, and say that everything from the status buffer onwards is ours, but everything before that is not.

@CKolkey CKolkey closed this Sep 2, 2023
@CKolkey CKolkey deleted the file-watcher-wip branch April 10, 2024 21:53
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.

3 participants