diff --git a/init.lua b/init.lua index 40ef6c3..6f6b9ee 100644 --- a/init.lua +++ b/init.lua @@ -1,7 +1,7 @@ require("keymaps") require("plugins") -require("scripts.autoroot") +require("scripts.autoroot").setup() vim.opt.relativenumber = true vim.opt.number = true diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index e1fdfee..8efe794 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -1,4 +1,6 @@ -return function() +local M = {} + +M.setup = function() local symbols = { Error = "󰅙", Info = "󰋼", Hint = "󰌵", Warn = "" } for name, icon in pairs(symbols) do @@ -35,3 +37,5 @@ return function() lspconfig.marksman.setup({}) lspconfig.tinymist.setup({}) end + +return M diff --git a/lua/plugins/lz-spec.lua b/lua/plugins/lz-spec.lua index 563863b..b77fd0f 100644 --- a/lua/plugins/lz-spec.lua +++ b/lua/plugins/lz-spec.lua @@ -17,7 +17,7 @@ return { { "nvim-lspconfig", event = "BufEnter", - after = require("lsp"), + after = require("lsp").setup, }, { "which-key.nvim", diff --git a/lua/scripts/autoroot.lua b/lua/scripts/autoroot.lua index 09e1212..293a5e0 100644 --- a/lua/scripts/autoroot.lua +++ b/lua/scripts/autoroot.lua @@ -1,27 +1,37 @@ --- Array of file names indicating root directory. Modify to your liking. -local root_names = { '.git', 'Makefile', '.svn', '.hg' } +local M = {} --- Cache to use for speed up (at cost of possibly outdated results) -local root_cache = {} +M.setup = function() + -- Array of file names indicating root directory. Modify to your liking. + local root_names = { ".git", "Makefile", ".svn", ".hg" } -local set_root = function() - -- Get directory path to start search from - local path = vim.api.nvim_buf_get_name(0) - if path == "" then return end - path = vim.fs.dirname(path) + -- Cache to use for speed up (at cost of possibly outdated results) + local root_cache = {} - -- Try cache and resort to searching upward for root directory - local root = root_cache[path] - if root == nil then - local root_file = vim.fs.find(root_names, { path = path, upward = true })[1] - if root_file == nil then return end - root = vim.fs.dirname(root_file) - root_cache[path] = root + local set_root = function() + -- Get directory path to start search from + local path = vim.api.nvim_buf_get_name(0) + if path == "" then + return + end + path = vim.fs.dirname(path) + + -- Try cache and resort to searching upward for root directory + local root = root_cache[path] + if root == nil then + local root_file = vim.fs.find(root_names, { path = path, upward = true })[1] + if root_file == nil then + return + end + root = vim.fs.dirname(root_file) + root_cache[path] = root + end + + -- Set current directory + vim.fn.chdir(root) end - -- Set current directory - vim.fn.chdir(root) + local root_augroup = vim.api.nvim_create_augroup("MyAutoRoot", {}) + vim.api.nvim_create_autocmd("BufEnter", { group = root_augroup, callback = set_root }) end -local root_augroup = vim.api.nvim_create_augroup('MyAutoRoot', {}) -vim.api.nvim_create_autocmd('BufEnter', { group = root_augroup, callback = set_root }) +return M