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

[WIP] File Watcher #44

Draft
wants to merge 72 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
b0da10c
Add filewatcher based on gitsigns implementation. This should set up a
CKolkey Jun 25, 2023
2ba5e57
Add debounce_trailing to utils
CKolkey Jun 25, 2023
9502ef7
Fix bug where setup is run twice, and initialize file watcher in setup.
CKolkey Jun 25, 2023
491cae3
Since the watcher now is only run in an async context, some of the repo
CKolkey Jun 25, 2023
f4c641a
Because the repo is now refreshed in async context, just refresh the
CKolkey Jun 25, 2023
c72bdf7
Remove autocmd - this is a poorer implementation of the filewatcher
CKolkey Jun 25, 2023
fc594aa
remove scheduler from all actions - remove manual status updates
CKolkey Jun 25, 2023
3114284
fix filepaths
CKolkey Jun 25, 2023
5c96a55
Mostly working
CKolkey Jun 26, 2023
547fae5
Add debug command to print repo state
CKolkey Jun 26, 2023
05f907f
Cleanup
CKolkey Jun 26, 2023
6a802b4
Ensure state is always updated, even if we bail early
CKolkey Jun 26, 2023
f4c23f3
bugfix: get envs properly
CKolkey Jun 26, 2023
7a869d2
notes
CKolkey Jun 26, 2023
68e1ad8
Use client.wrap for commit
CKolkey Jun 26, 2023
154cb23
Add source to repo refresh
CKolkey Jun 26, 2023
638bc35
Make watcher fn async
CKolkey Jun 26, 2023
5b1c6c5
Add cwd/git_root to the initializer in repo
CKolkey Jun 26, 2023
886b077
Rewrite repo refresh to use semaphore to prevent multiple refreshes
CKolkey Jun 26, 2023
e80ba09
Allow console highlights
CKolkey Jun 26, 2023
fbbba45
Use internal state and improve logging
CKolkey Jun 26, 2023
9f8faa5
Add NeogitMessages user command
CKolkey Jun 26, 2023
45f08f1
Don't expose _refresh publicly
CKolkey Jun 26, 2023
c8d665a
hide git-path details
CKolkey Jun 26, 2023
8cab98c
This needs items for rendering
CKolkey Jun 27, 2023
58f0041
Bugfix: Include count (current) and discard blank lines
CKolkey Jun 27, 2023
7a61015
Add logging to builder
CKolkey Jun 27, 2023
f6ba27f
Use git root for watcher path
CKolkey Jun 27, 2023
afb98b7
Organize
CKolkey Jun 27, 2023
fc2f6c6
Formatting
CKolkey Jun 28, 2023
91967ef
Reformat to be more friendly to lsp's goto definition
CKolkey Jul 1, 2023
368cc4e
Add notes
CKolkey Jul 1, 2023
b7d9a73
Make filewatcher slightly less aggressive
CKolkey Jul 1, 2023
ecf55e2
Add status.update() function that will refresh repo state then redraw
CKolkey Jul 1, 2023
b4c32c8
Alphabetize git barrel imports
CKolkey Jul 1, 2023
aa7bbdf
pull this function into a new git lib, "index"
CKolkey Jul 1, 2023
ee74024
Increase watcher debounce from 100ms to 300ms
CKolkey Jul 1, 2023
3d8a32c
Tune up logging
CKolkey Jul 1, 2023
b3dcf90
Don't print debug info for invalidating diffs that don't exist
CKolkey Jul 1, 2023
0f114fa
Add back mechanism for invalidating only specific diffs
CKolkey Jul 1, 2023
568fbda
Formatting
CKolkey Jul 1, 2023
c3f58eb
Add index updating visitor to track the git index. Without this the
CKolkey Jul 1, 2023
9433fcf
test
CKolkey Jul 1, 2023
20bd319
test empty
CKolkey Jul 1, 2023
78bea0e
Add logging for diff metatable
CKolkey Jul 2, 2023
869c6b8
Fix logging
CKolkey Jul 2, 2023
10d13fe
formatting
CKolkey Jul 3, 2023
d764411
It's a hash-like table so this needs to be called manually
CKolkey Jul 3, 2023
ae49278
Test out a more limited watcher
CKolkey Jul 3, 2023
95cea90
revert this: not picking up enough external events
CKolkey Jul 4, 2023
bccb548
refactor: extract git functions from status buffer into git lib
CKolkey Jul 4, 2023
4e72b92
extract util function
CKolkey Jul 4, 2023
8b54890
Revert
CKolkey Jul 4, 2023
84776f6
formatting
CKolkey Jul 4, 2023
8456dca
Clean up status
CKolkey Jul 4, 2023
524e7d3
Add notes on vim.system
CKolkey Jul 5, 2023
3e0071b
Use lua instead of c
CKolkey Jul 5, 2023
ad26f44
Run all update functions async, with a callback after they're done. Much
CKolkey Jul 5, 2023
cac1dcc
cleanup
CKolkey Jul 5, 2023
c375ae4
Reorder lock
CKolkey Jul 5, 2023
1f25512
Log and only update status once
CKolkey Jul 5, 2023
27971af
lint: unused variables
CKolkey Jul 10, 2023
4c8ae4e
fix/lint
CKolkey Jul 10, 2023
c11e444
Standardize option
CKolkey Jul 11, 2023
389ba29
Confirm modifying a commit if it has already been published upstream
CKolkey Jul 11, 2023
4d68bef
Allow for rebasing onto pushremote, and add 'b' action to rebase onto
CKolkey Jul 11, 2023
38dc48d
Remove duplicate and add highlight to base branch name
CKolkey Jul 12, 2023
e81232f
If remote.defaultPush is set, use that instead of blank
CKolkey Jul 12, 2023
e1f4ae8
Revert "Revert "expand on branch popup spec""
CKolkey Jul 13, 2023
072ecb6
Merge branch 'master' into file-watcher-wip
CKolkey Jul 15, 2023
4a75403
Merge branch 'master' into file-watcher-wip
CKolkey Jul 15, 2023
3f249d2
Merge branch 'master' into file-watcher-wip
CKolkey Jul 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lua/neogit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local hl = require("neogit.lib.hl")
local status = require("neogit.status")
local state = require("neogit.lib.state")
local input = require("neogit.lib.input")
local watcher = require("neogit.watcher")
local logger = require("neogit.logger")

local cli = require("neogit.lib.git.cli")
Expand Down Expand Up @@ -39,8 +40,7 @@ local setup = function(opts)
hl.setup()
signs.setup()
state.setup()

require("neogit.autocmds").setup()
watcher.setup()
end

---@param opts OpenOpts
Expand Down Expand Up @@ -71,6 +71,8 @@ local open = function(opts)
end
end

require("neogit.lib.git").repo:dispatch_refresh { source = "open" }

if opts[1] ~= nil then
local popup_name = opts[1]
local has_pop, popup = pcall(require, "neogit.popups." .. popup_name)
Expand Down
35 changes: 0 additions & 35 deletions lua/neogit/autocmds.lua

This file was deleted.

3 changes: 0 additions & 3 deletions lua/neogit/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ function M.wrap(cmd, opts)
else
notif.create(opts.msg.fail)
end

a.util.scheduler()
require("neogit.status").refresh(true, opts.refresh)
end

return M
2 changes: 0 additions & 2 deletions lua/neogit/integrations/diffview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ local dv_lib = require("diffview.lib")
local dv_utils = require("diffview.utils")

local neogit = require("neogit")
local status = require("neogit.status")
local a = require("plenary.async")

local old_config
Expand Down Expand Up @@ -132,7 +131,6 @@ local function get_local_diff_view(selected_file_name)
}

view:on_files_staged(a.void(function(_)
status.refresh({ status = true, diffs = true }, "on_files_staged")
view:update_files()
end))

Expand Down
30 changes: 15 additions & 15 deletions lua/neogit/lib/git.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
return {
repo = require("neogit.lib.git.repository"),
branch = require("neogit.lib.git.branch"),
cherry_pick = require("neogit.lib.git.cherry_pick"),
cli = require("neogit.lib.git.cli"),
init = require("neogit.lib.git.init"),
status = require("neogit.lib.git.status"),
stash = require("neogit.lib.git.stash"),
files = require("neogit.lib.git.files"),
config = require("neogit.lib.git.config"),
diff = require("neogit.lib.git.diff"),
fetch = require("neogit.lib.git.fetch"),
files = require("neogit.lib.git.files"),
index = require("neogit.lib.git.index"),
init = require("neogit.lib.git.init"),
log = require("neogit.lib.git.log"),
reflog = require("neogit.lib.git.reflog"),
branch = require("neogit.lib.git.branch"),
diff = require("neogit.lib.git.diff"),
rebase = require("neogit.lib.git.rebase"),
merge = require("neogit.lib.git.merge"),
cherry_pick = require("neogit.lib.git.cherry_pick"),
pull = require("neogit.lib.git.pull"),
push = require("neogit.lib.git.push"),
rebase = require("neogit.lib.git.rebase"),
reflog = require("neogit.lib.git.reflog"),
remote = require("neogit.lib.git.remote"),
repo = require("neogit.lib.git.repository"),
reset = require("neogit.lib.git.reset"),
revert = require("neogit.lib.git.revert"),
remote = require("neogit.lib.git.remote"),
config = require("neogit.lib.git.config"),
sequencer = require("neogit.lib.git.sequencer"),
pull = require("neogit.lib.git.pull"),
push = require("neogit.lib.git.push"),
index = require("neogit.lib.git.index"),
stash = require("neogit.lib.git.stash"),
status = require("neogit.lib.git.status"),
}
18 changes: 13 additions & 5 deletions lua/neogit/lib/git/diff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ local function build_metatable(f, raw_output_fn)
end,
})

logger.trace("[DIFF] Adding metatable for: " .. f.name)
f.has_diff = true
end

Expand Down Expand Up @@ -215,20 +216,27 @@ local function raw_staged(name)
end
end

-- When there is _no_ filter, invalidate all diffs
-- When there _is_ a filter, only invalidate matching items
-- And, of course, don't worry about items that haven't loaded diffs
local function invalidate_diff(filter, section, item)
if not rawget(item, "diff") then
return
end

if not filter or filter:accepts(section, item.name) then
logger.debug("[DIFF] Invalidating cached diff for: " .. item.name)
logger.debug(string.format("[DIFF] Invalidating diff for: %s", item.name))
item.diff = nil
end
end

return {
parse = parse_diff,
register = function(meta)
meta.update_diffs = function(repo, filter)
filter = filter or false
if filter and type(filter) == "table" then
filter = ItemFilter.create(filter)
meta.update_diffs = function(repo)
local filter
if repo.invalidate[1] then
filter = ItemFilter.create(repo.invalidate)
end

for _, f in ipairs(repo.untracked.items) do
Expand Down
6 changes: 6 additions & 0 deletions lua/neogit/lib/git/index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ function M.update()
:spawn_async()
end

function M.register(meta)
meta.update_index = function(state)
state.index.timestamp = state.index_stat()
end
end

return M
3 changes: 1 addition & 2 deletions lua/neogit/lib/git/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ M.init_repo = function()
vim.cmd(string.format("cd %s", directory))

M.create(directory)

status.refresh(true, "InitRepo")
status.refresh()
end

return M
4 changes: 3 additions & 1 deletion lua/neogit/lib/git/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ function M.list(options, show_popup)
table.insert(options, "--max-count=256")
end

local output = cli.log.format(format).graph.arg_list(options or {}).show_popup(show_popup).call():trim()
local output =
cli.log.format(format).graph.arg_list(options or {}).show_popup(show_popup).call_sync():trim()

return parse_log(output.stdout, graph)
end

Expand Down
1 change: 1 addition & 0 deletions lua/neogit/lib/git/merge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local M = {}

local a = require("plenary.async")

-- TODO: client.wrap()
local function merge_command(cmd)
local envs = client.get_envs_git_editor()
return cmd.env(envs).show_popup(true):in_pty(true).call(true)
Expand Down
3 changes: 2 additions & 1 deletion lua/neogit/lib/git/pull.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local util = require("neogit.lib.util")

local M = {}

-- TODO: client.wrap()
function M.pull_interactive(remote, branch, args)
local client = require("neogit.client")
local envs = client.get_envs_git_editor()
Expand All @@ -14,7 +15,7 @@ local function update_unpulled(state)
return
end

local result = cli.log.oneline.for_range("..@{upstream}").show_popup(false).call():trim().stdout
local result = cli.log.oneline.for_range("..@{upstream}").show_popup(false).call_sync():trim().stdout

state.unpulled.items = util.map(result, function(x)
return { name = x }
Expand Down
4 changes: 1 addition & 3 deletions lua/neogit/lib/git/rebase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local M = {}

local a = require("plenary.async")

-- TODO: client.wrap()
local function rebase_command(cmd)
local git = require("neogit.lib.git")
cmd = cmd or git.cli.rebase
Expand All @@ -22,9 +23,6 @@ function M.rebase_interactive(commit, args)
else
notif.create("Rebased successfully", vim.log.levels.INFO)
end
a.util.scheduler()
local status = require("neogit.status")
status.refresh(true, "rebase_interactive")
end

function M.rebase_onto(branch, args)
Expand Down
Loading