lsp plugin config file will load but not modify current buffer until sourced

106 views Asked by At

For my Neovim setup I have a config folder under the lua folder that contains all of my plugin configs (lsp, tabline, telescope, etc.) as well as a print statement displaying what plugins were loaded successfully via the following which is invoked in /zfg/init.lua:

local plugins = {
    'pear',
    'harpoon',
    'lsp-zero',
    'treesitter',
    'undotree',
    'colors',
    'lualine',
    'snip',
    'tabline',
    'telescope',
    'tmux'
}

local imports = "Loaded: "

for i,plug in pairs(plugins) do
    _ = i
    if not pcall(require, 'zfg.config.'..plug) then
        print('Failed to load '..plug)
    else
        imports = imports.." "..plug
    end
end

print(imports)

My directory structure is as follows:

nvim/
| -- init.lua
| - lua/zfg/
|    | - config/
|    |    |-- pear.lua
|    |    |-- colors.lua
|    |    |-- harpoon.lua
|    |    |-- lsp-zero.lua
|    |    |-- lualine.lua
|    |    |-- snip.lua
|    |    |-- tabline.lua
|    |    |-- telescope.lua
|    |    |-- treesitter.lua
|    |    |-- undotree.lua
|    |-- init.lua
|-- init.lua

I can then check this message in :mes to verify that most all the require calls worked (or at least I think that's how that works) in addition to using the other plugins.

The main issue is that other plugins will modify my buffer as expected: I can invoke snippets, the pears.nvim will expand on enter and use the pairs correctly, and most everything else will work as far as I've been able to tell. The issue appears to only be lsp-zero in that none of my setup seems to take (no bordered window boxes with suggestions, autocompletion, or mappings).

I have added an additional source command to the /nvim/zfg/init.lua file in an attempt to force the file to be sourced but this also failed:

local src = ":so ~/.config/nvim/lua/zfg/config/lsp-zero.lua"

vim.api.nvim_command(src)

It will work correctly when I source nvim/zfg/init.lua manually after starting up neovim but it will not work on startup despite seeing the log messages making it look like the lsp-zero.lua file was loaded.

1

There are 1 answers

0
OmegaBumBum On BEST ANSWER

I managed to resolve this issue by changing my structure around slightly. I used the following directory configuration:

nvim/
|-- init.lua
| - lua/zfg/
|    | - config/
|    |    |-- pear.lua
|    |    |-- colors.lua
|    |    |-- harpoon.lua
|    |    |-- lualine.lua
|    |    |-- snip.lua
|    |    |-- tabline.lua
|    |    |-- telescope.lua
|    |    |-- treesitter.lua
|    |    |-- undotree.lua
|    |-- init.lua
| - after/plugin
|    |-- lsp-zero.lua

As far as I can tell this fixes the issue by loading the completion engine and LSP functionalities after everything under the lua directory and the plugins are loaded (if I'm understanding Neovim configuration correctly).