Skip to content

[audit] Replace vim.fn.system shell pipeline with vim.system in treesitter.lua#297

Closed
stanfish06 wants to merge 1 commit into
masterfrom
audit/treesitter-vim-system
Closed

[audit] Replace vim.fn.system shell pipeline with vim.system in treesitter.lua#297
stanfish06 wants to merge 1 commit into
masterfrom
audit/treesitter-vim-system

Conversation

@stanfish06

Copy link
Copy Markdown
Owner

What

Replace vim.fn.system("ldd --version 2>&1 | head -n1") with vim.system({"ldd", "--version"}, {text=true}):wait() in lua/config/treesitter.lua.

Where

lua/config/treesitter.lua:42–51get_glibc_version() helper used by can_auto_install_parsers() at startup.

Why it matters

vim.fn.system() with shell metacharacters (2>&1, |, head) depends on $SHELL and introduces implicit shell-quoting rules. vim.system() (stable since Neovim 0.10) spawns the process directly without a shell, captures stdout and stderr as separate fields, and is the idiomatic modern API. The config already requires Neovim 0.11+ (uses vim.lsp.config/vim.lsp.enable), so vim.system() is always available.

Changes

  • vim.fn.system(shell_string)vim.system({args}, {text=true}):wait()
  • vim.v.shell_error check → result.code ~= 0
  • 2>&1 shell redirect replaced by: prefer stdout, fall back to stderr (handles distros that print version info to stderr)
  • head -n1 shell filter → output:match("^([^\n]*)") in Lua
  • Match logic is otherwise identical: GLIBC X.Y or trailing X.Y on first line

Generated by Claude Code

…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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread lua/config/treesitter.lua
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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@stanfish06 stanfish06 closed this Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants