mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-13 17:40:25 +00:00
fix #68 marks not saving due to over-writing by multiple vim instances
As described in #68, the global HarpoonConfig of vim instance 2 does not get updated if marks in vim instance 1 change, as described by @freehaha. This fix remedies the situation by refreshing marks for all other projects before saving HarpoonConfig to disk.
This commit is contained in:
parent
0c0b37d065
commit
fe5ffd59f7
@ -120,6 +120,9 @@ local function expand_dir(config)
|
||||
end
|
||||
|
||||
M.save = function()
|
||||
-- first refresh from disk everything but our project
|
||||
M.refresh_projects_b4update()
|
||||
|
||||
log.trace("save(): Saving cache config to", cache_config)
|
||||
Path:new(cache_config):write(vim.fn.json_encode(HarpoonConfig), "w")
|
||||
end
|
||||
@ -176,6 +179,49 @@ M.get_global_settings = function()
|
||||
return HarpoonConfig.global_settings
|
||||
end
|
||||
|
||||
|
||||
-- refresh all projects from disk, except our current one
|
||||
M.refresh_projects_b4update = function()
|
||||
log.trace("refresh_projects_b4update(): refreshing other projects", cache_config)
|
||||
-- save current runtime version of our project config for merging back in later
|
||||
local cwd = vim.loop.cwd()
|
||||
local current_p_config = {
|
||||
projects = {
|
||||
[cwd] = ensure_correct_config(HarpoonConfig).projects[cwd]
|
||||
}
|
||||
}
|
||||
|
||||
-- erase all projects from global config, will be loaded back from disk
|
||||
HarpoonConfig.projects = nil
|
||||
|
||||
-- this reads a stale version of our project but up-to-date versions
|
||||
-- of all other projects
|
||||
local ok2, c_config = pcall(read_config, cache_config)
|
||||
|
||||
if not ok2 then
|
||||
log.debug("refresh_projects_b4update(): No cache config present at", cache_config)
|
||||
c_config = {}
|
||||
end
|
||||
-- don't override non-project config in HarpoonConfig later
|
||||
c_config = { projects = c_config.projects }
|
||||
|
||||
-- erase our own project, will be merged in from current_p_config later
|
||||
c_config.projects[cwd] = nil
|
||||
|
||||
local complete_config = merge_tables(
|
||||
HarpoonConfig,
|
||||
expand_dir(c_config),
|
||||
expand_dir(current_p_config))
|
||||
|
||||
-- There was this issue where the vim.loop.cwd() didn't have marks or term, but had
|
||||
-- an object for vim.loop.cwd()
|
||||
ensure_correct_config(complete_config)
|
||||
|
||||
HarpoonConfig = complete_config
|
||||
log.debug("refresh_projects_b4update(): Complete config", HarpoonConfig)
|
||||
log.trace("refresh_projects_b4update(): log_key", Dev.get_log_key())
|
||||
end
|
||||
|
||||
M.get_term_config = function()
|
||||
log.trace("get_term_config()")
|
||||
return ensure_correct_config(HarpoonConfig).projects[vim.loop.cwd()].term
|
||||
|
Loading…
x
Reference in New Issue
Block a user