Skip to content

Commit 59b1329

Browse files
refactor: Track all loaded files for easier reloading
1 parent 8008c58 commit 59b1329

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lua/orgmode/files/file.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ local ts_utils = require('orgmode.utils.treesitter')
44
local Headline = require('orgmode.files.headline')
55
local ts = vim.treesitter
66
local config = require('orgmode.config')
7-
local Duration = require('orgmode.objects.duration')
87

98
---@class OrgFileMetadata
109
---@field mtime number

lua/orgmode/files/init.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ local Listitem = require('orgmode.files.elements.listitem')
1010

1111
---@class OrgFiles
1212
---@field paths string[]
13-
---@field files table<string, OrgFile>
13+
---@field files table<string, OrgFile> table with files that are part of paths
14+
---@field all_files table<string, OrgFile> all loaded files, no matter if they are part of paths
1415
---@field load_state 'loading' | 'loaded' | nil
1516
local OrgFiles = {}
1617

@@ -19,6 +20,7 @@ function OrgFiles:new(opts)
1920
local data = {
2021
paths = opts.paths or {},
2122
files = {},
23+
all_files = {},
2224
load_state = nil,
2325
}
2426
setmetatable(data, self)
@@ -79,6 +81,7 @@ end
7981

8082
function OrgFiles:unload()
8183
self.files = {}
84+
self.all_files = {}
8285
self.paths = {}
8386
self.load_state = nil
8487
return self
@@ -125,12 +128,19 @@ end
125128

126129
---@return OrgPromise<OrgFile>
127130
function OrgFiles:load_file(filename)
128-
local file = self.files[filename]
131+
local file = self.all_files[filename]
129132
if file then
130133
return file:reload()
131134
end
132135

133-
return OrgFile.load(filename)
136+
local promise = OrgFile.load(filename):next(function(orgfile)
137+
if orgfile then
138+
self.all_files[filename] = orgfile
139+
end
140+
return orgfile
141+
end)
142+
143+
return promise
134144
end
135145

136146
---@return OrgFile | nil
@@ -145,7 +155,6 @@ function OrgFiles:get(filename)
145155
end
146156

147157
function OrgFiles:reload(filename)
148-
local prev_file = self.files[filename]
149158
self:load_file(filename):next(function(orgfile)
150159
return orgfile
151160
end)

0 commit comments

Comments
 (0)