Skip to content

Commit 78dc5d0

Browse files
committed
feat: add type annotations for plenary.json
1 parent 4216828 commit 78dc5d0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lua/plenary/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
---@field curl PlenaryCurl
77
---@field functional PlenaryFunctional
88
---@field job PlenaryJob
9+
---@field json PlenaryJson
910
---@field path PlenaryPath
1011
---@field scandir PlenaryScandir
1112
---@field tbl PlenaryTbl

lua/plenary/json.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,32 @@
22

33
local singleComment = "singleComment"
44
local multiComment = "multiComment"
5+
---@return ""
56
local stripWithoutWhitespace = function()
67
return ""
78
end
89

10+
---@param str string
11+
---@param from? integer
12+
---@param to? integer
13+
---@return string
914
local function slice(str, from, to)
1015
from = from or 1
1116
to = to or #str
1217
return str:sub(from, to)
1318
end
1419

20+
---@param str string
21+
---@param from? integer
22+
---@param to? integer
23+
---@return string, integer count
1524
local stripWithWhitespace = function(str, from, to)
1625
return slice(str, from, to):gsub("%S", " ")
1726
end
1827

28+
---@param jsonString string
29+
---@param quotePosition integer
30+
---@return boolean
1931
local isEscaped = function(jsonString, quotePosition)
2032
local index = quotePosition - 1
2133
local backslashCount = 0
@@ -27,13 +39,14 @@ local isEscaped = function(jsonString, quotePosition)
2739
return backslashCount % 2 == 1 and true or false
2840
end
2941

42+
---@class PlenaryJson
3043
local M = {}
3144

3245
-- Strips any json comments from a json string.
3346
-- The resulting string can then be used by `vim.fn.json_decode`
3447
--
3548
---@param jsonString string
36-
---@param options table
49+
---@param options? { whitespace?: boolean }
3750
--- * whitespace:
3851
--- - defaults to true
3952
--- - when true, comments will be replaced by whitespace
@@ -43,6 +56,7 @@ function M.json_strip_comments(jsonString, options)
4356
local strip = options.whitespace == false and stripWithoutWhitespace or stripWithWhitespace
4457

4558
local insideString = false
59+
---@type "multiComment"|"singleComment"|false
4660
local insideComment = false
4761
local offset = 1
4862
local result = ""

0 commit comments

Comments
 (0)