Skip to content

Commit ed461c7

Browse files
AnnatarHeclaude
andcommitted
refactor(version): use vim.json.decode for JSON parsing
Replace manual regex-based JSON parser with Neovim's built-in vim.json.decode for more robust handling of edge cases. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 74db5fb commit ed461c7

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

‎lua/shelltime/version.lua‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,15 @@ local function url_encode(str)
2424
return str
2525
end
2626

27-
--- Parse JSON response (minimal parser for version check response)
27+
--- Parse JSON response using Neovim's built-in JSON decoder
2828
---@param json_str string JSON string
2929
---@return table|nil Parsed table or nil on error
3030
local function parse_json(json_str)
31-
-- Simple JSON parser for { "isLatest": bool, "latestVersion": "...", "version": "..." }
32-
local is_latest = json_str:match('"isLatest"%s*:%s*(true)')
33-
local latest_version = json_str:match('"latestVersion"%s*:%s*"([^"]+)"')
34-
local version = json_str:match('"version"%s*:%s*"([^"]+)"')
35-
36-
if latest_version and version then
37-
return {
38-
isLatest = is_latest ~= nil,
39-
latestVersion = latest_version,
40-
version = version,
41-
}
31+
local ok, result = pcall(vim.json.decode, json_str)
32+
if not ok or type(result) ~= 'table' then
33+
return nil
4234
end
43-
return nil
35+
return result
4436
end
4537

4638
--- Check CLI version against server

0 commit comments

Comments
 (0)