Skip to content

Commit 9aad189

Browse files
authored
Merge pull request #208 from neo451/proper-type-check
feat: proper type check in Makefile
2 parents 92fa8e9 + 86409e5 commit 9aad189

File tree

19 files changed

+134
-34
lines changed

19 files changed

+134
-34
lines changed

.github/workflows/typecheck.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# name: Run type check
2+
#
3+
# on:
4+
# push:
5+
# branches-ignore: [sync, stable]
6+
# paths: ["colors/**", "lua/**", "tests/**"]
7+
# pull_request:
8+
# branches-ignore: [sync, stable]
9+
# paths: ["colors/**", "lua/**", "tests/**"]
10+
#
11+
# concurrency:
12+
# group: ${{ github.workflow }}-${{ github.ref }}-${{ github.actor }}
13+
# cancel-in-progress: true
14+
#
15+
# jobs:
16+
# build:
17+
# name: Run tests
18+
# timeout-minutes: 15
19+
# runs-on: ubuntu-latest
20+
#
21+
# steps:
22+
# - uses: actions/checkout@v4
23+
#
24+
# - name: Setup neovim
25+
# shell: bash
26+
# run: |
27+
# mkdir -p _neovim
28+
# curl -sL https://github.com/neovim/neovim/releases/download/nightly/nvim-linux-x86_64.tar.gz | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
29+
# export PATH="${PWD}/_neovim/bin:${PATH}"
30+
# export VIMRUNTIME="${PWD}/_neovim/share/nvim/runtime"
31+
#
32+
# nvim --version
33+
#
34+
# - name: Install lua-language-server
35+
# uses: jdx/mise-action@v2
36+
# with:
37+
# tool_versions: |
38+
# lua-language-server 3.15.0
39+
#
40+
# - name: Run tests
41+
# run:
42+
# make types

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
deps/
2+
data/
3+
stuff/

.luarc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"runtime.version": "LuaJIT", // the version for neovim
3+
"diagnostics.libraryFiles": "Disable",
4+
"workspace.checkThirdParty": "Disable",
5+
"workspace.ignoreDir": ["lib/"],
6+
"workspace.library": ["$VIMRUNTIME/lua/", "./lua/"],
7+
"diagnostics.globals": ["vim", "MiniTest"]
8+
}

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
LUARC = $(shell readlink -f .luarc.json)
2+
13
# Run all test files
2-
test: deps/mini.nvim
4+
test: deps/mini.nvim deps/nvim-treesitter
5+
nvim --headless --noplugin -u ./scripts/install_grammar.lua
36
nvim --headless --noplugin -u ./scripts/minimal_init.lua -c "lua MiniTest.run()"
47

58
# Run test from file at `$FILE` environment variable
@@ -12,5 +15,12 @@ deps/mini.nvim:
1215
@mkdir -p deps
1316
git clone --filter=blob:none https://github.com/echasnovski/mini.nvim $@
1417

18+
# Download 'mini.nvim' to use its 'mini.test' testing module
19+
deps/nvim-treesitter:
20+
git clone --filter=blob:none https://github.com/nvim-treesitter/nvim-treesitter.git --branch main $@
21+
1522
gen_doc:
1623
./panvimdoc.sh --project-name feed --input-file doc.md --vim-version 0.11 --shift-heading-level-by -1 --toc true
24+
25+
types: ## Type check with lua-ls
26+
lua-language-server --configpath "$(LUARC)" --check lua/feed/

lua/feed/commands.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ M.update = {
169169
local args = vim.v.argv
170170
table.remove(args, 1)
171171
table.remove(args, 1)
172-
local cmds = vim.tbl_flatten({
172+
local cmds = ut.tbl_flatten({
173173
"nvim",
174174
args,
175175
"--headless",
@@ -251,9 +251,14 @@ M.export = {
251251
doc = "use pandoc to convert entry to any format",
252252
impl = function(to, fp)
253253
local entry, id = ui.get_entry()
254-
require("feed.pandoc").convert({ id = id, to = to }, function(res)
255-
ut.save_file(vim.fs.joinpath(fp, entry.title .. "." .. to), res)
256-
end)
254+
assert(entry, "no valid entry")
255+
require("feed.pandoc").convert({
256+
id = id,
257+
to = to,
258+
stdout = function(res)
259+
ut.save_file(vim.fs.joinpath(fp, entry.title .. "." .. to), res)
260+
end,
261+
})
257262
end,
258263
}
259264

lua/feed/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---@class feed.searchOpts
2-
---@field backend "telescope" | "mini.pick" | "fzf-lua" | "snacks.pick"
2+
---@field backend "telescope" | "mini.pick" | "fzf-lua" | "snacks.pick" | table -- TODO: not nice
33
---@field sort_order? "ascending" | "descending"
44
---@field ignorecase? boolean
55
---@field default_query? string

lua/feed/curl.lua

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ end
5353
---@param url string
5454
---@param opts { headers: table, data: string | table, etag: string, last_modified: string, timeout: string, cmds: table }
5555
---@param cb? any
56-
---@return vim.SystemCompleted?
56+
---@return vim.SystemObj
5757
function M.get(url, opts, cb)
5858
opts = opts or {}
5959
opts.timeout = vim.F.if_nil(opts.timeout, "10")
@@ -64,7 +64,7 @@ function M.get(url, opts, cb)
6464
user_agent = "feed.nvim/2.0",
6565
}, opts.headers or {}))
6666
local dump_fp = vim.fn.tempname()
67-
local cmds = vim.tbl_flatten({
67+
local cmds = ut.tbl_flatten({
6868
"curl",
6969
req_header,
7070
"-sSL",
@@ -103,8 +103,21 @@ function M.get(url, opts, cb)
103103
return cb and cb(obj) or obj
104104
end
105105

106-
return cb and vim.system(cmds, { text = true }, cb and process or nil)
107-
or process(vim.system(cmds, { text = true }):wait())
106+
if cb then
107+
return vim.system(cmds, { text = true }, cb and process or nil)
108+
else
109+
return setmetatable({}, {
110+
__index = function(_, k)
111+
if k == "wait" then
112+
return process(vim.system(cmds, { text = true }):wait())
113+
end
114+
end,
115+
})
116+
end
117+
118+
-- TODO: Curl.get just return the vim.system obj, call :wait to sync
119+
-- return cb and vim.system(cmds, { text = true }, cb and process or nil)
120+
-- or process(vim.system(cmds, { text = true }):wait())
108121
end
109122

110123
---@async

lua/feed/db/local.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ function M:setup_sync(c_feeds)
432432
table.sort(merged_tags)
433433

434434
if not feeds[url] then
435+
---@diagnostic disable-next-line: missing-fields
435436
feeds[url] = {}
436437
end
437438

lua/feed/db/ttrss.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@
104104
---@field getCounters fun(self: ttrssApi): table
105105
---@field setArticleLabel fun(self: ttrssApi, param: { article_ids: string, label_id: integer, assign: boolean })
106106
---@field updateArticle fun(self: ttrssApi, param: { article_ids: string, mode: integer, field: integer, data: string })
107+
107108
local api = {}
108109
local Curl = require("feed.curl")
109110
local Config = require("feed.config")
110111

111112
api.__index = api
112113

113-
---@param obj vim.SystemCompleted?
114+
---@param obj table? -- TODO: properly type
114115
local function decode_check(obj, method) --- TODO: assert decode gets the method
115116
assert(obj, "no response")
116117
assert(obj.code == 0, "curl err")
@@ -153,13 +154,13 @@ for k, v in pairs(methods) do
153154
data.sid = self.sid
154155
data.op = k
155156
if type(v) == "string" then
156-
return decode_check(Curl.get(url, { data = data }), k)[v]
157+
return decode_check(Curl.get(url, { data = data }):wait(), k)[v]
157158
elseif type(v) == "table" and v.async then
158159
return Curl.get(url, { data = data }, function(obj)
159160
return decode_check(obj, k)
160161
end)
161162
else
162-
return decode_check(Curl.get(url, { data = data }), k)
163+
return decode_check(Curl.get(url, { data = data }):wait(), k)
163164
end
164165
end
165166
end

lua/feed/pandoc.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ local function convert(ctx)
1818
local src = ctx.src
1919
local fp = ctx.id and tostring(db.dir / "data" / ctx.id) or nil
2020
local from = ctx.from or "html"
21-
local to = ctx.to or vim.api.nvim_get_runtime_file("lua/feed/pandoc/gfm.lua", false)[1]
21+
local to = ctx.to or vim.api.nvim_get_runtime_file("scripts/gfm.lua", false)[1]
2222
local stdout = ctx.stdout
2323
local on_exit = ctx.on_exit
2424

0 commit comments

Comments
 (0)