[audit] Replace vim.fn.system shell pipeline with vim.system in treesitter.lua#297
[audit] Replace vim.fn.system shell pipeline with vim.system in treesitter.lua#297stanfish06 wants to merge 1 commit into
Conversation
…tter.lua vim.fn.system() with shell metacharacters (2>&1, |) depends on $SHELL and is harder to reason about. vim.system() (added in Neovim 0.10) spawns the process directly, captures stdout/stderr separately, and is the idiomatic modern API. No behaviour change: glibc version detection logic is identical.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e26934613
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| local function get_glibc_version() | ||
| local result = vim.fn.system("ldd --version 2>&1 | head -n1") | ||
| if vim.v.shell_error ~= 0 then | ||
| local result = vim.system({ "ldd", "--version" }, { text = true }):wait() |
There was a problem hiding this comment.
Handle missing ldd without aborting startup
On macOS or other systems where ldd is not in PATH, vim.system({ "ldd", "--version" }, ...) throws before :wait() can return, so the result.code check below is never reached. Because get_glibc_version() is called by ts_install() while this module loads, those users now hit a Lua startup error instead of the previous shell pipeline simply producing no parseable glibc version and continuing to the tree-sitter CLI check.
Useful? React with 👍 / 👎.
What
Replace
vim.fn.system("ldd --version 2>&1 | head -n1")withvim.system({"ldd", "--version"}, {text=true}):wait()inlua/config/treesitter.lua.Where
lua/config/treesitter.lua:42–51—get_glibc_version()helper used bycan_auto_install_parsers()at startup.Why it matters
vim.fn.system()with shell metacharacters (2>&1,|,head) depends on$SHELLand introduces implicit shell-quoting rules.vim.system()(stable since Neovim 0.10) spawns the process directly without a shell, capturesstdoutandstderras separate fields, and is the idiomatic modern API. The config already requires Neovim 0.11+ (usesvim.lsp.config/vim.lsp.enable), sovim.system()is always available.Changes
vim.fn.system(shell_string)→vim.system({args}, {text=true}):wait()vim.v.shell_errorcheck →result.code ~= 02>&1shell redirect replaced by: preferstdout, fall back tostderr(handles distros that print version info to stderr)head -n1shell filter →output:match("^([^\n]*)")in LuaGLIBC X.Yor trailingX.Yon first lineGenerated by Claude Code