Skip to content

Commit f2c2e8a

Browse files
committed
figured out how to do typechecks, etc..
1 parent d246c52 commit f2c2e8a

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

.luarc.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
3-
"runtime": {
4-
"version": "LuaJIT"
5-
},
6-
"workspace": {
7-
"library": [
8-
"${3rd}/luv/library",
9-
"${3rd}/busted/library",
10-
"${3rd}/luassert/library",
11-
"${3rd}/plenary.nvim/lua"
12-
],
13-
"checkThirdParty": false,
14-
"maxPreload": 2000,
15-
"preloadFileSize": 1000
16-
},
17-
"diagnostics": {
18-
"globals": [
19-
"vim"
20-
]
21-
}
2+
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
3+
"runtime": {
4+
"version": "LuaJIT"
5+
},
6+
"workspace": {
7+
"#comment": "no globbing, see https://luals.github.io/wiki/settings/#workspacelibrary",
8+
"library": [
9+
"./lua",
10+
"./deps/nui.nvim/lua/",
11+
"./deps/plenary.nvim/lua/"
12+
],
13+
"checkThirdParty": false,
14+
"maxPreload": 2000,
15+
"preloadFileSize": 1000
16+
},
17+
"diagnostics": {
18+
"globals": [
19+
"vim"
20+
]
21+
}
2222
}

lua/magenta/anthropic.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ local default_config = {
2222
}
2323

2424
---@param config? table
25-
---@return table
25+
---@return AnthropicClient
2626
function Client.new(config)
2727
local opts = vim.tbl_deep_extend("force", default_config, config or {})
2828

@@ -54,7 +54,7 @@ function Client:get_api_key()
5454
end
5555

5656
---@class AnthropicRequestActions
57-
---@field callback fun(err: nil|string, chunk: nil|table) Callback function for request completion
57+
---@field callback fun(err: nil|string, chunk: nil|string) Callback function for request completion
5858
---@field done? fun() Function to run when request is complete
5959
---@field on_stream? fun(chunk: string) Function to handle streaming chunks
6060

lua/magenta/init.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
local log = require('magenta.log').log
1+
local log = require('magenta.log').log;
22

33
local M = {}
44

55
---@class Config
66
---@field sidebar_width number Width of the sidebar
77
---@field position string Position of the sidebar ("left" or "right")
88
---@field anthropic table Configuration for the Anthropic client
9-
-- Default configuration
109
local default_config = {
1110
sidebar_width = 80,
1211
position = "left",
@@ -17,24 +16,23 @@ local default_config = {
1716
}
1817
}
1918

20-
-- Store the user's configuration
21-
M.config = {}
19+
M.config = vim.tbl_deep_extend("force", default_config, {})
20+
2221

23-
-- Store the sidebar instance and components
2422
local sidebar = nil
2523
local input_area = nil
2624
local main_area = nil
25+
26+
---@type AnthropicClient
2727
local anthropic_client = nil
2828

2929
-- Initialize the plugin with user config
3030
function M.setup(opts)
3131
log.debug("Setting up magenta with opts:", opts)
3232
M.config = vim.tbl_deep_extend("force", default_config, opts or {})
3333

34-
-- Initialize Anthropic client
3534
anthropic_client = require("magenta.anthropic").new(M.config.anthropic)
3635

37-
-- Safely require nui components
3836
local ok, err = pcall(function()
3937
-- Try to load all required nui components
4038
local Layout = require("nui.layout")
@@ -156,8 +154,10 @@ function M.send_message()
156154
return
157155
end
158156

159-
log.debug("Received stream text:", text)
160-
append_to_main({ text = text })
157+
if text then
158+
log.debug("Received stream text:", text)
159+
append_to_main({ text = text })
160+
end
161161
end,
162162
done = function()
163163
log.debug("Request completed")

lua/magenta/log.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local M = {}
22

3-
M.log = require('plenary.log').new({
3+
local plenary_log = require('plenary.log')
4+
M.log = plenary_log.new({
45
plugin = 'magenta',
56
level = "trace",
67
})

tests/minimal_init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ local function ensure_deps()
66
if vim.fn.isdirectory(deps_path) == 0 then
77
vim.fn.mkdir(deps_path, "p")
88
end
9-
9+
1010
local deps = {
1111
["plenary.nvim"] = "https://github.com/nvim-lua/plenary.nvim",
1212
["nui.nvim"] = "https://github.com/MunifTanjim/nui.nvim"
1313
}
14-
14+
1515
for name, url in pairs(deps) do
1616
local dep_path = deps_path .. "/" .. name
1717
if vim.fn.isdirectory(dep_path) == 0 then

0 commit comments

Comments
 (0)