Last active
August 24, 2022 16:23
Neovim - Project Local Config with exrc.nvim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("config.lsp.custom").patch_lsp_settings("sumneko_lua", function(settings) | |
settings.Lua.diagnostics.globals = { "hs", "spoon" } | |
settings.Lua.workspace.library = {} | |
local hammerspoon_emmpylua_annotations = vim.fn.expand("~/.config/hammerspoon/Spoons/EmmyLua.spoon/annotations") | |
if vim.fn.isdirectory(hammerspoon_emmpylua_annotations) == 1 then | |
table.insert(settings.Lua.workspace.library, hammerspoon_emmpylua_annotations) | |
end | |
return settings | |
end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ Modify your Neovim config file ]] | |
local cwd = vim.fn.getcwd(-1, -1) | |
if cwd == '/path/to/project-a' then | |
-- config for project-a | |
elseif cwd = '/path/to/project-b' then | |
-- config for project-b | |
end | |
----------------- | |
--[[ Built-in Option: `exrc` ]] | |
vim.o.exrc = true | |
vim.o.secure = true | |
----------------- | |
--[[ Plugin: `exrc.nvim` ]] | |
vim.o.exrc = false | |
require("exrc").setup({ | |
files = { | |
".nvimrc.lua", | |
".nvimrc", | |
".exrc.lua", | |
".exrc", | |
}, | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local mod = {} | |
---@param server_name string | |
---@param settings_patcher fun(settings: table): table | |
function mod.patch_lsp_settings(server_name, settings_patcher) | |
local function patch_settings(client) | |
client.config.settings = settings_patcher(client.config.settings) | |
client.notify("workspace/didChangeConfiguration", { | |
settings = client.config.settings, | |
}) | |
end | |
local clients = vim.lsp.get_active_clients({ name = server_name }) | |
if #clients > 0 then | |
patch_settings(clients[1]) | |
return | |
end | |
vim.api.nvim_create_autocmd("LspAttach", { | |
callback = function(args) | |
local client = vim.lsp.get_client_by_id(args.data.client_id) | |
if client.name == server_name then | |
patch_settings(client) | |
return true | |
end | |
end, | |
}) | |
end | |
return mod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment