Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MunifTanjim
Last active August 24, 2022 16:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MunifTanjim/7a34aa247cbabdec50f4de45fffdf53e to your computer and use it in GitHub Desktop.
Save MunifTanjim/7a34aa247cbabdec50f4de45fffdf53e to your computer and use it in GitHub Desktop.
Neovim - Project Local Config with exrc.nvim
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)
--[[ 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",
},
})
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