p00f / clangd_extensions.nvim

Clangd's off-spec features for neovim's LSP client. Use https://sr.ht/~p00f/clangd_extensions.nvim instead
MIT License
495 stars 18 forks source link

plugin commands not created automatically #46

Closed mraveloarinjaka closed 1 year ago

mraveloarinjaka commented 1 year ago

I haven't switch my neovim configuration to lua entirely and I am using https://github.com/junegunn/vim-plug to load my plugins. The file plugin/clangd_extensions.lua containing the various commands created by the plugin is not read during the initialization. And I believe that neovim is only automatically loading a lua file if it is under a lua directory in its runtime path. What about moving those commands to a dedicated file (e.g. lua/clangd_extensions/commands.lua) and, similar to what is done for inlay hints, have the user explicitly requiring that file if needed? I can submit a PR if you think that the idea is worth implementing.

p00f commented 1 year ago

The file plugin/clangd_extensions.lua containing the various commands created by the plugin is not read during the initialization.

I don't think that's possible, what neovim version are you on?

What about moving those commands to a dedicated file (e.g. lua/clangd_extensions/commands.lua) and, similar to what is done for inlay hints, have the user explicitly requiring that file if needed?

No, if this is because your neovim version is too old I'll try writing that file in vimscript instead

mraveloarinjaka commented 1 year ago

according to the splash screen my neovim version is 0.9.1: is it an old one?

mraveloarinjaka commented 1 year ago

That being said, as I said in my initial comment, I have not entirely switched to a Lua config. I am using an init.vim that sources my Lua configuration; I am using vim-plug to source the plugins and populate the runtime path.

mraveloarinjaka commented 1 year ago

No, if this is because your neovim version is too old I'll try writing that file in vimscript instead

I believe it was a vimscript before. If you are open to switch back to a vim file we can keep the lua code by enclosing it in a heredoc.

p00f commented 1 year ago

according to the splash screen my neovim version is 0.9.1: is it an old one?

No, this is recent enough

That being said, as I said in my initial comment, I have not entirely switched to a Lua config. I am using an init.vim that sources my Lua configuration; I am using vim-plug to source the plugins and populate the runtime path.

That shouldn't be a problem

I believe it was a vimscript before.

It wasn't anything before, there was nothing in plugin/. The commands were defined somewhere else

Your issue is something else entirely, can you provide a minimal init.vim to reproduce? See :h $NVIM_APPNAME

mraveloarinjaka commented 1 year ago

Here is a sample configuration: https://github.com/mraveloarinjaka/sandbox_neovim_configuration. You should call "PlugInstall" to install the plugins.

mraveloarinjaka commented 1 year ago

For your information you can check below my runtimepath when I load a c file. The clangd_extensions.nvim directory is present. { "C:\\Users\\mraveloarinjaka\\AppData\\Local\\direnv\\sandbox-nvim", "C:\\Users\\mraveloarinjaka\\AppData\\Local\\direnv\\sandbox-nvim\\plugged\\nvim-lspconfig", "C:\\Users\\mraveloarinjaka\\AppData\\Local\\direnv\\sandbox-nvim\\plugged\\clangd_extensions.nvim", "D:\\apps\\scoop\\apps\\neovim\\current\\share\\nvim\\runtime", "D:\\apps\\scoop\\apps\\neovim\\current\\share\\nvim\\runtime\\pack\\dist\\opt\\matchit", "D:\\apps\\scoop\\apps\\neovim\\current\\lib\\nvim" }

p00f commented 1 year ago

Can you try removing {'for': ['c', 'cpp']} from the vim-plug configuration? Might have something to do with the load order - plugin/clangd_extensions.lua only defines commands, and does not load any other file so the startuptime cost is negligible

I'll try out your minimal init.vim sometime tomorrow

mraveloarinjaka commented 1 year ago

Actually that was it! I guess there is a flaw in the way the lazy loading is implemented on vim-plug side

mraveloarinjaka commented 1 year ago

may be the following line https://github.com/junegunn/vim-plug/blob/master/plug.vim#L663 is not enough to lazy load a plugin

p00f commented 1 year ago

It's already lazy loaded (lua folder is like vimscript autoload, only loaded when explicitly called), you don't need to do anything