Implement lazy loading of directories

When the number of files in a project directory is above the max
limit switch back to a mechanism to read directory content only
when the corresponding folder is expanded in the treeview.

When the command core:find-file is invoked the command core:open-file
is executed instead because the complete list of the project's
files is not available.

When a project search is done we search through all the files within
the project dir without indexing them.

Address issues #217 #203 #183.
This commit is contained in:
Francesco Abbate
2021-05-26 14:22:10 +02:00
parent 8acb3fae8c
commit 10fde6e264
4 changed files with 146 additions and 71 deletions
+9 -4
View File
@@ -170,12 +170,17 @@ function ResultsView:draw()
local ox, oy = self:get_content_offset()
local x, y = ox + style.padding.x, oy + style.padding.y
local files_number = core.project_files_number()
local per = self.last_file_idx / files_number
local per = files_number and self.last_file_idx / files_number or 1
local text
if self.searching then
text = string.format("Searching %d%% (%d of %d files, %d matches) for %q...",
per * 100, self.last_file_idx, files_number,
#self.results, self.query)
if files_number then
text = string.format("Searching %d%% (%d of %d files, %d matches) for %q...",
per * 100, self.last_file_idx, files_number,
#self.results, self.query)
else
text = string.format("Searching (%d files, %d matches) for %q...",
self.last_file_idx, #self.results, self.query)
end
else
text = string.format("Found %d matches for %q",
#self.results, self.query)
+21 -8
View File
@@ -93,6 +93,13 @@ function TreeView:get_item_height()
end
function TreeView:invalidate_cache(dirname)
for _, v in pairs(self.cache[dirname]) do
v.skip = nil
end
end
function TreeView:check_cache()
-- invalidate cache's skip values if project_files has changed
for i = 1, #core.project_directories do
@@ -102,9 +109,7 @@ function TreeView:check_cache()
self.last[dir.name] = dir.files
else
if dir.files ~= last_files then
for _, v in pairs(self.cache[dir.name]) do
v.skip = nil
end
self:invalidate_cache(dir.name)
self.last[dir.name] = dir.files
end
end
@@ -208,17 +213,25 @@ function TreeView:on_mouse_pressed(button, x, y, clicks)
if caught then
return
end
if not self.hovered_item then
local hovered_item = self.hovered_item
if not hovered_item then
return
elseif self.hovered_item.type == "dir" then
elseif hovered_item.type == "dir" then
if keymap.modkeys["ctrl"] and button == "left" then
create_directory_in(self.hovered_item)
create_directory_in(hovered_item)
else
self.hovered_item.expanded = not self.hovered_item.expanded
if core.project_files_limit and not hovered_item.expanded then
local filename, abs_filename = hovered_item.filename, hovered_item.abs_filename
local index = string.find(abs_filename, filename, 1, true)
local dirname = string.sub(abs_filename, 1, index - 2)
core.scan_project_folder(dirname, filename)
self:invalidate_cache(dirname)
end
hovered_item.expanded = not hovered_item.expanded
end
else
core.try(function()
local doc_filename = common.relative_path(core.project_dir, self.hovered_item.abs_filename)
local doc_filename = common.relative_path(core.project_dir, hovered_item.abs_filename)
core.root_view:open_doc(core.open_doc(doc_filename))
end)
end