Skip to content

Commit

Permalink
fix(typecheck): use type definitions from nvim runtime instead (#1358)
Browse files Browse the repository at this point in the history
* fix(typecheck): use type definitions from nvim runtime instead

* fix(typecheck): add neodev for stable API

* fix(typecheck): workaround couple of edge cases
  • Loading branch information
pysan3 authored Mar 28, 2024
1 parent c1d36ad commit e7f393f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/.luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"lua/?/init.lua"
],
"Lua.workspace.library": [
"/home/runner/work/neorg/neorg/deps/neovim/runtime/lua",
"/home/runner/work/neorg/neorg/deps/neodev.nvim/types/stable"
],
"Lua.diagnostics.libraryFiles": "Disable",
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ jobs:
repository: "folke/neodev.nvim"
path: "deps/neodev.nvim"

- name: Checkout neovim for type annotations
uses: actions/checkout@v3
with:
repository: "neovim/neovim"
path: "deps/neovim"

- name: Type Check Code Base
uses: mrcjkb/[email protected]
with:
Expand Down
5 changes: 4 additions & 1 deletion lua/neorg/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ function utils.get_language_shorthands(reverse_lookup)
["yaml"] = { "yml" },
}

return reverse_lookup and vim.tbl_add_reverse_lookup(langs) or langs
-- TODO: `vim.tbl_add_reverse_lookup` deprecated: NO ALTERNATIVES
-- GOOD JOB CORE DEVS
-- <https://github.com/neovim/neovim/pull/27639>
return reverse_lookup and vim.tbl_add_reverse_lookup(langs) or langs ---@diagnostic disable-line
end

--- Checks whether Neovim is running at least at a specific version.
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/integrations/treesitter/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ module.public = {
-- Do we need to go through each tree? lol
vim.treesitter.get_parser(opts.buf, opts.ft):for_each_tree(function(tree)
-- Get the root for that tree
---@type TSNode
local root = tree:root()

--- Recursively searches for a node of a given type
Expand Down
27 changes: 10 additions & 17 deletions lua/neorg/modules/core/tempus/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,16 @@ module.public = {
---@param parsed_date Date #The date to convert
---@return osdate #A Lua date
to_lua_date = function(parsed_date)
return os.date( ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
"*t",
os.time(
vim.tbl_deep_extend(
"force",
os.date("*t"),
{ ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
day = parsed_date.day,
month = parsed_date.month and parsed_date.month.number or nil,
year = parsed_date.year,
hour = parsed_date.time and parsed_date.time.hour,
min = parsed_date.time and parsed_date.time.minute,
sec = parsed_date.time and parsed_date.time.second,
}
)
)
)
local now = os.date("*t") --[[@as osdate]]
local parsed = os.time(vim.tbl_deep_extend("force", now, {
day = parsed_date.day,
month = parsed_date.month and parsed_date.month.number or nil,
year = parsed_date.year,
hour = parsed_date.time and parsed_date.time.hour,
min = parsed_date.time and parsed_date.time.minute,
sec = parsed_date.time and parsed_date.time.second,
}) --[[@as osdateparam]])
return os.date("*t", parsed) --[[@as osdate]]
end,

--- Converts a lua `osdate` to a Neorg date.
Expand Down

0 comments on commit e7f393f

Please sign in to comment.