Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Invalid buffer id #317

Closed
2 tasks done
zeitchef opened this issue Feb 1, 2025 · 4 comments
Closed
2 tasks done

bug: Invalid buffer id #317

zeitchef opened this issue Feb 1, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@zeitchef
Copy link

zeitchef commented Feb 1, 2025

Neovim version (nvim -v)

0.10.4

Neovim distribution

n/a

Operating system

macOS

Terminal emulator / GUI

Ghostty

Describe the bug

After the last commit, I'm getting an error when the plugin loads:

Error executing vim.schedule lua callback: ...azy/render-markdown.nvim/lua/render-markdown/manager.lua:112: Invalid buffer id: 1
stack traceback:
        [C]: in function 'get'
        ...azy/render-markdown.nvim/lua/render-markdown/manager.lua:112: in function 'should_attach'
        ...azy/render-markdown.nvim/lua/render-markdown/manager.lua:70: in function 'attach'
        ...azy/render-markdown.nvim/lua/render-markdown/manager.lua:63: in function <...azy/render-markdown.nvim/lua/render-markdown/manager.lua:62>
Image

Expected behavior

There should be no error

Healthcheck output

==============================================================================
render-markdown: require("render-markdown.health").check()

render-markdown.nvim [version] ~
- OK plugin 7.8.13
- OK neovim >= 0.10

render-markdown.nvim [configuration] ~
- OK valid

render-markdown.nvim [nvim-treesitter] ~
- OK installed
- OK markdown: parser installed
- OK markdown: highlight enabled
- OK markdown_inline: parser installed
- OK markdown_inline: highlight enabled

render-markdown.nvim [icons] ~
- OK using: mini.icons

render-markdown.nvim [executables] ~
- OK none to check

render-markdown.nvim [conflicts] ~
- OK headlines: not installed
- ERROR obsidian: installed
  - ADVICE:
    - Ensure UI is disabled by setting ui = { enable = false } in obsidian.nvim config

Plugin configuration

return {
	'MeanderingProgrammer/render-markdown.nvim',
	ft = { 'markdown', 'Avante' },
	opts = {
		file_types = { 'markdown', 'Avante' },
		latex = {
			enabled = false,
		},
		heading = {
			enabled = false,
		},
		bullet = {
			right_pad = 1,
			-- icons = { '-' },
		},
		link = {
			enabled = false,
		},
		checkbox = {
			custom = {
				progress = {
					raw = '[/]',
					rendered = '',
					highlight = 'RenderMarkdownBullet',
					scope_highlight = nil,
				},
			},
		},
	},
}

Plugin error log

n/a

Confirmations

  • I have updated this plugin to the latest version using my plugin manager
  • I have provided the text contained in all screenshots as raw text in this issue. This means if there is a screenshot below it is the copy pasted contents of the file in the screenshot. I understand that my issue will be closed if I have not.

Additional information

No response

@zeitchef zeitchef added the bug Something isn't working label Feb 1, 2025
@V4G4X
Copy link

V4G4X commented Feb 1, 2025

I am also getting this, but I do NOT get it every time. (Like opening a clean session).
I get it only when I open an existing session.

My first theory was that it conflicted with auto-sessions.

But the following mini repro config didn't reproduce the issue for me:

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
    spec = {
        {
            'MeanderingProgrammer/render-markdown.nvim',
            dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, -- if you prefer nvim-web-devicons
            ---@module 'render-markdown'
            ---@type render.md.UserConfig
            opts = {},
        },
        {
            'rmagatti/auto-session',
            lazy = false,

            ---enables autocomplete for opts
            ---@module "auto-session"
            ---@type AutoSession.Config
            opts = {
                suppressed_dirs = { '~/', '~/Projects', '~/Downloads', '/' },
                -- log_level = 'debug',
            }
        },
    },
})

Any ideas?

@hoarse-boy
Copy link

what i have found, if i give some delay before opening old session it will not show the error. for now i use lazy.nvim and use the previous tag of v7.7.0

@guoliang
Copy link

guoliang commented Feb 1, 2025

getting this issue too when it loads a session

MeanderingProgrammer added a commit that referenced this issue Feb 2, 2025
## Details

Related issues:

- #309
- #315
- #317

Okay this is getting convoluted to handle the differences in lazy
loading between `lazy.nvim` and `vim-plug`. The issues are as follows:

- `lazy.nvim` & Lazy Loaded: Attempting to attach to current buffer at
  the start will not pickup user configuration (called from plugin
  directory before setup) so may not listen to all needed events. This
  means we should not attach to current buffer and rely on the
  `FileType` auto command.
- `vim-plug` & Lazy Loaded: The initial load swallows the `FileType`
  event for the current buffer (`lazy.nvim` seems to trigger the event)
  so first buffer will be ignored. This means we cannot rely on the
  `FileType` auto command and need to attach to the current buffer.

To fix this we need to be aware of the plugin manager being used so we
can do the right thing, which sucks, but oh well.

The solution expands on our existing logic to hook into `lazy.nvim`
configuration for this plugin. When the user has NOT configured lazy
loading (via filetypes nor commands) we attempt to attach to the current
buffer. This means if they have we will skip attaching and will rely on
the `FileType` event.

This solves the `lazy.nvim` problem of not using the updated user
configuration. This does mean when not lazy loading with `lazy.nvim` we
will attempt to attach to the current buffer. This will initially fail
since the filetype will not be set for the buffer but will succeed for
the buffer later once the `FileType` event is triggered.

For `vim-plug` we don't have any hooks so no matter what it will look
like we are NOT lazy loading. This means we will attempt to attach to
the current buffer fixing the issue of lazy loading with `vim-plug`.

Have also added a check that buffer is valid in the `should_attach`
function. The issue related to this should be fixed from the other
updates but having it in place seems like a good idea in either case.
@MeanderingProgrammer
Copy link
Owner

Thanks for the report, should be resolved by: 4645c18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants