Skip to content

Commit 3ead133

Browse files
author
lex
committed
fix: move PosteInfo to plugin/poste.lua so dev version always wins
Lazy.nvim loads production init.lua first (cached). PosteInfo defined inside setup() would always be the old production version even after dev plugin/poste.lua was sourced later. Moving PosteInfo to plugin/poste.lua ensures the latest file on rtp defines the command. Also switch setup guard from module-level to vim.g for cross-module safety.
1 parent d80278a commit 3ead133

2 files changed

Lines changed: 59 additions & 52 deletions

File tree

lua/poste/init.lua

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ function M.setup(opts)
3535
opts = opts or {}
3636
state.config = vim.tbl_deep_extend("force", state.config, opts)
3737

38-
if state._setup_done then
38+
if vim.g.poste_setup_done then
3939
return
4040
end
41-
state._setup_done = true
41+
vim.g.poste_setup_done = true
4242

4343
completion.register()
4444
require("poste.http.lua_docs").setup()
@@ -130,56 +130,6 @@ function M.setup(opts)
130130
require("poste.http.history").show()
131131
end, { desc = "Show HTTP request history" })
132132

133-
vim.api.nvim_create_user_command("PosteInfo", function()
134-
local binary = state.find_poste_binary()
135-
local binary_path = binary or "(not found)"
136-
local version = "(unknown)"
137-
if binary then
138-
local ok, output = pcall(vim.fn.system, { binary, "--version" })
139-
if ok then
140-
version = vim.trim(output)
141-
end
142-
end
143-
144-
local parts = { "" }
145-
146-
table.insert(parts, "binary: " .. binary_path)
147-
table.insert(parts, "version: " .. version)
148-
table.insert(parts, "")
149-
150-
local blink_ok, blink = pcall(require, "blink.cmp")
151-
if blink_ok then
152-
local providers = {}
153-
if blink.config and blink.config.sources and blink.config.sources.providers then
154-
for id, _ in pairs(blink.config.sources.providers) do
155-
table.insert(providers, id)
156-
end
157-
end
158-
local has_poste = vim.tbl_contains(providers, "poste") and "yes" or "no"
159-
table.insert(parts, "blink.cmp: loaded")
160-
table.insert(parts, " providers: " .. (#providers > 0 and table.concat(providers, ", ") or "(none)"))
161-
table.insert(parts, " poste src: " .. has_poste)
162-
else
163-
table.insert(parts, "blink.cmp: not loaded")
164-
end
165-
166-
local cmp_ok = pcall(require, "cmp")
167-
if cmp_ok then
168-
table.insert(parts, "nvim-cmp: loaded")
169-
end
170-
171-
local completion_ok, completion = pcall(require, "poste.http.completion")
172-
if completion_ok then
173-
table.insert(parts, "poste cmp: " .. completion.status())
174-
end
175-
176-
local ft = vim.bo.filetype or "(none)"
177-
table.insert(parts, "filetype: " .. ft)
178-
table.insert(parts, "")
179-
180-
vim.notify(table.concat(parts, "\n"), vim.log.levels.INFO)
181-
end, { desc = "Show Poste environment info" })
182-
183133
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
184134
pattern = { "*.http", "*.rest", "*.redis" },
185135
callback = function()

plugin/poste.lua

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,60 @@ if install_ok then
2121
end
2222

2323
require("poste").setup()
24+
25+
-- PosteInfo: show binary, version, and completion engine status.
26+
-- Defined here rather than in setup() so the latest plugin/poste.lua
27+
-- on rtp always wins, even when lazy.nvim cached an older init.lua.
28+
pcall(vim.api.nvim_del_user_command, "PosteInfo")
29+
vim.api.nvim_create_user_command("PosteInfo", function()
30+
local state = require("poste.state")
31+
local binary = state.find_poste_binary()
32+
local binary_path = binary or "(not found)"
33+
local version = "(unknown)"
34+
if binary then
35+
local ok, output = pcall(vim.fn.system, { binary, "--version" })
36+
if ok then
37+
version = vim.trim(output)
38+
end
39+
end
40+
41+
local sep = ""
42+
local parts = { sep }
43+
44+
table.insert(parts, "binary: " .. binary_path)
45+
table.insert(parts, "version: " .. version)
46+
table.insert(parts, sep)
47+
48+
local blink_ok = pcall(require, "blink.cmp")
49+
if blink_ok then
50+
local providers = {}
51+
local config_ok, config = pcall(require, "blink.cmp.config")
52+
if config_ok and config.sources and config.sources.providers then
53+
for id, _ in pairs(config.sources.providers) do
54+
table.insert(providers, id)
55+
end
56+
end
57+
local has_poste = vim.tbl_contains(providers, "poste") and "yes" or "no"
58+
table.insert(parts, "blink.cmp: loaded")
59+
table.insert(parts, " providers: " .. (#providers > 0 and table.concat(providers, ", ") or "(none)"))
60+
table.insert(parts, " poste src: " .. has_poste)
61+
else
62+
table.insert(parts, "blink.cmp: not loaded")
63+
end
64+
65+
local cmp_ok = pcall(require, "cmp")
66+
if cmp_ok then
67+
table.insert(parts, "nvim-cmp: loaded")
68+
end
69+
70+
local completion_ok, completion = pcall(require, "poste.http.completion")
71+
if completion_ok then
72+
table.insert(parts, "poste cmp: " .. completion.status())
73+
end
74+
75+
local ft = vim.bo.filetype or "(none)"
76+
table.insert(parts, "filetype: " .. ft)
77+
table.insert(parts, sep)
78+
79+
vim.notify(table.concat(parts, "\n"), vim.log.levels.INFO)
80+
end, { desc = "Show Poste environment info" })

0 commit comments

Comments
 (0)