Skip to content

Commit 03590b6

Browse files
committed
fix: setup sequence
1 parent d37cc05 commit 03590b6

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

lua/cppman/index.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ local utils = require("cppman.utils")
55
local CACHE_HOME = os.getenv("XDG_CACHE_HOME") or vim.fs.joinpath(os.getenv("HOME"), ".cache")
66
local CACHE_DIR = vim.fs.joinpath(CACHE_HOME, "cppman")
77

8-
local index_db_path = vim.fs.joinpath(CACHE_DIR, "index.db")
9-
index_db_path = vim.fn.filereadable(index_db_path) == 1 and index_db_path
10-
or require("cppman.config").get().index_db_path
8+
local index_db_path
119

1210
---@type vim.SystemObj
1311
local job = nil
@@ -16,6 +14,10 @@ local job = nil
1614
M.entries = {}
1715

1816
M.setup = function()
17+
index_db_path = vim.fs.joinpath(CACHE_DIR, "index.db")
18+
index_db_path = vim.fn.filereadable(index_db_path) == 1 and index_db_path
19+
or require("cppman.config").get().index_db_path
20+
1921
if vim.fn.filereadable(index_db_path) == 0 then
2022
M.fetch()
2123
else

lua/cppman/init.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ local function pick(entries)
88
require("cppman.picker." .. config.get().picker)(entries)
99
end
1010

11-
---@param opts Cppman.Config
11+
---@param opts? Cppman.Config
1212
M.setup = function(opts)
13-
config.setup(opts)
13+
if vim.g.loaded_cppman then
14+
return
15+
end
16+
17+
config.setup(opts or {})
18+
19+
require("cppman.index").setup()
20+
21+
vim.g.loaded_cppman = true
1422
end
1523

1624
M.fetch_index = function()

plugin/cppman.lua

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
local os = vim.uv.os_uname().sysname
2-
if os ~= "Linux" then
3-
require("cppman.utils").error(os .. " is not supported")
4-
return
5-
end
6-
7-
require("cppman.index").setup()
1+
-- TODO: A rough fix for setup sequence, refactor it later
2+
vim.defer_fn(function()
3+
if not vim.g.loaed_cppman then
4+
require("cppman").setup()
5+
end
6+
end, 0)
87

98
vim.api.nvim_create_user_command("Cppman", function(args)
109
if args.args == "" then

0 commit comments

Comments
 (0)