refactor: add setup function to autoroot and lsp
This commit is contained in:
parent
7346c8991b
commit
f4f7326044
4 changed files with 37 additions and 23 deletions
2
init.lua
2
init.lua
|
@ -1,7 +1,7 @@
|
||||||
require("keymaps")
|
require("keymaps")
|
||||||
require("plugins")
|
require("plugins")
|
||||||
|
|
||||||
require("scripts.autoroot")
|
require("scripts.autoroot").setup()
|
||||||
|
|
||||||
vim.opt.relativenumber = true
|
vim.opt.relativenumber = true
|
||||||
vim.opt.number = true
|
vim.opt.number = true
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
return function()
|
local M = {}
|
||||||
|
|
||||||
|
M.setup = function()
|
||||||
local symbols = { Error = "", Info = "", Hint = "", Warn = "" }
|
local symbols = { Error = "", Info = "", Hint = "", Warn = "" }
|
||||||
|
|
||||||
for name, icon in pairs(symbols) do
|
for name, icon in pairs(symbols) do
|
||||||
|
@ -35,3 +37,5 @@ return function()
|
||||||
lspconfig.marksman.setup({})
|
lspconfig.marksman.setup({})
|
||||||
lspconfig.tinymist.setup({})
|
lspconfig.tinymist.setup({})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
|
@ -17,7 +17,7 @@ return {
|
||||||
{
|
{
|
||||||
"nvim-lspconfig",
|
"nvim-lspconfig",
|
||||||
event = "BufEnter",
|
event = "BufEnter",
|
||||||
after = require("lsp"),
|
after = require("lsp").setup,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"which-key.nvim",
|
"which-key.nvim",
|
||||||
|
|
|
@ -1,27 +1,37 @@
|
||||||
-- Array of file names indicating root directory. Modify to your liking.
|
local M = {}
|
||||||
local root_names = { '.git', 'Makefile', '.svn', '.hg' }
|
|
||||||
|
|
||||||
-- Cache to use for speed up (at cost of possibly outdated results)
|
M.setup = function()
|
||||||
local root_cache = {}
|
-- Array of file names indicating root directory. Modify to your liking.
|
||||||
|
local root_names = { ".git", "Makefile", ".svn", ".hg" }
|
||||||
|
|
||||||
local set_root = function()
|
-- Cache to use for speed up (at cost of possibly outdated results)
|
||||||
-- Get directory path to start search from
|
local root_cache = {}
|
||||||
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 set_root = function()
|
||||||
local root = root_cache[path]
|
-- Get directory path to start search from
|
||||||
if root == nil then
|
local path = vim.api.nvim_buf_get_name(0)
|
||||||
local root_file = vim.fs.find(root_names, { path = path, upward = true })[1]
|
if path == "" then
|
||||||
if root_file == nil then return end
|
return
|
||||||
root = vim.fs.dirname(root_file)
|
end
|
||||||
root_cache[path] = root
|
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
|
end
|
||||||
|
|
||||||
-- Set current directory
|
local root_augroup = vim.api.nvim_create_augroup("MyAutoRoot", {})
|
||||||
vim.fn.chdir(root)
|
vim.api.nvim_create_autocmd("BufEnter", { group = root_augroup, callback = set_root })
|
||||||
end
|
end
|
||||||
|
|
||||||
local root_augroup = vim.api.nvim_create_augroup('MyAutoRoot', {})
|
return M
|
||||||
vim.api.nvim_create_autocmd('BufEnter', { group = root_augroup, callback = set_root })
|
|
||||||
|
|
Loading…
Reference in a new issue