Skip to content

bug: the plugin directly sources .nvim.lua #44

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

Closed
1 of 3 tasks
ShiftyGames opened this issue Apr 5, 2025 · 8 comments
Closed
1 of 3 tasks

bug: the plugin directly sources .nvim.lua #44

ShiftyGames opened this issue Apr 5, 2025 · 8 comments
Labels
bug Something isn't working

Comments

@ShiftyGames
Copy link

ShiftyGames commented Apr 5, 2025

Neovim version (nvim -v)

NVIM v0.11.0

Error Message

Failed to run config for nvim-html-css

vim/_editor.lua:447: C:\Users\shifty\minimal.lua..nvim_exec2() called at C:\Users\shifty\minimal.lua:0, line 1: Vim:E492: Not an editor command: MyCommand echo hello

stacktrace:

  • vim_editor.lua:447 in cmd
  • .nvim.lua:3
  • minimal.lua:24

Steps To Reproduce

  1. echo 'vim.cmd [[MyCommand]]' > .nvim.lua
  2. nvim -u minimal.lua

Minimal Configuration

-- Paste your minimal init.lua or init.vim here
-- Only include what's necessary to reproduce the issue
-- Bootstrap Lazy
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
  local out = vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable",     -- latest stable release
    lazypath,
  })
  if vim.v.shell_error ~= 0 then
    vim.api.nvim_echo({
      { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
      { out,                            "WarningMsg" },
      { "\nPress any key to exit..." },
    }, true, {})
    vim.fn.getchar()
    os.exit(1)
  end
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  spec = {
    {
      "Jezda1337/nvim-html-css",
      dependencies = {
        "hrsh7th/nvim-cmp",
        "nvim-treesitter/nvim-treesitter",
      },
      opts = {},
    },
  },
})

-- neovim automatically sources './.nvim.lua' when exrc=true
-- nvim-html-css sources it forcibly too early.
vim.opt.exrc = false -- the error occurs for either value of exrc here

-- Everything below this line is actually in ~/.config/nvim/plugin/mycommand.lua
vim.api.nvim_create_user_command("MyCommand",
  function(opts)
    print("Hello MyCommand")
  end,
  {}
)

Related Plugins

  • nvim-cmp
  • blink.cmp
  • Other (please specify in Additional Information)

Additional Information

See :h 'exrc'
The .nvim.lua file is already sourced by neovim at a later time in the startup sequence and it only does so if the user has set exrc and the .nvim.lua file is in the trusted list. Your plugin should not be sourcing that file directly.

@ShiftyGames ShiftyGames added the bug Something isn't working label Apr 5, 2025
@Jezda1337
Copy link
Owner

exrc is disabled by default, so the plugin enables it and after that it reads the file if exist. Also I didn't encounter at any issue.
Any specific steps?

exrc.mov

@ShiftyGames
Copy link
Author

The error shows up immediately on my screen without any other actions. Perhaps this is a difference between 0.11 release and 0.12-dev?

@Jezda1337
Copy link
Owner

Here is the example with 0.11, but I notice that you using windows, I don't have win to test :/

exrc.mov

@ShiftyGames
Copy link
Author

Oh, I completely forgot to mention the contents of .nvim.lua!

-- .nvim.lua
vim.cmd [[MyCommand]]

@Jezda1337
Copy link
Owner

Thanks, I got the error:

Image

@Jezda1337
Copy link
Owner

Should be fixed, in case you still have an issue re-open this one.

@ShiftyGames
Copy link
Author

The fix doesn't seem quite right. Calling vim.cmd("runtime! plugin/**/*.{vim,lua}") looks out-of-place, that sort of thing is handled by neovim (or lazy.nvim) at a later step in the initialization process and will cause other issues if a user has other plugins that rely on other packages being initialized/setup. Those packages might not get loaded until after nvim-html-css.

Also, the bug I'm reporting is that 'the plugin directly sources .nvim.lua' instead of letting the regular neovim processes source the file. The file gets executed twice in total. I'm not sure what the fix is to get your plugin to work the way you want it to. Perhaps there's an event one could hook into that triggers after reading the .nvim.lua file.

@Jezda1337
Copy link
Owner

I agree, this was dirty hack, but the lazy doesn't actually wait for the all runtimes to start, so that was the reason why I have to manually source local .nvim.lua file. I will fix that dw

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

2 participants