romgrk / barbar.nvim

The neovim tabline plugin.
2.16k stars 81 forks source link

Barbar command cannot be executed when I opened a python file using Neovim (Label: bug) #532

Closed mcwatson123 closed 5 months ago

mcwatson123 commented 9 months ago

Description

I have a problem related to Python files when they are opened through nvim filename.py in PowerShell 7 Windows 11. I always set up Neovim with the autocommand VimEnter to achieve the layout I desire, especially in the following code snippet:

------SOME CODES-----------

" Check for the presence of a filename argument"
if argc() > 0
  " Use the first argument as the filename"
  let g:startup_filename = argv()[0]
  let g:nama_file = fnamemodify(expand(argv()[0]),':t:r')
  execute 'edit ' . g:startup_filename
else
  " Set a default filename if no argument is provided"
  let g:startup_filename = "default_filename.txt"
endif

au VimEnter * NvimTreeOpen 
au VimEnter * setlocal relativenumber
au VimEnter * set wrap 
au VimEnter * set modifiable
au VimEnter * TerminalSplit bash 
au VimEnter * wincmd x
autocmd VimEnter * call feedkeys("\<Esc>\<Esc>")
au VimEnter * wincmd j
au VimEnter * res 8
au VimEnter * wincmd l
au VimEnter * silent! q!
au VimEnter * execute 'vsp ' . g:startup_filename
au VimEnter * wincmd x
au VimEnter * vert res 30 
au VimEnter * wincmd l
au VimEnter * TagbarOpen 
"au VimEnter * wincmd l"
au VimEnter * wincmd l
au VimEnter * setlocal relativenumber
au VimEnter * set wrap 
au VimEnter * vert res 20 
autocmd VimEnter * call feedkeys("\<Esc>")
au VimEnter * wincmd h
autocmd VimEnter * call feedkeys("\<Esc>")

----SOME CODES------

"===============BARBAR SETUP ===================================="

lua <<EOF

require('barbar').setup({
  exclude_ft = {'terminal', 'pwsh.exe', 'C:/Program Files/PowerShell/7'},
  exclude_name = {'terminal', 'pwsh.exe', 'C:/Program Files/PowerShell/7/pwsh.exe', '/bin/bash'},

  -- Enable/disable animations
  animation = true,
  -- Automatically hide the tabline when there are this many buffers left.
  -- Set to any value >=0 to enable.
  auto_hide = false,

  -- Enable/disable current/total tabpages indicator (top right corner)
  tabpages = true,

  -- Enables/disable clickable tabs
  --  - left-click: go to buffer
  --  - middle-click: delete buffer
  clickable = true,

  -- Excludes buffers from the tabline
  --exclude_ft = {'javascript'},
  --exclude_name = {'package.json'},

  -- A buffer to this direction will be focused (if it exists) when closing the current buffer.
  -- Valid options are 'left' (the default), 'previous', and 'right'
  focus_on_close = 'left',

  -- Hide inactive buffers and file extensions. Other options are `alternate`, `current`, and `visible`.
  hide = {extensions = false, inactive = false},

  -- Disable highlighting alternate buffers
  highlight_alternate = false,

  -- Disable highlighting file icons in inactive buffers
  highlight_inactive_file_icons = false,

  -- Enable highlighting visible buffers
  highlight_visible = true,

  icons = {
    -- Configure the base icons on the bufferline.
    -- Valid options to display the buffer index and -number are `true`, 'superscript' and 'subscript'
    buffer_index = true,
    buffer_number = false,
    button = '',
    -- Enables / disables diagnostic symbols
    diagnostics = {
      [vim.diagnostic.severity.ERROR] = {enabled = true, icon = 'ff'},
      [vim.diagnostic.severity.WARN] = {enabled = false},
      [vim.diagnostic.severity.INFO] = {enabled = false},
      [vim.diagnostic.severity.HINT] = {enabled = true},
    },
    gitsigns = {
      added = {enabled = true, icon = '+'},
      changed = {enabled = true, icon = '~'},
      deleted = {enabled = true, icon = '-'},
    },
    filetype = {
      -- Sets the icon's highlight group.
      -- If false, will use nvim-web-devicons colors
      custom_colors = false,

      -- Requires `nvim-web-devicons` if `true`
      enabled = true,
    },
    separator = {left = '▎', right = ''},

    -- If true, add an additional separator at the end of the buffer list
    separator_at_end = true,

    -- Configure the icons on the bufferline when modified or pinned.
    -- Supports all the base icon options.
    modified = {button = '●'},
    pinned = {button = '', filename = true},

    -- Use a preconfigured buffer appearance— can be 'default', 'powerline', or 'slanted'
    preset = 'default',

    -- Configure the icons on the bufferline based on the visibility of a buffer.
    -- Supports all the base icon options, plus `modified` and `pinned`.
    alternate = {filetype = {enabled = false}},
    current = {buffer_index = true},
    inactive = {button = '×'},
    visible = {modified = {buffer_number = false}},
  },

  -- If true, new buffers will be inserted at the start/end of the list.
  -- Default is to insert after current buffer.
  insert_at_end = false,
  insert_at_start = false,

  -- Sets the maximum padding width with which to surround each tab
  maximum_padding = 1,

  -- Sets the minimum padding width with which to surround each tab
  minimum_padding = 1,

  -- Sets the maximum buffer name length.
  maximum_length = 30,

  -- Sets the minimum buffer name length.
  minimum_length = 0,

  -- If set, the letters for each buffer in buffer-pick mode will be
  -- assigned based on their name. Otherwise or in case all letters are
  -- already assigned, the behavior is to assign letters in order of
  -- usability (see order below)
  semantic_letters = true,

  -- Set the filetypes which barbar will offset itself for
  sidebar_filetypes = {
    -- Use the default values: {event = 'BufWinLeave', text = nil}
    NvimTree = true,
    -- Or, specify the text used for the offset:
    undotree = {text = 'undotree'},
    -- Or, specify the event which the sidebar executes when leaving:
    ['neo-tree'] = {event = 'BufWipeout'},
    -- Or, specify both
    Outline = {event = 'BufWinLeave', text = 'symbols-outline'},
  },

  -- New buffer letters are assigned in this order. This order is
  -- optimal for the qwerty keyboard layout but might need adjustment
  -- for other layouts.
  letters = 'asdfjkl;ghnmxcvbziowerutyqpASDFJKLGHNMXCVBZIOWERUTYQP',

  -- Sets the name of unnamed buffers. By default format is "[Buffer X]"
  -- where X is the buffer number. But only a static string is accepted here.
  no_name_title = nil,
})
EOF

"lua require'barbar'.setup{exclude_name={'pwsh.exe','bash  - 1'},icons={buffer_index=true},preset='slanted',focus_on_close='left',tabpages=true} "

"==============================="

----SOME CODES--------

I have also tried :PlugInstall and PlugUpdate and the output for barbar.nvim is "OK" and "Already Up to Date"

Steps to Reproduce

The issue arises when the autocommand executes Barbar's proprietary commands, such as BufferNext and BufferClose, and an error occurs as follows:

Error executing Lua callback: ...a\Local\nvim-data\plugged\barbar.nvim/lua/barbar/api.lua:215: BufWinEnter Autocommands for "*": Vim(append):Error executing lua callback: ...ocal\nvim-data\plugged\barbar.nvim/lua/barbar/events.lua:198: Invalid window id: -1
stack traceback:
        [C]: in function 'win_get_position'
        ...ocal\nvim-data\plugged\barbar.nvim/lua/barbar/events.lua:198: in function <...ocal\nvim-data\plugged\barbar.nvim/lua/barbar/events.lua:193>
        [C]: in function 'set_current_buf'
        ...a\Local\nvim-data\plugged\barbar.nvim/lua/barbar/api.lua:215: in function 'goto_buffer_relative'
        ...pData\Local\nvim-data\plugged\barbar.nvim/lua/barbar.lua:34: in function <...pData\Local\nvim-data\plugged\barbar.nvim/lua/barbar.lua:34>
stack traceback:
        [C]: in function 'set_current_buf'
        ...a\Local\nvim-data\plugged\barbar.nvim/lua/barbar/api.lua:215: in function 'goto_buffer_relative'
        ...pData\Local\nvim-data\plugged\barbar.nvim/lua/barbar.lua:34: in function <...pData\Local\nvim-data\plugged\barbar.nvim/lua/barbar.lua:34>

Here's a breakdown of the relevant code sections:

Screenshots

Informations

============================================================================== nvim: require("nvim.health").check()

Configuration ~

Runtime ~

Performance ~

Remote Plugins ~

============================================================================== nvim-lsp-installer: require("nvim-lsp-installer.health").check()

nvim-lsp-installer report ~

`

============================================================================== nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~

OS Info: { machine = "x86_64", release = "10.0.22621", sysname = "Windows_NT", version = "Windows 11 Home Single Language" } ~

Parser/Features H L F I J

============================================================================== provider: health#provider#check

Clipboard (optional) ~

Python 3 provider (optional) ~

Python virtualenv ~

Ruby provider (optional) ~

Node.js provider (optional) ~

Perl provider (optional) ~

============================================================================== telescope: require("telescope.health").check()

Checking for required plugins ~

Checking external dependencies ~

===== Installed extensions ===== ~

============================================================================== vim.lsp: require("vim.lsp.health").check()

vim.lsp: Active Clients ~

============================================================================== vim.treesitter: require("vim.treesitter.health").check()

Iron-E commented 9 months ago

Could you add a minimal reproduction, such that one can do nvim --clean -u minimal.vim and have the bug occur (example).

I see that there is a reproduction here, but without a self-contained example it will be hard to track this down.

Sorry if this is burdensome! I appreciate the detailed report so far.

mcwatson123 commented 8 months ago

@Iron-E I tried this

nvim --clean -u minimal.vim

When the file first opened, I didn't encounter any error messages. This might have something to do with Nvim-treesitter and Nvim-tree. That's pretty much all I know about it.

image

Iron-E commented 8 months ago

What was the content of the minimal file?

mcwatson123 commented 8 months ago

image Too many errors here

Iron-E commented 8 months ago

Sorry in advance for any confusion, I'll try to clarify. Let me know if you have further questions!

In a minimal file you'll want to leave out :Plug commands; Plug is responsible for installing plugins and loading them when neovim starts. However, we want to reduce the number of commands being run to as few as possible, so we can do without :Plug for now— here's how. If you put the installation location of barbar.nvim in the &rtp manually, it will load on its own.

After that, you can continue putting as little from your config (keeping relevant lines, such as your autocmds from the original post) as possible. Finally, remove any lines that allow the error you've encountered to remain.

Keep in mind, if you want to copy the example I linked into a .vim file, you can do this:

lua << EOF
-- lua goes here
EOF
mcwatson123 commented 7 months ago

@Iron-E

  1. I've tried doing what you mean. Please understand if my understanding is bad, don't be hasty, and don't be mad. You said that I was told to "leave out" :Plug command in "minimal file". As far as I know, the "minimal file" is the init.vim file (I use this) or init.lua and I followed the tutorial from neuralnine to enter the content below.
call plug#begin('C:/Users/Mackenzie Watson/AppData/Local/nvim-data/plugged')

---some codes------

Plug 'romgrk/barbar.nvim' " for tabline

--some codes---

call plug#end()

in init.vim (or what you said "minimal file") and as a result there is no harm in using the Plug command in init.vim, whereas you said I should "leave out" (delete?) :Plug.

  1. You asked me to include lua <<EOF in init.vim and I have entered it as explained previously
lua <<EOF

require('barbar').setup({
   exclude_ft = {'terminal', 'pwsh.exe', 'C:/Program Files/PowerShell/7'},
   exclude_name = {'terminal', 'pwsh.exe', 'C:/Program Files/PowerShell/7/pwsh.exe', '/bin/bash'},

   -- Enable/disable animations
   animation = true,
   -- Automatically hide the tabline when there are this many buffers left.
   -- Set to any value >=0 to enable.
   auto_hide = false,

------------
})
  1. You asked me to add the path "~/local/AppData/nvim-data/plugged/barbar.nvim" to my runtimepath and this was not necessary because when I tried
nvim D:/Documents/.../input.py

and in it I did

:echo &rtp, as a result I already have the "path to barbar.nvim", as shown below.

image

  1. You refer to the link https://github.com/romgrk/barbar.nvim/issues/522 and here you provide a solution to upgrade neovim (I am using choco upgrade --pre) to the latest version and I have updated it to version 0.10.0 and the result is the error still the same. Below is the image for the given input.py file (:version)

image

and this is the error

barbar nvim error

Iron-E commented 7 months ago

Sorry again for any confusion— I'll try to explain a different way :)

Put the contents of the following code block into a file called "minimal.lua" on your computer:

vim.opt.rtp:append {
  '~/.local/share/nvim/lazy/barbar.nvim', -- or your install path
  -- other plugins can be loaded this way too
}

require'barbar'.setup {
  -- put the setup options here
}

-- the minimal lines required to make the bug appear

vim.cmd [[
" vimscript goes in here if necessary
]]

Then edit the lines with comments so that they fit your requirements.

With this configuration, barbar can be loaded without Plug, which improves the chances of figuring out the one thing which is causing the problem.

The goal is:

  1. nvim --clean -u minimal.lua
  2. :edit a python file
  3. The bug occurs

You can start out pasting big blocks of your main config, and then reduce it until you're left with the smallest amount that still causes the bug to happen

Hopefully this helps!

Iron-E commented 5 months ago

Closing for now, feel free to reopen if there are any changes!