Skip to content

Commit 4007436

Browse files
chore: Fix types
1 parent 10ded34 commit 4007436

File tree

20 files changed

+72
-70
lines changed

20 files changed

+72
-70
lines changed

lua/orgmode/agenda/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local AgendaTodosView = require('orgmode.agenda.views.todos')
1010
local AgendaTagsView = require('orgmode.agenda.views.tags')
1111
local AgendaView = require('orgmode.agenda.views.agenda')
1212
local Menu = require('orgmode.ui.menu')
13+
local Promise = require('orgmode.utils.promise')
1314

1415
---@class Agenda
1516
---@field content table[]
@@ -406,7 +407,7 @@ function Agenda:_remote_edit(opts)
406407
end
407408
local update = Files.update_file(item.file, function(_)
408409
vim.fn.cursor({ item.file_position, 0 })
409-
return utils.promisify(require('orgmode').action(action)):next(function()
410+
return Promise.resolve(require('orgmode').action(action)):next(function()
410411
return Files.get_closest_headline()
411412
end)
412413
end)

lua/orgmode/api/headline.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local OrgPosition = require('orgmode.api.position')
55
local PriorityState = require('orgmode.objects.priority_state')
66
local Date = require('orgmode.objects.date')
77
local Calendar = require('orgmode.objects.calendar')
8+
local Promise = require('orgmode.utils.promise')
89

910
---@class OrgHeadline
1011
---@field title string headline title without todo keyword, tags and priority. Ex. `* TODO I am a headline :SOMETAG:` returns `I am a headline`
@@ -218,7 +219,7 @@ function OrgHeadline:_do_action(action)
218219
return Files.update_file(self.file.filename, function()
219220
local view = vim.fn.winsaveview()
220221
vim.fn.cursor({ self.position.start_line, 0 })
221-
return utils.promisify(action()):next(function()
222+
return Promise.resolve(action()):next(function()
222223
vim.fn.winrestview(view)
223224
return self:reload()
224225
end)

lua/orgmode/capture/templates.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ local Templates = {}
4040
-- TODO Introduce type
4141
function Templates:new()
4242
local opts = {}
43-
opts.templates = config.org_agenda_templates or config.org_capture_templates
43+
opts.templates = config.org_capture_templates
4444
setmetatable(opts, self)
4545
self.__index = self
4646
return opts
@@ -132,6 +132,7 @@ function Templates:_compile_expressions(content)
132132
for exp in content:gmatch('%%%b()') do
133133
local snippet = exp:match('%((.*)%)')
134134
local func = load(snippet)
135+
---@diagnostic disable-next-line: param-type-mismatch
135136
local ok, response = pcall(func)
136137
if ok then
137138
content = content:gsub(vim.pesc(exp), response)

lua/orgmode/clock/init.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ end
1717
function Clock:org_clock_in()
1818
local item = Files.get_closest_headline()
1919
local last_clocked_headline = Files.get_clocked_headline()
20+
if not item then
21+
return
22+
end
2023
if item:is_clocked_in() then
2124
return utils.echo_info(string.format('Clock continues in "%s"', item.title))
2225
end
@@ -41,6 +44,9 @@ end
4144

4245
function Clock:org_clock_out()
4346
local item = Files.get_closest_headline()
47+
if not item then
48+
return
49+
end
4450
if not item:is_clocked_in() then
4551
return
4652
end
@@ -51,6 +57,9 @@ end
5157

5258
function Clock:org_clock_cancel()
5359
local item = Files.get_closest_headline()
60+
if not item then
61+
return
62+
end
5463
if not item:is_clocked_in() then
5564
return utils.echo_info('No active clock')
5665
end

lua/orgmode/clock/report.lua

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function ClockReport:draw_for_agenda(start_line)
4545
table.insert(data, 'hr')
4646
end
4747

48-
local clock_table = Table.from_list(data, start_line):compile()
48+
local clock_table = Table.from_list(data, start_line, 0):compile()
4949
self.table = clock_table
5050
local result = {}
5151
for i, row in ipairs(clock_table.rows) do
@@ -111,25 +111,25 @@ end
111111
---@param to Date
112112
---@return ClockReport
113113
function ClockReport.from_date_range(from, to)
114-
local report = {
115-
from = from,
116-
to = to,
117-
total_duration = 0,
118-
files = {},
119-
}
114+
local total_duration = 0
115+
local files = {}
120116
for _, orgfile in ipairs(Files.all()) do
121117
local file_clocks = orgfile:get_clock_report(from, to)
122118
if #file_clocks.headlines > 0 then
123-
report.total_duration = report.total_duration + file_clocks.total_duration.minutes
124-
table.insert(report.files, {
119+
total_duration = total_duration + file_clocks.total_duration.minutes
120+
table.insert(files, {
125121
name = orgfile.category .. '.org',
126122
total_duration = file_clocks.total_duration,
127123
headlines = file_clocks.headlines,
128124
})
129125
end
130126
end
131-
report.total_duration = Duration.from_minutes(report.total_duration)
132-
return ClockReport:new(report)
127+
return ClockReport:new({
128+
from = from,
129+
to = to,
130+
total_duration = Duration.from_minutes(total_duration),
131+
files = files,
132+
})
133133
end
134134

135135
return ClockReport

lua/orgmode/colors/highlights.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ end
101101
function M.define_org_headline_colors(faces)
102102
local headline_colors = { 'Title', 'Constant', 'Identifier', 'Statement', 'PreProc', 'Type', 'Special', 'String' }
103103
local ts_highlights_enabled = config:ts_highlights_enabled()
104-
local all_keywords = {}
104+
local all_keywords = ''
105105
if not ts_highlights_enabled then
106106
local todo_keywords = config:get_todo_keywords()
107107
all_keywords = table.concat(todo_keywords.ALL, [[\|]])
@@ -117,7 +117,6 @@ function M.define_org_headline_colors(faces)
117117
vim.cmd([[hi default OrgHideLeadingStars ctermfg=0 guifg=bg]])
118118
table.insert(contains, 'OrgHideLeadingStars')
119119
end
120-
contains = table.concat(contains, ',')
121120
for i, color in ipairs(headline_colors) do
122121
local j = i
123122
while j < 40 do
@@ -128,7 +127,7 @@ function M.define_org_headline_colors(faces)
128127
j,
129128
j,
130129
all_keywords,
131-
contains
130+
table.concat(contains, ',')
132131
)
133132
)
134133
end

lua/orgmode/config/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ function Config:setup_mappings(category, buffer)
292292
end
293293
end
294294

295+
---@return string|nil
295296
function Config:parse_archive_location(file, archive_loc)
296297
if self:is_archive_file(file) then
297298
return nil

lua/orgmode/init.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ function Org:init()
4040
end
4141

4242
---@param file? string
43-
---@return string
4443
function Org:reload(file)
4544
self:init()
4645
return self.files.reload(file)
@@ -122,7 +121,7 @@ local function setup(opts)
122121
end
123122

124123
---@param file? string
125-
---@return Org
124+
---@return Org|nil
126125
local function reload(file)
127126
if not instance then
128127
return
@@ -146,7 +145,7 @@ local function set_dot_repeat(cmd, opts)
146145
end
147146

148147
---@param cmd string
149-
---@param opts? table
148+
---@param opts? any
150149
local function action(cmd, opts)
151150
local parts = vim.split(cmd, '.', true)
152151
if not instance or #parts < 2 then

lua/orgmode/objects/calendar.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,9 @@ function Calendar.render()
137137
local content = vim.tbl_map(function(item)
138138
return ' ' .. table.concat(item, ' ') .. ' '
139139
end, cal_rows)
140-
weekday_row = ' ' .. table.concat(weekday_row, ' ')
141140

142141
-- put it all together
143-
table.insert(content, 1, weekday_row)
142+
table.insert(content, 1, ' ' .. table.concat(weekday_row, ' '))
144143
table.insert(content, 1, title)
145144
-- TODO: redundant, since it's static data
146145
table.insert(content, ' [<] - prev month [>] - next month')

lua/orgmode/objects/help.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ function Help.prepare_content(opts)
275275

276276
local prepare_func = Help['_prepare_' .. t]
277277
if not prepare_func then
278-
return
278+
return {}
279279
end
280280

281281
local content, include_generic = prepare_func(mappings, max_height)

0 commit comments

Comments
 (0)