Commit Graph

10 Commits

Author SHA1 Message Date
0814086a23 docs: misc (#33093)
Co-authored-by: Jx <JxJxxJxJ@github.com>
Co-authored-by: Richard Dzenis <richard@dzenis.dev>
Co-authored-by: Shixian Sheng <shixian_sheng-2@protonmail.com>
Co-authored-by: Sourabh Kumar <sourabh7.tech@gmail.com>
Co-authored-by: Yegor Yefremov <yegorslists@googlemail.com>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2025-04-13 07:41:54 +08:00
7ead328a48 build(cjson): sync with upstream (#32114)
Sync with commit 91ca29db9a
2025-02-26 09:40:02 +01:00
517ecb85f5 feat(stdlib): vim.json.encode(...,{escape_slash:boolean}) #30561
Problem:
vim.json.encode escapes every slash in string values (for example in
file paths), and is not optional. Use-case is for preventing HTML
injections (eg. injecting `</script>` closing tag); in the context of
Nvim this is rarely useful.

Solution:
- Add a `escape_slash` flag to `vim.json.encode`.
- Defaults to `false`. (This is a "breaking" change, but more like
  a bug fix.)
2024-12-06 12:43:41 -08:00
e15991c811 fix(vim.json): properly treat luanil options as booleans (#28622)
Note: Upstream doesn't have this. It's an Nvim addition.
2024-05-03 19:26:56 +08:00
8d4a53fe6e fix(vim.json)!: remove global options, "null", "array_mt" #24070
Problem:
- `vim.json` exposes various global options which:
  - affect all Nvim Lua plugins (especially the LSP client)
  - are undocumented and untested
  - can cause confusing problems such as: cc76ae3abe
- `vim.json` exposes redundant mechanisms:
  - `vim.json.null` is redundant with `vim.NIL`.
  - `array_mt` is redundant because Nvim uses a metatable
    (`vim.empty_dict()`) for empty dict instead, which `vim.json` is
    configured to use by default (see `as_empty_dict`).
    Example:
    ```
    :lua vim.print(vim.json.decode('{"bar":[],"foo":{}}'))
    --> { bar = {},  foo = vim.empty_dict() }
    ```
    Thus we don't need to also decorate empty arrays with `array_mt`.

Solution:
Remove the functions from the public vim.json interface.
Comment-out the implementation code to minimize drift from upstream.

TODO:
- Expose the options as arguments to `vim.json.new()`
2023-06-21 01:10:32 -07:00
4d2744ffe3 refactor: fix clang-tidy bugprone-signed-char-misuse warnings
Prefer to declare variables with correct type instead of explicit casts
wherever possible.
2022-03-04 19:52:41 +01:00
b87867e69e feat(lua): add proper support of luv threads 2022-02-26 14:01:38 +01:00
912a6e5a9c feat(lsp): improve json deserialization performance (#15854)
* Add optional second table argument to vim.json.decode which takes
  a table 'luanil' which can include the 'object' and/or 'array' keys. These
  options use luanil when converting NULL in json objects and arrays
  respectively. The default behavior matches the original lua-cjson.
* Remove recursive_convert_NIL function from rpc.lua, use
  vim.json.decode with luanil = { object = true } instead. This removes a hotpath
  in the json deserialization pipeline by dropping keys with json NULL
  values throughout the deserialized table.
2021-10-05 08:37:20 -07:00
30fed27241 feat(lua): expose lua-cjson as vim.json
* add vim.json.encode and vim.json.decode
* use vim.NIL instead of cjson.null
* resolve strict-prototypes warnings

* The following benchmark shows an approximately 2.5x (750 ms vs 300 ms) improvement in deserialization performance over
  vim.fn.json_decode on a medium package.json

  ```lua
  local uv = vim.loop
  local function readfile(path)
    return
  end

  local json_url = "https://raw.githubusercontent.com/rust-analyzer/rust-analyzer/b24c8d5c89ee93d1172b4127564f5da3b0c88dad/editors/code/package.json"
  io.popen(string.format('curl -v -f -L -O %q &> /dev/null', json_url))

  local json_string = io.open('package.json'):read '*a'

  uv.update_time()
  local start = uv.hrtime()

  for i = 1,1000 do
    vim.fn.json_decode(json_string)
  end

  uv.update_time()
  print(string.format("Deserialization time vim.fn.json_decode: %s ms", (uv.hrtime() - start) * (1e-6)))

  uv.update_time()
  local start = uv.hrtime()

  for i = 1,1000 do
    vim.json.decode(json_string)
  end
  uv.update_time()
  print(string.format("Deserialization time vim.json.decode: %s ms", (uv.hrtime() - start) * (1e-6)))
  ```

Co-Authored-By: Björn Linse <bjorn.linse@gmail.com>
2021-09-26 00:35:55 -07:00
8decc9f52d feat(lua): add lua-cjson as vendored dependency
Derived from the openresty lua-cjson fork at commit 3d93d29709
2021-09-26 00:35:47 -07:00