Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ jobs:
sudo apt-get install lua-check -y --no-install-recommends
make check

- name: Check formatting
run: |
sudo apt-get install npm -y --no-install-recommends
sudo npm install -g @johnnymorganz/stylua-bin
make check-fmt
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ MINIMAL_INIT=tests/minimal_init.lua
TESTS_DIR=tests
NO_UTIL_SPEC=checks

.PHONY: test
.PHONY: test fmt check-fmt

test: ## Run the whole test suite
@nvim \
Expand All @@ -26,6 +26,12 @@ no-utils: ## Make sure there are no errant utils hanging around

pass: test no-utils check ## Run everything, if it's a 0 code, everything's good

fmt:
stylua lua/

check-fmt:
stylua --check lua/

help: ## Displays this information.
@printf '%s\n' "Usage: make <command>"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down
28 changes: 20 additions & 8 deletions lua/gptmodels/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,44 @@ function M.exec(args)

local handle, pid = uv.spawn(args.cmd, {
stdio = { stdin, stdout, stderr },
args = args.args
args = args.args,
}, function(code, signal) -- on exit
stdin:close()
stdout:close()
stderr:close()
done = true
if args.onexit then args.onexit(code, signal) end
if args.onexit then
args.onexit(code, signal)
end
end)

if args.onread then
uv.read_start(stdout, function(err, data) args.onread(err, data) end)
uv.read_start(stderr, function(_, err) args.onread(err, nil) end)
uv.read_start(stdout, function(err, data)
args.onread(err, data)
end)
uv.read_start(stderr, function(_, err)
args.onread(err, nil)
end)
end

if args.sync then
-- arbitrarily chosen, don't love that it's built in here
vim.wait(2 * 60 * 1000, function() return done end)
vim.wait(2 * 60 * 1000, function()
return done
end)
end

return {
handle = handle,
pid = pid,
done = function() return done end,
done = function()
return done
end,
die = function()
if not handle then return end
uv.process_kill(handle, 'sigterm')
if not handle then
return
end
uv.process_kill(handle, "sigterm")
-- Give it a moment to terminate gracefully
vim.defer_fn(function()
if not handle:is_closing() then
Expand Down
5 changes: 2 additions & 3 deletions lua/gptmodels/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local util = require('gptmodels.util')
local util = require("gptmodels.util")
local code_window = require("gptmodels.windows.code")
local chat_window = require("gptmodels.windows.chat")

Expand All @@ -25,14 +25,13 @@ end

---@param opts { visual_mode: boolean }
---@see file plugin/init.lua
M.chat = function (opts)
M.chat = function(opts)
if opts.visual_mode then
local selection = util.get_visual_selection()
chat_window.build_and_mount(selection)
else
chat_window.build_and_mount()
end

end

return M
9 changes: 4 additions & 5 deletions lua/gptmodels/llm.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-- This is meant to be a universally callable layer, which itself decides which llm to call
-- based on config or some state

require('gptmodels.types')
local Store = require('gptmodels.store')
require("gptmodels.types")
local Store = require("gptmodels.store")

local M = {}

--- Make request
---@param args MakeGenerateRequestArgs
---@return Job
M.generate = function(args)
local provider = require('gptmodels.providers.' .. Store:get_model().provider)
local provider = require("gptmodels.providers." .. Store:get_model().provider)
args.llm.model = Store:get_model().model
return provider.generate(args)
end
Expand All @@ -19,10 +19,9 @@ end
---@param args MakeChatRequestArgs
---@return Job
M.chat = function(args)
local provider = require('gptmodels.providers.' .. Store:get_model().provider)
local provider = require("gptmodels.providers." .. Store:get_model().provider)
args.llm.model = Store:get_model().model
return provider.chat(args)
end

return M

Loading