Skip to content

Commit

Permalink
perf(json): migrate legacy json_encode/json_decode to lua module (#367)
Browse files Browse the repository at this point in the history
* refactor(infra): embed rxi json.lua

* perf(json): embed rxi json.lua

* perf(json): ignore code coverage on json.lua

* perf(json): ignore code cov in luacov

* chore

* chore

* chore

* chore(pr): format with stylua

* perf(json): use 'vim.json' for nvim-0.9+

* chore

* chore

* chore

* ci(depends): auto download and commit rxi/json.lua

* ci(depends): fix syntax

* ci(depends): auto-commit

* chore(pr): format with stylua, add rxi/json.lua

* chore

---------

Co-authored-by: linrongbin16 <linrongbin16@users.noreply.github.com>
  • Loading branch information
linrongbin16 and linrongbin16 authored Nov 7, 2023
1 parent 0e0d063 commit 9e34209
Show file tree
Hide file tree
Showing 11 changed files with 691 additions and 121 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --config-path .stylua.toml --color always ./
- name: Format with stylua
- name: Add rxi/json.lua
if: ${{ github.ref != 'refs/heads/main' }}
shell: bash
run: |
echo "pwd"
echo $PWD
git clone --depth 1 https://github.com/rxi/json.lua.git ~/.json.lua
cp ~/.json.lua/json.lua ./lua/fzfx/rxi_json.lua
- name: Auto Commit
if: ${{ github.ref != 'refs/heads/main' }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "chore(pr): format with stylua"
commit_message: "chore(pr): auto-commit"
unit_test:
name: Unit Test
strategy:
Expand Down
3 changes: 3 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ modules = {
["fzfx"] = "lua/fzfx.lua",
["fzfx.*"] = "lua",
}
exclude = {
"lua/fzfx/rxi_json.lua",
}
4 changes: 2 additions & 2 deletions bin/general/previewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ shell_helpers.log_ensure(
"metajsonstring is not string! %s",
vim.inspect(metajsonstring)
)
local metaopts = vim.fn.json_decode(metajsonstring) --[[@as PreviewerMetaOpts]]
local metaopts = shell_helpers.json.decode(metajsonstring) --[[@as PreviewerMetaOpts]]
shell_helpers.log_debug("metaopts:[%s]", vim.inspect(metaopts))

--- @param l string?
Expand All @@ -81,7 +81,7 @@ elseif metaopts.previewer_type == "command_list" then
os.exit(0)
return
end
local cmd_splits = vim.fn.json_decode(cmd)
local cmd_splits = shell_helpers.json.decode(cmd)
if type(cmd_splits) ~= "table" or vim.tbl_isempty(cmd_splits) then
os.exit(0)
return
Expand Down
4 changes: 2 additions & 2 deletions bin/general/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ shell_helpers.log_ensure(
vim.inspect(metajsonstring)
)
--- @type ProviderMetaOpts
local metaopts = vim.fn.json_decode(metajsonstring) --[[@as ProviderMetaOpts]]
local metaopts = shell_helpers.json.decode(metajsonstring) --[[@as ProviderMetaOpts]]
shell_helpers.log_debug("metaopt:[%s]", vim.inspect(metaopts))

--- @param line string?
Expand Down Expand Up @@ -103,7 +103,7 @@ then
return
end

local cmd_splits = vim.fn.json_decode(cmd)
local cmd_splits = shell_helpers.json.decode(cmd)
if type(cmd_splits) ~= "table" or vim.tbl_isempty(cmd_splits) then
os.exit(0)
return
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ coverage:
patch:
default:
threshold: 90%
ignore:
- "lua/fzfx/rxi_json.lua"
Loading

0 comments on commit 9e34209

Please sign in to comment.