Call dmon_unwatch when changing project
Fix a conspicuous omission to call the dmon_unwatch function when changing project directory. This uncovered a bug or a quirk of the dmon library where the watch_ids can change as a result of calling dmon_unwatch because they are just indexes on a contiguous array. Use a workaround to always unwatch the first valid watch_id N times.
This commit is contained in:
parent
d0b99a598d
commit
f9a776852e
|
@ -164,7 +164,10 @@ command.add(nil, {
|
||||||
core.error("Cannot open folder %q", text)
|
core.error("Cannot open folder %q", text)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
core.confirm_close_docs(core.docs, core.open_folder_project, text)
|
core.confirm_close_docs(core.docs, function(dirpath)
|
||||||
|
core.close_current_project()
|
||||||
|
core.open_folder_project(dirpath)
|
||||||
|
end, text)
|
||||||
end, suggest_directory)
|
end, suggest_directory)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,22 @@ function core.set_project_dir(new_dir, change_project_fn)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function core.close_current_project()
|
||||||
|
-- When using system.unwatch_dir we need to pass the watch_id provided by dmon.
|
||||||
|
-- In reality when unwatching a directory the dmon library shifts the other watch_id
|
||||||
|
-- values so the actual watch_id changes. To workaround this problem we assume the
|
||||||
|
-- first watch_id is always 1 and the watch_id are continguous and we unwatch the
|
||||||
|
-- first watch_id repeateadly up to the number of watch_ids.
|
||||||
|
local watch_id_max = 0
|
||||||
|
for _, project_dir in ipairs(core.project_directories) do
|
||||||
|
if project_dir.watch_id and project_dir.watch_id > watch_id_max then
|
||||||
|
watch_id_max = project_dir.watch_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i = 1, watch_id_max do
|
||||||
|
system.unwatch_dir(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function core.open_folder_project(dir_path_abs)
|
function core.open_folder_project(dir_path_abs)
|
||||||
if core.set_project_dir(dir_path_abs, core.on_quit_project) then
|
if core.set_project_dir(dir_path_abs, core.on_quit_project) then
|
||||||
|
|
|
@ -707,6 +707,13 @@ static int f_watch_dir(lua_State *L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int f_unwatch_dir(lua_State *L) {
|
||||||
|
dmon_watch_id watch_id;
|
||||||
|
watch_id.id = luaL_checkinteger(L, 1);
|
||||||
|
dmon_unwatch(watch_id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if __linux__
|
#if __linux__
|
||||||
static int f_watch_dir_add(lua_State *L) {
|
static int f_watch_dir_add(lua_State *L) {
|
||||||
dmon_watch_id watch_id;
|
dmon_watch_id watch_id;
|
||||||
|
@ -810,6 +817,7 @@ static const luaL_Reg lib[] = {
|
||||||
{ "fuzzy_match", f_fuzzy_match },
|
{ "fuzzy_match", f_fuzzy_match },
|
||||||
{ "set_window_opacity", f_set_window_opacity },
|
{ "set_window_opacity", f_set_window_opacity },
|
||||||
{ "watch_dir", f_watch_dir },
|
{ "watch_dir", f_watch_dir },
|
||||||
|
{ "unwatch_dir", f_unwatch_dir },
|
||||||
{ "path_compare", f_path_compare },
|
{ "path_compare", f_path_compare },
|
||||||
#if __linux__
|
#if __linux__
|
||||||
{ "watch_dir_add", f_watch_dir_add },
|
{ "watch_dir_add", f_watch_dir_add },
|
||||||
|
|
Loading…
Reference in New Issue