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

Rearrange Plugin Loading and SDL Initialization #1881

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d5940b6
Initial commit to clean up projects; spun off find-file to its own pl…
adamharrison Apr 1, 2023
2f4aff1
Bump modversion.
adamharrison Jun 22, 2024
a716131
Bumped modversion and changed a few minor things.
adamharrison Jun 22, 2024
f2fd9ba
Added in handling of ignored files.
adamharrison Jun 22, 2024
0350614
Fixed small issue.
adamharrison Jun 27, 2024
3cc4543
Fixed issue with absolute arguments.
adamharrison Jul 5, 2024
9e2ec1b
Removed home encoding; may revert this if I can find out why it was d…
adamharrison Jul 7, 2024
9c05676
Fixed minor issue with file suggestions.
adamharrison Aug 22, 2024
0303199
Cleaned up treeview.
adamharrison Aug 22, 2024
41f8206
Typo.
adamharrison Aug 22, 2024
59650ec
Added in visible.
adamharrison Aug 23, 2024
056a2cb
Ensured that the appropriate project module is loaded.
adamharrison Sep 10, 2024
975e416
Fixed improper rebase.
adamharrison Sep 10, 2024
17a3503
Abstracted out the storage system of the workspace plugin so other pl…
adamharrison Mar 6, 2024
3de9036
Fixed double return.
adamharrison Mar 6, 2024
a8fce83
Fixed functional issue.
adamharrison Mar 6, 2024
11af515
Added documentation.
adamharrison Apr 3, 2024
b84738f
Sumenko reports duplicate function definitions, unsure why.
adamharrison Apr 3, 2024
d5dbfad
Fixed minor bug with workspace.
adamharrison Sep 28, 2024
7be990f
Fixed switching projects on restart.
adamharrison Oct 9, 2024
f2a66b4
Merge branch 'master' into PR/project-rework
adamharrison Oct 22, 2024
00d708c
Harmonized spacing around asserts, and fixed an issue forgetting to s…
adamharrison Nov 3, 2024
86388a6
Made project an object.
adamharrison Nov 3, 2024
62bc82e
Removing unecessary yields.
adamharrison Nov 3, 2024
28b7029
Removed unecessary fallback.
adamharrison Nov 3, 2024
fed7967
Removed unecessary line.
adamharrison Nov 3, 2024
64b5f57
Reveted backslash handling, as it doesn't seem to make any difference.
adamharrison Nov 3, 2024
8e0ae38
Spacing.
adamharrison Nov 3, 2024
320695c
Only stonks.
adamharrison Nov 3, 2024
19046d0
Removed uneeded error handling.
adamharrison Nov 3, 2024
fef8f81
Added in function to determine project by path, and added in deprecat…
adamharrison Nov 3, 2024
dcb0ee6
Merge branch 'master' into PR/project-rework
adamharrison Nov 3, 2024
0bb8d7e
Removed storage module.
adamharrison Nov 3, 2024
283b0ae
Typo.
adamharrison Nov 3, 2024
0a3b440
Changed to use deprecation log instead of regular warn so as to not s…
adamharrison Nov 27, 2024
10f2ab9
Fixed small bug with saving workspaces on project change.
adamharrison Nov 27, 2024
b20a85c
Revert "Removed storage module."
adamharrison Nov 3, 2024
84d62d2
Initial commit.
adamharrison Sep 15, 2024
2b2a009
Moved around plugin initialization.
adamharrison Sep 16, 2024
9491db9
Fixing restarting when changing projects.
adamharrison Sep 16, 2024
e1f5d69
Added in autorestart plugin.
adamharrison Sep 16, 2024
dbb75bf
Moved screensaver call to after video subsystem init.
adamharrison Sep 16, 2024
cc1d209
Fixed minor issue.
adamharrison Sep 16, 2024
154d1d1
Missing extension.
adamharrison Sep 16, 2024
0f7c3dc
Kept initailization of previous_find and previous_replace.
adamharrison Sep 16, 2024
d7b15e8
Allowed priority regex to take a decimal place.
adamharrison Sep 16, 2024
a2ac9f6
Fixed priority regex.
adamharrison Sep 16, 2024
18382f6
Fixed version mismatch error.
adamharrison Sep 19, 2024
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
Next Next commit
Initial commit to clean up projects; spun off find-file to its own pl…
…ugin, removed project limit, removed the concept of a project maintaining an ordered list of files, and allowed treeview to see things like hidden files and files not actually in the project.

Normalizing things, fixed typo.

Abstracted root project, and made things more in line with current master behaviour.

Removed unused legacy code, as well as ensured that we use absolute paths.

Fixed issue with backslahes on linux, will look at windows at some point.

Removed stray print.

Removed orphaned function.

Removed extraneous command.

Fixed the ability to close project folders.

Removed superceded function.

Applied jgm's suggestions.
  • Loading branch information
adamharrison committed Sep 13, 2024
commit d5940b6efd7b91382b268019aec91ce6608a708e
36 changes: 0 additions & 36 deletions data/core/bit.lua

This file was deleted.

46 changes: 12 additions & 34 deletions data/core/commands/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ local restore_title_view = false

local function suggest_directory(text)
text = common.home_expand(text)
local basedir = common.dirname(core.project_dir)
local basedir = common.dirname(core.root_project().path)
return common.home_encode_list((basedir and text == basedir .. PATHSEP or text == "") and
core.recent_projects or common.dir_path_suggest(text))
core.recent_projects or common.dir_path_suggest(text, core.root_project().path))
end

local function check_directory_path(path)
Expand Down Expand Up @@ -86,28 +86,6 @@ command.add(nil, {
})
end,

["core:find-file"] = function()
if not core.project_files_number() then
return command.perform "core:open-file"
end
local files = {}
for dir, item in core.get_project_files() do
if item.type == "file" then
local path = (dir == core.project_dir and "" or dir .. PATHSEP)
table.insert(files, common.home_encode(path .. item.filename))
end
end
core.command_view:enter("Open File From Project", {
submit = function(text, item)
text = item and item.text or text
core.root_view:open_doc(core.open_doc(common.home_expand(text)))
end,
suggest = function(text)
return common.fuzzy_match_with_recents(files, core.visited_files, text)
end
})
end,

["core:new-doc"] = function()
core.root_view:open_doc(core.open_doc())
end,
Expand All @@ -127,7 +105,7 @@ command.add(nil, {
local dirname, filename = view.doc.abs_filename:match("(.*)[/\\](.+)$")
if dirname then
dirname = core.normalize_to_project_dir(dirname)
text = dirname == core.project_dir and "" or common.home_encode(dirname) .. PATHSEP
text = dirname == core.root_project().path and "" or common.home_encode(dirname) .. PATHSEP
end
end
core.command_view:enter("Open File", {
Expand Down Expand Up @@ -182,7 +160,7 @@ command.add(nil, {
end,

["core:change-project-folder"] = function()
local dirname = common.dirname(core.project_dir)
local dirname = common.dirname(core.root_project().path)
local text
if dirname then
text = common.home_encode(dirname) .. PATHSEP
Expand All @@ -196,17 +174,17 @@ command.add(nil, {
core.error("Cannot open directory %q", path)
return
end
if abs_path == core.project_dir then return end
if abs_path == core.root_project().path then return end
core.confirm_close_docs(core.docs, function(dirpath)
core.open_folder_project(dirpath)
core.open_project(dirpath)
end, abs_path)
end,
suggest = suggest_directory
})
end,

["core:open-project-folder"] = function()
local dirname = common.dirname(core.project_dir)
local dirname = common.dirname(core.root_project().path)
local text
if dirname then
text = common.home_encode(dirname) .. PATHSEP
Expand All @@ -220,7 +198,7 @@ command.add(nil, {
core.error("Cannot open directory %q", path)
return
end
if abs_path == core.project_dir then
if abs_path == core.root_project().path then
core.error("Directory %q is currently opened", abs_path)
return
end
Expand All @@ -242,22 +220,22 @@ command.add(nil, {
core.error("%q is not a directory", text)
return
end
core.add_project_directory(system.absolute_path(text))
core.add_project(system.absolute_path(text))
end,
suggest = suggest_directory
})
end,

["core:remove-directory"] = function()
local dir_list = {}
local n = #core.project_directories
local n = #core.projects
for i = n, 2, -1 do
dir_list[n - i + 1] = core.project_directories[i].name
dir_list[n - i + 1] = core.projects[i].name
end
core.command_view:enter("Remove Directory", {
submit = function(text, item)
text = common.home_expand(item and item.text or text)
if not core.remove_project_directory(text) then
if not core.remove_project(text) then
core.error("No directory %q to be removed", text)
end
end,
Expand Down
1 change: 1 addition & 0 deletions data/core/commands/doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ local commands = {
elseif last_doc and last_doc.filename then
local dirname, filename = core.last_active_view.doc.abs_filename:match("(.*)[/\\](.+)$")
text = core.normalize_to_project_dir(dirname) .. PATHSEP
if text == core.root_project().path then text = "" end
end
core.command_view:enter("Save As", {
text = text,
Expand Down
6 changes: 4 additions & 2 deletions data/core/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ function common.path_suggest(text, root)
local s, e = file:find(root, nil, true)
if s == 1 then
file = file:sub(e + 1)
table.insert(res, file)
end
elseif clean_dotslash then
-- remove added dot slash
Expand All @@ -277,10 +278,11 @@ end

---Returns a list of directories that are related to a path.
---@param text string The input path.
---@param root string The root directory.
---@return string[]
function common.dir_path_suggest(text)
function common.dir_path_suggest(text, root)
local path, name = text:match("^(.-)([^"..PATHSEP.."]*)$")
local files = system.list_dir(path == "" and "." or path) or {}
local files = system.list_dir(path == "" and (root or ".") or path) or {}
local res = {}
for _, file in ipairs(files) do
file = path .. file
Expand Down
9 changes: 0 additions & 9 deletions data/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,6 @@ config.line_endings = PLATFORM == "Windows" and "crlf" or "lf"
---@type number
config.line_limit = 80

---Maximum number of project files to keep track of.
---If the number of files in the project exceeds this number,
---Lite XL will not be able to keep track of them.
---They will be not be searched when searching for files or text.
---
---Defaults to 2000.
---@type number
config.max_project_files = 2000

---Enables/disables all transitions.
---
---Defaults to true.
Expand Down
118 changes: 7 additions & 111 deletions data/core/dirwatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ function dirwatch:check(change_callback, scan_time, wait_time)
end
change_callback(path)
elseif self.reverse_watched[id] then
change_callback(self.reverse_watched[id])
local path = self.reverse_watched[id]
change_callback(path)
local info = system.get_file_info(path)
if info and info.type == "file" then
self:unwatch(path)
self:watch(path)
end
end
end, function(err)
last_error = err
Expand All @@ -126,114 +132,4 @@ function dirwatch:check(change_callback, scan_time, wait_time)
return had_change
end


-- inspect config.ignore_files patterns and prepare ready to use entries.
local function compile_ignore_files()
local ipatterns = config.ignore_files
local compiled = {}
-- config.ignore_files could be a simple string...
if type(ipatterns) ~= "table" then ipatterns = {ipatterns} end
for i, pattern in ipairs(ipatterns) do
-- we ignore malformed patterns that raise an error
if pcall(string.match, "a", pattern) then
table.insert(compiled, {
use_path = pattern:match("/[^/$]"), -- contains a slash but not at the end
-- A '/' or '/$' at the end means we want to match a directory.
match_dir = pattern:match(".+/%$?$"), -- to be used as a boolen value
pattern = pattern -- get the actual pattern
})
end
end
return compiled
end


local function fileinfo_pass_filter(info, ignore_compiled)
if info.size >= config.file_size_limit * 1e6 then return false end
local basename = common.basename(info.filename)
-- replace '\' with '/' for Windows where PATHSEP = '\'
local fullname = "/" .. info.filename:gsub("\\", "/")
for _, compiled in ipairs(ignore_compiled) do
local test = compiled.use_path and fullname or basename
if compiled.match_dir then
if info.type == "dir" and string.match(test .. "/", compiled.pattern) then
return false
end
else
if string.match(test, compiled.pattern) then
return false
end
end
end
return true
end


local function compare_file(a, b)
return system.path_compare(a.filename, a.type, b.filename, b.type)
end


-- compute a file's info entry completed with "filename" to be used
-- in project scan and return it or falsy if it shouldn't appear in the list.
local function get_project_file_info(root, file, ignore_compiled)
local info = system.get_file_info(root .. PATHSEP .. file)
-- In some cases info.type is nil even if info is valid.
-- This happens when it is neither a file nor a directory,
-- for example /dev/* entries on linux.
if info and info.type then
info.filename = file
return fileinfo_pass_filter(info, ignore_compiled) and info
end
end


-- "root" will by an absolute path without trailing '/'
-- "path" will be a path starting without '/' and without trailing '/'
-- or the empty string.
-- It identifies a sub-path within "root".
-- The current path location will therefore always be: root .. '/' .. path.
-- When recursing, "root" will always be the same, only "path" will change.
-- Returns a list of file "items". In each item the "filename" will be the
-- complete file path relative to "root" *without* the trailing '/', and without the starting '/'.
function dirwatch.get_directory_files(dir, root, path, entries_count, recurse_pred)
local t = {}
local t0 = system.get_time()
local ignore_compiled = compile_ignore_files()

local all = system.list_dir(root .. PATHSEP .. path)
if not all then return nil end
local entries = { }
for _, file in ipairs(all) do
local info = get_project_file_info(root, (path ~= "" and (path .. PATHSEP) or "") .. file, ignore_compiled)
if info then
table.insert(entries, info)
end
end
table.sort(entries, compare_file)

local recurse_complete = true
for _, info in ipairs(entries) do
table.insert(t, info)
entries_count = entries_count + 1
if info.type == "dir" then
if recurse_pred(dir, info.filename, entries_count, system.get_time() - t0) then
local t_rec, complete, n = dirwatch.get_directory_files(dir, root, info.filename, entries_count, recurse_pred)
recurse_complete = recurse_complete and complete
if n ~= nil then
entries_count = n
for _, info_rec in ipairs(t_rec) do
table.insert(t, info_rec)
end
end
else
recurse_complete = false
end
end
end

return t, recurse_complete, entries_count
end


return dirwatch
6 changes: 3 additions & 3 deletions data/core/doc/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Doc:new(filename, abs_filename, new_file)
if filename then
self:set_filename(filename, abs_filename)
if not new_file then
self:load(filename)
self:load(abs_filename)
end
end
if new_file then
Expand Down Expand Up @@ -89,7 +89,7 @@ end
function Doc:reload()
if self.filename then
local sel = { self:get_selection() }
self:load(self.filename)
self:load(self.abs_filename)
self:clean()
self:set_selection(table.unpack(sel))
end
Expand All @@ -103,7 +103,7 @@ function Doc:save(filename, abs_filename)
else
assert(self.filename or abs_filename, "calling save on unnamed doc without absolute path")
end
local fp = assert(io.open(filename, "wb"))
local fp = assert( io.open(abs_filename, "wb") )
for _, line in ipairs(self.lines) do
if self.crlf then line = line:gsub("\n", "\r\n") end
fp:write(line)
Expand Down
Loading