Skip to content

Commit 52a2193

Browse files
Improves type annotations (#465)
* Improves type annotations of `Logbook` * Improves `Section` type annotations * Removes local variables that were not necessary * Adds type for `node` in Logbook
1 parent aba09c5 commit 52a2193

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

lua/orgmode/parser/logbook.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ function Logbook:get_total_minutes(from, to)
5454
return total_minutes
5555
end
5656

57-
---@param from string
58-
---@param to string
57+
---@param from? string
58+
---@param to? string
5959
---@return Duration
6060
function Logbook:get_total(from, to)
6161
return Duration.from_minutes(self:get_total_minutes(from, to))
@@ -134,7 +134,8 @@ function Logbook:recalculate_estimate(line)
134134
end
135135

136136
---@param lines string
137-
---@param dates string
137+
---@param node userdata
138+
---@param dates Date[]
138139
---@return Logbook
139140
function Logbook.parse(lines, node, dates)
140141
local opts = {
@@ -173,6 +174,10 @@ function Logbook.new_from_section(section)
173174
})
174175
end
175176

177+
---@param lines any
178+
---@param node any
179+
---@param dates Date[]
180+
---@return table
176181
function Logbook._parse_clocks(lines, node, dates)
177182
local items = {}
178183
local range = Range.from_node(node)

lua/orgmode/parser/section.lua

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local Logbook = require('orgmode.parser.logbook')
1111
local config = require('orgmode.config')
1212

1313
---@class Section
14-
---@field id number
14+
---@field id string
1515
---@field line_number number
1616
---@field level number
1717
---@field node table
@@ -20,7 +20,7 @@ local config = require('orgmode.config')
2020
---@field line string
2121
---@field range Range
2222
---@field sections Section[]
23-
---@field todo_keyword table<string, string>
23+
---@field todo_keyword SectionTodoKeyword
2424
---@field priority string
2525
---@field title string
2626
---@field category string
@@ -34,8 +34,35 @@ local config = require('orgmode.config')
3434
---@field clocked_in boolean
3535
local Section = {}
3636

37+
---@class SectionTodoKeyword
38+
---@field node unknown
39+
---@field type 'TODO'|'DONE'|''
40+
---@field value string
41+
42+
---@class NewSectionOptions
43+
---@field content string[]
44+
---@field dates Date[]
45+
---@field level number
46+
---@field line string
47+
---@field logbook Logbook
48+
---@field node table
49+
---@field own_tags string[]
50+
---@field parent Section
51+
---@field priority string
52+
---@field properties table
53+
---@field range Range
54+
---@field root File
55+
---@field tags string[]
56+
---@field title string
57+
---@field todo_keyword_node unknown
58+
59+
---Constructs a new Section
60+
---@param data NewSectionOptions
61+
---@return Section
3762
function Section:new(data)
3863
data = data or {}
64+
65+
---@type Section
3966
local section = {}
4067
section.id = string.format('%s####%s', data.root.filename or '', data.range.start_line)
4168
section.line_number = data.range.start_line
@@ -337,7 +364,7 @@ function Section:is_last_section()
337364
return self.parent.sections[#self.parent.sections].id == self.id
338365
end
339366

340-
---@return Section
367+
---@return Section?
341368
function Section:get_prev_headline_same_level()
342369
if self:is_first_section() then
343370
return nil
@@ -353,7 +380,7 @@ function Section:get_prev_headline_same_level()
353380
return nil
354381
end
355382

356-
---@return Section
383+
---@return Section?
357384
function Section:get_next_headline_same_level()
358385
if self:is_last_section() then
359386
return nil

0 commit comments

Comments
 (0)