3

I decided to spring-clean and update my nvim config files/plugins, and thought I’d make proper use of the after/plug folder. While setting up LSP (with mason, mason-lspconfig, and lspconfig), I wanted to move all the lsp language server settings out from after/plugin/lsp/init.lua to their own files (now in after/plugin/lsp/settings).

The problem is I don’t seem to be able to require them into the init.lua file.

Things I’ve tried to no avail:

require(‘after/plugin/lsp/settings/sumneko_lua.lua’)
require(vim.fn.stdpath("config") .. "/after/plugin/lsp/settings/sumneko_lua”)
require(vim.fn.expand('%:h').. ‘/settings/sumneko_lua’)

The attempt using expand works when I resource the file in nvim; but causes an error when starting nvim.

I understand that all the files in after/plugin are automagically sourced at startup. So if I had a file shared.lua:

local M = {}                                                                              
                                                                                         
function M.greet()                                                                        
  vim.notify("Hello!”)
end

return M

in the same folder as after/plugin/lsp/init.lua, how can I get access to the greet() function from init.lua?

Any pointers would be greatly appreciated.

1 Answer 1

1

It turned out to be quite a simple solution in the end: I simply updated the paths to be searched in init.lua

-- nvim/init.lua
-- Allow require to look in after/plugin folder

local home_dir = os.getenv("HOME")
package.path = home_dir .. "/.config/nvim/after/plugin/?.lua;" .. package.path

And then I can require any file inside the after/plugin folder

e.g - require("lsp/settings/sumneko") or require("lsp/shared").greet()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.