Skip to content

File changes not immediately visible after formatter run #222

Description

@Philogy

Neovim version (nvim -v)

NVIM v0.11.0 Build type: Release LuaJIT 2.1.1744318430

Operating system/version

MacOS Sonoma 14.5

Expected behaviour

Upon saving a file the formatter is called and also the updated contents of the file are visible in the "buffer" (not sure if this is the right neovim terminology for the file you actually see).

Actual behaviour

The formatter is run but the updated contents are not immediately visible in the buffer. One must either alt-tab away and back or close & reopen the file or use :e to view the updated contents.

Output of :checkhealth guard

Executable check ~
- OK forge found

Settings ~
- OK fmt_on_save: true
- OK lsp_as_default_formatter: false
- OK save_on_fmt: true

Tools registered for current buffer (bufnr 1) ~
- OK Current buffer has filetype solidity:
- 1 formatter autocmds attached
- 0 linter autocmds attached
- formatters:
- {
    args = { "fmt" },
    cmd = "forge",
    stdin = false
  }

How to reproduce the issue

Setup Minimal Neovim & Install Formatter

mkdir /tmp/guard-repro
cd /tmp/guard-repro
git clone https://github.com/nvimdev/guard.nvim
git clone https://github.com/nvimdev/guard-collection
# Installs `forge`
curl -L https://foundry.paradigm.xyz | bash
foundryup

Create Minimal Neovim Config

vim.opt.rtp:append('/tmp/guard-repro/guard.nvim')
vim.opt.rtp:append('/tmp/guard-repro/guard-collection')

local ft = require('guard.filetype')
ft("solidity"):fmt({
  cmd = "forge",
  args = { "fmt" },
  stdin = false,
})

Setup Minimal Foundry Project

mkdir src
echo "contract A {}" > src/mini.sol
touch foundry.toml

Open neovim

nvim --clean -u repro.lua src/mini.sol

Test Behavior

  1. Insert spaces between curly braces
  2. Trigger formatting with :w
  3. Observe no changes
  4. "refresh" file via :e or alt-tabbing => file updated

Are you sure this is a min repro?

  • I understand that if my repro step is too complicated (e.g. here is my 1k+ line config and please help me), developers might not be able to help.
  • I can confirm that my reproduction step only involves vim.opt.rtp and configuration themselves

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions