Explorer/history panel window options use :set semantics, so windows opened from the panel lose number/signcolumn/list

Open Beginner friendly
#579 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
lua, neovim

Research direction

Start in lua/codediff/ui/lib/split.lua at Split:_apply_win_options(), which sets vim.wo[self.winid][k] without a scope, then look at apply_pane_options() in lua/codediff/ui/view/side_by_side/create.lua. Switch both to local-scope writes (vim.wo[winid][0][k]), reproduce with the nvim --clean command in the issue, and confirm that :tabnew g.py from the explorer keeps number and signcolumn set. Done means the inherited values stay at the user's settings while the panel still renders as before.

Written by the indexing model from the issue text.

Description

Summary

Windows created while the explorer (or history) panel is the current window inherit the panel's number=false, relativenumber=false, signcolumn=no, list=false, wrap=false, etc. For example, pressing :tabnew some/file.py or :vsplit with the cursor in the explorer opens a file with no line numbers and no sign column, even though the user's config has them on.

The reason is that the panel's win_options are applied with vim.wo[winid][k] = v, which has :set semantics (it updates both the window-local value and the window's "global" copy that new windows inherit). Applying them with :setlocal semantics (vim.wo[winid][0][k] = v, or nvim_set_option_value(k, v, { win = winid, scope = "local" })) keeps the panel's look while leaving the inherited values alone.

Environment

  • codediff.nvim 4.0.6 (commit 09d9ebe)
  • Neovim v0.12.6, macOS

Steps to reproduce

mkdir /tmp/cd-test && cd /tmp/cd-test && git init -q
printf 'a\n' > f.py; printf 'x\n' > g.py; git add .; git commit -qm init; echo b >> f.py
nvim --clean -c 'set number list signcolumn=yes' \
  -c 'packadd codediff.nvim' -c 'lua require("codediff").setup()' \
  -c 'CodeDiff' -c 'sleep 500m' \
  -c 'lua vim.cmd("tabnew g.py"); print(("number=%s list=%s signcolumn=%s"):format(vim.wo.number, vim.wo.list, vim.wo.signcolumn))'

(Adjust packadd to however the plugin is installed; the behaviour is the same in a normal interactive session: :CodeDiff, then :tabnew g.py from the explorer.)

Observed: number=false list=false signcolumn=no
Expected: number=true list=true signcolumn=yes (the user's settings)

For comparison, doing the same from the nvim-tree window gives number=true list=true signcolumn=yes; nvim-tree applies its window options with nvim_set_option_value(k, v, { scope = "local" }).

Cause

lua/codediff/ui/lib/split.lua, Split:_apply_win_options():

for k, v in pairs(self._win_options) do
  pcall(function()
    vim.wo[self.winid][k] = v   -- :set semantics
  end)
end

Per :h vim.wo / :h nvim_set_option_value(), setting vim.wo[winid][k] without a buffer index behaves like :set in that window, so the window's inheritable copy of the option is overwritten too. New windows (:split, :vsplit, :tabnew, nvim_open_win) copy their options from the current window, so anything spawned from the panel starts with the panel's values.

The same pattern is used in apply_pane_options() in lua/codediff/ui/view/side_by_side/create.lua (vim.wo[original_win][opt] = val for cursorline, wrap, list). Because the explorer window is created while a diff pane is current, it inherits list=false from there, and then passes it on.

Suggested fix

Use :setlocal semantics in both places:

-- lib/split.lua
vim.wo[self.winid][0][k] = v

-- view/side_by_side/create.lua
vim.wo[original_win][0][opt] = val
vim.wo[modified_win][0][opt] = val

I verified the split.lua change by monkeypatching Split:_apply_win_options at runtime: the explorer still renders with number=false signcolumn=no, and :tabnew g.py from it now gives number=true signcolumn=yes (list stays false until apply_pane_options gets the same treatment).

Happy to open a PR if that is easier.

Dominant language
Lua
Stars
1.6k
Forks
104
Avg merge
16d 23h
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from esmuellert/codediff.nvim

All issues in esmuellert/codediff.nvim

Similar issues

More Lua issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.