From e7f393f9e4a17c32289875e273f687863336894c Mon Sep 17 00:00:00 2001 From: takuto Date: Fri, 29 Mar 2024 02:30:58 +0900 Subject: [PATCH] fix(typecheck): use type definitions from nvim runtime instead (#1358) * fix(typecheck): use type definitions from nvim runtime instead * fix(typecheck): add neodev for stable API * fix(typecheck): workaround couple of edge cases --- .github/workflows/.luarc.json | 1 + .github/workflows/typecheck.yml | 6 +++++ lua/neorg/core/utils.lua | 5 +++- .../core/integrations/treesitter/module.lua | 1 + lua/neorg/modules/core/tempus/module.lua | 27 +++++++------------ 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.github/workflows/.luarc.json b/.github/workflows/.luarc.json index e83431278..199a752b0 100644 --- a/.github/workflows/.luarc.json +++ b/.github/workflows/.luarc.json @@ -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", diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml index 22e18d5b6..1ea820e19 100644 --- a/.github/workflows/typecheck.yml +++ b/.github/workflows/typecheck.yml @@ -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/lua-typecheck-action@v0.2.1 with: diff --git a/lua/neorg/core/utils.lua b/lua/neorg/core/utils.lua index fbd66096e..9589d0c37 100644 --- a/lua/neorg/core/utils.lua +++ b/lua/neorg/core/utils.lua @@ -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 + -- + 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. diff --git a/lua/neorg/modules/core/integrations/treesitter/module.lua b/lua/neorg/modules/core/integrations/treesitter/module.lua index 8afad40dd..f15c1f943 100644 --- a/lua/neorg/modules/core/integrations/treesitter/module.lua +++ b/lua/neorg/modules/core/integrations/treesitter/module.lua @@ -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 diff --git a/lua/neorg/modules/core/tempus/module.lua b/lua/neorg/modules/core/tempus/module.lua index 4e84671f8..46ae0b8ff 100644 --- a/lua/neorg/modules/core/tempus/module.lua +++ b/lua/neorg/modules/core/tempus/module.lua @@ -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 - "*t", - os.time( - vim.tbl_deep_extend( - "force", - os.date("*t"), - { ---@diagnostic disable-line -- TODO: type error workaround - 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.