Skip to content

Commit

Permalink
Setting up extrenals opts
Browse files Browse the repository at this point in the history
  • Loading branch information
luxluth committed Mar 28, 2024
1 parent e7ed229 commit bef6be3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
26 changes: 12 additions & 14 deletions lua/oz.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@
local engine = require("oz.engine")
local utils = require("oz.utils")

---@class Config
local config = {
opt = {
ozengine_path = "ozengine",
show_compiler_output = true,
linter = false,
keymap = "<C-r>",
},
---@class Options
local opts = {
ozengine_path = "ozengine",
show_compiler_output = true,
linter = false,
keymap = "<C-r>",
}

---@class OzNvim
local M = {}

---@type Config
M.config = config
---@type Options
M.opts = opts

---@param args Config?
---@param args Options?
-- you can define your setup function here. Usually configurations can be merged, accepting outside params and
-- you can also put some validation here for those.
function M.setup(args)
M.config = vim.tbl_deep_extend("force", M.config, args or {})
M.opts = vim.tbl_deep_extend("force", M.opts, args or {})
end

function M.engine_path()
engine.path(M.config.opt.ozengine_path)
return M.config.opt.ozengine_path
engine.path(M.opts.ozengine_path)
return M.opts.ozengine_path
end

---@param bufnr integer
Expand Down
2 changes: 1 addition & 1 deletion lua/oz/engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end
---Start the ozengine server
---@param instance OzNvim
function EC:start(instance)
local command = { instance.config.opt.ozengine_path, "x-oz://system/OPI.ozf" }
local command = { instance.opts.ozengine_path, "x-oz://system/OPI.ozf" }
if self.server.pid == nil then
self.server.pid = vim.fn.jobstart(command, {
---@param data string
Expand Down
2 changes: 1 addition & 1 deletion plugin/oz.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ vim.api.nvim_create_autocmd({ "BufEnter" }, {
oz.restart_engine()
end, {})

vim.keymap.set("v", oz.config.opt.keymap, function()
vim.keymap.set("v", oz.opts.keymap, function()
oz.feed_selection(args.buf)
end, { desc = "Feed the current selection into the oz engine" })
end,
Expand Down
2 changes: 1 addition & 1 deletion tests/oz/oz_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("setup", function()
end)

it("works with custom var", function()
plugin.setup({ opt = { ozengine_path = "notapath" } })
plugin.setup({ ozengine_path = "notapath" })
assert(plugin.engine_path() == "notapath", "getting a custom ozenginepath")
end)
end)

0 comments on commit bef6be3

Please sign in to comment.