MagicDuck / grug-far.nvim

Find And Replace plugin for neovim
MIT License
831 stars 25 forks source link

Closing grug-far with Ctrl W - O changes the file syntax of the current buffer #298

Open mariano-dagostino opened 1 week ago

mariano-dagostino commented 1 week ago

When I find what I need with grub-far I usually keep the current buffer opened and close the rest using Ctrl-W + O this action seems to confuse nvim and the current buffer gets a different syntax language. Hopefully this video will illustrate the problem.

https://github.com/user-attachments/assets/dd81933e-0b35-42c4-a9f4-8cc5c9d7e3d1

MagicDuck commented 1 week ago

hmm, that's strange, I can't reproduce this myself (tried with both tsc and php files and with minimal repro env). There's probably some other plugin or autocommand that's causing it.

Can you try it with a minimal reproduction config. ex: repro.lua:

local root = vim.fn.fnamemodify('~/.nvim_repro', ':p')
-- set stdpaths to use .repro
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end
-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    '--single-branch',
    'https://github.com/folke/lazy.nvim.git',
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

vim.g.maplocalleader = ','
-- install plugins
local plugins = {
  -- do not remove the colorscheme!
  'folke/tokyonight.nvim',
  {
    "MagicDuck/grug-far.nvim",
    config = function()
      require('grug-far').setup({})
    end,
  },
  -- add any other pugins here
}

require('lazy').setup(plugins, {
  root = root .. '/plugins',
})

-- add anything else here
-- vim.opt.termguicolors = true
-- do not remove the colorscheme!
vim.cmd([[colorscheme tokyonight]])

Then run with:

nvim -u repro.lua /path/to/somefile.php

If you can't reproduce it with the minimal repro, I would suggest narrowing it down to find the particular offending plugin or config. Maybe there's something that improve in grug-far.nvim to make it more resilient :)

Btw, the only place in the code we set the filetype for the buffer is here, just after creating the buffer... https://github.com/MagicDuck/grug-far.nvim/blob/190c03d54e8976491e6e49acb97087bf4182b079/lua/grug-far/farBuffer.lua#L250

MagicDuck commented 2 days ago

@mariano-dagostino any update from your side? Otherwise I'll close the issue...

mariano-dagostino commented 2 days ago

@MagicDuck Thanks. I will try to setup the minimal environment as you requested. Maybe next week. I'm using lazyvim and still familiarizing with lua script.

MagicDuck commented 1 day ago

sure, no worries 😄