Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(provider): refactor "ASYNC_DIRECT" callback signature #810

Merged
merged 6 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ jobs:
run: |
cargo binstall --no-confirm selene
selene --config selene.toml ./lua
# - uses: stevearc/nvim-typecheck-action@v2
# with:
# path: lua
# configpath: ".luarc.json"
- uses: stevearc/nvim-typecheck-action@v2
with:
nvim-version: v0.10.3
path: lua
configpath: ".luarc.json"
- uses: stefanzweifel/git-auto-commit-action@v5
if: ${{ github.ref != 'refs/heads/main' }}
with:
Expand Down
23 changes: 14 additions & 9 deletions lua/fzfx/cfg/_lsp_locations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@
local function impl(query, context, on_complete)
local lsp_clients = lsp.get_clients({ bufnr = context.bufnr })
if tbl.tbl_empty(lsp_clients) then
on_complete("no active lsp clients.")
log.echo(LogLevels.INFO, "no active lsp clients.")
on_complete(nil)

Check warning on line 294 in lua/fzfx/cfg/_lsp_locations.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/_lsp_locations.lua#L293-L294

Added lines #L293 - L294 were not covered by tests
return
end

Expand All @@ -307,7 +308,7 @@
end
if not supported then
log.echo(LogLevels.INFO, vim.inspect(opts.method) .. " not supported.")
on_complete(vim.inspect(opts.method) .. " not supported.")
on_complete(nil)

Check warning on line 311 in lua/fzfx/cfg/_lsp_locations.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/_lsp_locations.lua#L311

Added line #L311 was not covered by tests
return
end

Expand All @@ -324,11 +325,11 @@

if tbl.tbl_empty(results) then
log.echo(LogLevels.INFO, "no lsp locations found.")
on_complete("no lsp locations found.")
on_complete(nil)

Check warning on line 328 in lua/fzfx/cfg/_lsp_locations.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/_lsp_locations.lua#L328

Added line #L328 was not covered by tests
return
end

on_complete(nil, results)
on_complete(results)

Check warning on line 332 in lua/fzfx/cfg/_lsp_locations.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/_lsp_locations.lua#L332

Added line #L332 was not covered by tests
end
)

Expand Down Expand Up @@ -644,7 +645,8 @@
local function impl(query, context, on_complete)
local lsp_clients = lsp.get_clients({ bufnr = context.bufnr })
if tbl.tbl_empty(lsp_clients) then
on_complete("no active lsp clients.")
log.echo(LogLevels.INFO, "no active lsp clients.")
on_complete(nil)

Check warning on line 649 in lua/fzfx/cfg/_lsp_locations.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/_lsp_locations.lua#L648-L649

Added lines #L648 - L649 were not covered by tests
return
end
-- log.debug(
Expand All @@ -659,7 +661,8 @@
end
end
if not supported then
on_complete(vim.inspect(opts.method) .. " not supported.")
log.echo(LogLevels.INFO, vim.inspect(opts.method) .. " not supported.")
on_complete(nil)

Check warning on line 665 in lua/fzfx/cfg/_lsp_locations.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/_lsp_locations.lua#L664-L665

Added lines #L664 - L665 were not covered by tests
return
end

Expand All @@ -676,7 +679,8 @@
M._process_prepare_call_hierarchy_response(response1 --[[@as table? ]])

if prepared_item == nil then
on_complete("no lsp call hierarchy found.")
log.echo(LogLevels.INFO, "no lsp call hierarchy found.")
on_complete(nil)

Check warning on line 683 in lua/fzfx/cfg/_lsp_locations.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/_lsp_locations.lua#L682-L683

Added lines #L682 - L683 were not covered by tests
return
end

Expand All @@ -692,11 +696,12 @@
local results = M._process_call_hierarchy_response(response2 --[[@as table? ]], opts)

if tbl.tbl_empty(results) then
on_complete("no lsp call hierarchy found.")
log.echo(LogLevels.INFO, "no lsp call hierarchy found.")
on_complete(nil)

Check warning on line 700 in lua/fzfx/cfg/_lsp_locations.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/_lsp_locations.lua#L699-L700

Added lines #L699 - L700 were not covered by tests
return
end

on_complete(nil, results)
on_complete(results)

Check warning on line 704 in lua/fzfx/cfg/_lsp_locations.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/_lsp_locations.lua#L704

Added line #L704 was not covered by tests
end
)

Expand Down
11 changes: 7 additions & 4 deletions lua/fzfx/cfg/git_branches.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@
async.void(function()
local git_root_cmd = context.git_root_cmd
if git_root_cmd:failed() then
on_complete("not in git repo.")
log.echo(LogLevels.INFO, "not in git repo.")
on_complete(nil)

Check warning on line 96 in lua/fzfx/cfg/git_branches.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/git_branches.lua#L95-L96

Added lines #L95 - L96 were not covered by tests
return
end

local git_current_branch_cmd = cmds.run_git_current_branch_async()
if git_current_branch_cmd:failed() then
on_complete(table.concat(git_current_branch_cmd.stderr, " "))
log.echo(LogLevels.INFO, table.concat(git_current_branch_cmd.stderr, " "))
on_complete(nil)

Check warning on line 103 in lua/fzfx/cfg/git_branches.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/git_branches.lua#L102-L103

Added lines #L102 - L103 were not covered by tests
return
end

Expand All @@ -107,7 +109,8 @@

local git_branches_cmd = cmds.run_git_branches_async(remote_branch)
if git_branches_cmd:failed() then
on_complete(table.concat(git_branches_cmd.stderr, " "))
log.echo(LogLevels.INFO, table.concat(git_branches_cmd.stderr, " "))
on_complete(nil)

Check warning on line 113 in lua/fzfx/cfg/git_branches.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/git_branches.lua#L112-L113

Added lines #L112 - L113 were not covered by tests
return
end

Expand All @@ -117,7 +120,7 @@
end
end

on_complete(nil, results)
on_complete(results)
end)()
end

Expand Down
28 changes: 5 additions & 23 deletions lua/fzfx/detail/general.lua
Original file line number Diff line number Diff line change
Expand Up @@ -387,34 +387,16 @@
--- @param query string?
--- @param context fzfx.PipelineContext?
function ProviderSwitch:_handle_async_direct(provider_config, query, context)
--- @param err1 string?
--- @param data1 string[]?
local function _on_complete(err1, data1)
log.debug(
string.format("|async done| data1:%s, err1:%s", vim.inspect(data1), vim.inspect(err1))
)
--- @param data1 string[]|nil
local function _on_complete(data1)
log.debug(string.format("|async done| data1:%s", vim.inspect(data1)))

Check warning on line 392 in lua/fzfx/detail/general.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/detail/general.lua#L392

Added line #L392 was not covered by tests
log.debug(string.format("|async done| donefile:%s", vim.inspect(self.donefile)))

-- When data is ready, write it into `resultfile`.
if err1 then
if tbl.tbl_empty(data1) then

Check warning on line 396 in lua/fzfx/detail/general.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/detail/general.lua#L396

Added line #L396 was not covered by tests
fio.writefile(self.resultfile, "")
log.echo(LogLevels.INFO, err1)
-- log.err(
-- string.format(
-- "failed to complete pipeline %s (ASYNC_DIRECT provider %s)! query:%s, context:%s, error:%s",
-- vim.inspect(self.pipeline),
-- vim.inspect(provider_config),
-- vim.inspect(query),
-- vim.inspect(context),
-- vim.inspect(err1)
-- )
-- )
else
if tbl.tbl_empty(data1) then
fio.writefile(self.resultfile, "")
else
fio.writelines(self.resultfile, data1 --[[@as string[] ]])
end
fio.writelines(self.resultfile, data1 --[[@as string[] ]])

Check warning on line 399 in lua/fzfx/detail/general.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/detail/general.lua#L399

Added line #L399 was not covered by tests
end

-- Then notify provider it is ready.
Expand Down
2 changes: 1 addition & 1 deletion lua/fzfx/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
--- @alias fzfx.CommandStringProvider fzfx.PlainCommandStringProvider|fzfx.FunctionalCommandStringProvider
--- @alias fzfx.CommandArrayProvider fzfx.PlainCommandArrayProvider|fzfx.FunctionalCommandArrayProvider
--- @alias fzfx.DirectProvider fun(query:string?,context:fzfx.PipelineContext?):string[]?
--- @alias fzfx.AsyncDirectProviderOnComplete fun(err:string?,data:string[]?):nil
--- @alias fzfx.AsyncDirectProviderOnComplete fun(data:string[]|nil):nil
--- @alias fzfx.AsyncDirectProvider fun(query:string?,context:fzfx.PipelineContext?,on_complete:fzfx.AsyncDirectProviderOnComplete):nil
--- @alias fzfx.Provider fzfx.CommandStringProvider|fzfx.CommandArrayProvider|fzfx.DirectProvider|fzfx.AsyncDirectProvider
---
Expand Down
Loading