Skip to content

Commit

Permalink
feat(nvim): try to minimize effect on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed May 18, 2022
1 parent 4abadd6 commit bf13348
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions lua/xbase/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
local M = {}
local config = require "xbase.config"
local lib = require "libxbase"

vim.g.xbase = {
---@type Project[]
Expand All @@ -25,8 +23,8 @@ end

--- Register current neovim client
M.register = function()
local _ = lib.ensure()
lib.register { address = vim.env.NVIM_LISTEN_ADDRESS }
local _ = require("libxbase").ensure()
require("libxbase").register { address = vim.env.NVIM_LISTEN_ADDRESS }
end

---Tries to register vim instance as client for xbase server.
Expand All @@ -41,42 +39,44 @@ M.try_register = function(root, opts)
end

M.drop = function(remove_client)
lib.drop { remove_client = remove_client }
require("libxbase").drop { remove_client = remove_client }
end

M.build = function(opts)
lib.build(opts)
require("libxbase").build(opts)
end

M.run = function(opts)
lib.run(opts)
require("libxbase").run(opts)
end

M.watch = function(opts)
lib.watch_target(opts)
require("libxbase").watch_target(opts)
end

---Setup xbase for current instance.
---Should ran once per neovim instance
---@param opts xbaseOptions
---@overload fun()
M.setup = function(opts)
local root = vim.loop.cwd()
opts = opts or {}
-- Mutate xbase configuration
config.set(opts)
-- Try to register current vim instance
-- NOTE: Should this register again on cwd change?
M.try_register(root, opts)
vim.schedule(function()
opts = opts or {}
local root = vim.loop.cwd()
-- Mutate xbase configuration
require("xbase.config").set(opts)
-- Try to register current vim instance
-- NOTE: Should this register again on cwd change?
M.try_register(root, opts)

vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
pattern = { "*.m", "*.swift", "*.c" },
callback = function()
vim.keymap.set("n", "<leader>ef", require("xbase.pickers").actions, { buffer = true })
end,
})
-- so that on a new buffer it would work
vim.keymap.set("n", "<leader>ef", require("xbase.pickers").actions, { buffer = true })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
pattern = { "*.m", "*.swift", "*.c" },
callback = function()
vim.keymap.set("n", "<leader>ef", require("xbase.pickers").actions, { buffer = true })
end,
})
-- so that on a new buffer it would work
vim.keymap.set("n", "<leader>ef", require("xbase.pickers").actions, { buffer = true })
end)
end

return M

0 comments on commit bf13348

Please sign in to comment.