Skip to content

Commit 799e1fe

Browse files
committed
Merge branch 'main' into feat/db_layer
2 parents c59136b + 171361e commit 799e1fe

File tree

15 files changed

+161
-83
lines changed

15 files changed

+161
-83
lines changed

.github/FUNDING.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12+
polar: # Replace with a single Polar username
13+
buy_me_a_coffee: davidyz # Replace with a single Buy Me a Coffee username
14+
thanks_dev: # Replace with a single thanks.dev username
15+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and integrations for some of the popular plugins.
2121
* [About Versioning](#about-versioning)
2222
* [TODOs](#todos)
2323
* [Credit](#credit)
24+
* [Special Thanks](#special-thanks)
2425
* [Star History](#star-history)
2526

2627
<!-- mtoc-end -->
@@ -111,6 +112,9 @@ This project follows an adapted semantic versioning:
111112
- The nix community (especially [@sarahec](https://github.com/sarahec) and [@GaetanLepage](https://github.com/GaetanLepage))
112113
for maintaining the nix packages.
113114

115+
### Special Thanks
116+
[![JetBrains logo.](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg)](https://jb.gg/OpenSource)
117+
114118
## Star History
115119

116120
[![Star History Chart](https://api.star-history.com/svg?repos=Davidyz/VectorCode&type=Date)](https://www.star-history.com/#Davidyz/VectorCode&Date)

lua/vectorcode/cacher/default.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---@type VectorCode.CacheBackend
22
local M = {}
3+
4+
local utils = require("vectorcode.utils")
35
local vc_config = require("vectorcode.config")
46
local notify_opts = vc_config.notify_opts
57
local jobrunner = require("vectorcode.jobrunner.cmd")
@@ -54,7 +56,7 @@ local function async_runner(query_message, buf_nr)
5456
local project_root = cache.options.project_root
5557
if project_root ~= nil then
5658
assert(
57-
vim.uv.fs_stat(vim.fs.normalize(project_root)).type == "directory",
59+
utils.is_directory(project_root),
5860
("%s is not a valid directory!"):format(project_root)
5961
)
6062
vim.list_extend(args, { "--project_root", project_root })

lua/vectorcode/cacher/init.lua

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,37 @@ return {
1818
return
1919
end
2020
check_item = check_item or "config"
21-
jobrunner.run_async({ "check", check_item }, function(result, error, code, signal)
22-
local out = {
23-
stdout = table.concat(vim.iter(result):flatten(math.huge):totable()),
24-
stderr = table.concat(vim.iter(error):flatten(math.huge):totable()),
25-
code = code,
26-
signal = signal,
27-
}
28-
if out.code == 0 and type(on_success) == "function" then
29-
vim.schedule_wrap(on_success)(out)
30-
elseif out.code ~= 0 and type(on_failure) == "function" then
31-
vim.schedule_wrap(on_failure)(out)
32-
end
33-
end, 0)
21+
jobrunner.run_async(
22+
{ "check", check_item },
23+
function(result, _error, code, signal)
24+
local out_msg = nil
25+
if type(result) == "table" and #result > 0 then
26+
out_msg = table.concat(vim.iter(result):flatten(math.huge):totable())
27+
elseif type(result) == "string" then
28+
out_msg = result
29+
end
30+
31+
local err_msg = nil
32+
if type(_error) == "table" and #_error > 0 then
33+
err_msg = table.concat(vim.iter(_error):flatten(math.huge):totable())
34+
elseif type(_error) == "string" then
35+
out_msg = _error
36+
end
37+
38+
local out = {
39+
stdout = out_msg,
40+
stderr = err_msg,
41+
code = code,
42+
signal = signal,
43+
}
44+
if out.code == 0 and type(on_success) == "function" then
45+
vim.schedule_wrap(on_success)(out)
46+
elseif out.code ~= 0 and type(on_failure) == "function" then
47+
vim.schedule_wrap(on_failure)(out)
48+
end
49+
end,
50+
0
51+
)
3452
end,
3553
},
3654
}

lua/vectorcode/init.lua

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

33
local vc_config = require("vectorcode.config")
4+
local utils = require("vectorcode.utils")
45
local logger = vc_config.logger
56
local get_config = vc_config.get_user_config
67
local notify_opts = vc_config.notify_opts
@@ -60,7 +61,7 @@ M.query = vc_config.check_cli_wrap(
6061
else
6162
jobrunner.run_async(args, function(result, error)
6263
logger.debug(result)
63-
callback(result)
64+
callback(result or {})
6465
if error then
6566
logger.warn(vim.inspect(error))
6667
end
@@ -148,10 +149,7 @@ M.vectorise = vc_config.check_cli_wrap(
148149
M.update = vc_config.check_cli_wrap(function(project_root)
149150
logger.info("vectorcode.update: ", project_root)
150151
local args = { "update" }
151-
if
152-
type(project_root) == "string"
153-
and vim.uv.fs_stat(vim.fs.normalize(project_root)).type == "directory"
154-
then
152+
if project_root ~= nil and utils.is_directory(project_root) then
155153
vim.list_extend(args, { "--project_root", project_root })
156154
end
157155
logger.debug("vectorcode.update cmd args: ", args)
@@ -191,8 +189,8 @@ function M.check(check_item, stdout_cb)
191189
return_code = code
192190
if type(stdout_cb) == "function" then
193191
stdout_cb({
194-
stdout = table.concat(vim.iter(result):flatten(math.huge):totable()),
195-
stderr = table.concat(vim.iter(error):flatten(math.huge):totable()),
192+
stdout = utils.flatten_table_to_string(result),
193+
stderr = utils.flatten_table_to_string(error, "Unknown error."),
196194
code = code,
197195
signal = signal,
198196
})

lua/vectorcode/integrations/codecompanion/common.lua

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,17 @@ local TOOL_RESULT_SOURCE = "VectorCodeToolResult"
1010
return {
1111
tool_result_source = TOOL_RESULT_SOURCE,
1212

13-
---@param t table|string
13+
---@param t table|string|nil
1414
---@return string
1515
flatten_table_to_string = function(t)
16-
if type(t) == "string" then
17-
return t
18-
end
19-
20-
-- Handle empty tables or tables with empty strings
21-
local flattened = vim
22-
.iter(t)
23-
:flatten(math.huge)
24-
:filter(function(item)
25-
return type(item) == "string" and vim.trim(item) ~= ""
26-
end)
27-
:totable()
28-
29-
if #flattened == 0 then
30-
return "Unknown error occurred"
31-
end
32-
33-
return table.concat(flattened, "\n")
16+
vim.deprecate(
17+
"vectorcode.integrations.codecompanion.common.flatten_table_to_string",
18+
"vectorcode.utils.flatten_table_to_string",
19+
"1.0.0",
20+
"vectorcode",
21+
true
22+
)
23+
return require("vectorcode.utils").flatten_table_to_string(t)
3424
end,
3525

3626
---@param use_lsp boolean

lua/vectorcode/integrations/codecompanion/files_ls_tool.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
local cc_common = require("vectorcode.integrations.codecompanion.common")
44
local vc_config = require("vectorcode.config")
5+
local utils = require("vectorcode.utils")
56

67
local default_opts = {
78
use_lsp = vc_config.get_user_config().async_backend == "lsp",
@@ -27,13 +28,13 @@ return function(opts)
2728
---@return nil|{ status: string, data: string }
2829
function(tools, action, _, cb)
2930
local args = { "files", "ls", "--pipe" }
31+
action = utils.fix_nil(action)
3032
if action ~= nil then
3133
action.project_root = action.project_root
3234
or vim.fs.root(0, { ".vectorcode", ".git" })
3335
if action.project_root ~= nil then
3436
action.project_root = vim.fs.normalize(action.project_root)
35-
local stat = vim.uv.fs_stat(action.project_root)
36-
if stat and stat.type == "directory" then
37+
if utils.is_directory(action.project_root) then
3738
vim.list_extend(args, { "--project_root", action.project_root })
3839
end
3940
end
@@ -43,7 +44,7 @@ return function(opts)
4344
cb({ status = "success", data = result })
4445
else
4546
if type(error) == "table" then
46-
error = cc_common.flatten_table_to_string(error)
47+
error = utils.flatten_table_to_string(error, "Unknown error.")
4748
end
4849
cb({
4950
status = "error",

lua/vectorcode/integrations/codecompanion/files_rm_tool.lua

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
local cc_common = require("vectorcode.integrations.codecompanion.common")
44
local vc_config = require("vectorcode.config")
5+
local utils = require("vectorcode.utils")
56

67
local default_opts = {
78
use_lsp = vc_config.get_user_config().async_backend == "lsp",
@@ -57,10 +58,10 @@ The value should be one of the following:
5758
---@return nil|{ status: string, data: string }
5859
function(tools, action, _, cb)
5960
local args = { "files", "rm", "--pipe" }
61+
action = utils.fix_nil(action)
6062
if action.project_root then
6163
local project_root = vim.fs.abspath(vim.fs.normalize(action.project_root))
62-
local stat = vim.uv.fs_stat(project_root)
63-
if stat and stat.type == "directory" then
64+
if utils.is_directory(project_root) then
6465
vim.list_extend(args, { "--project_root", project_root })
6566
else
6667
return { status = "error", data = "Invalid path " .. project_root }
@@ -76,12 +77,7 @@ The value should be one of the following:
7677
:filter(
7778
---@param item string
7879
function(item)
79-
local stat = vim.uv.fs_stat(item)
80-
if stat and stat.type == "file" then
81-
return true
82-
else
83-
return false
84-
end
80+
return utils.is_file(item)
8581
end
8682
)
8783
:totable()
@@ -90,7 +86,7 @@ The value should be one of the following:
9086
args,
9187
---@param result VectoriseResult
9288
function(result, error, code, _)
93-
if result then
89+
if code == 0 then
9490
cb({ status = "success", data = result })
9591
else
9692
cb({ status = "error", data = { error = error, code = code } })

lua/vectorcode/integrations/codecompanion/ls_tool.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---@module "codecompanion"
22

3-
local cc_common = require("vectorcode.integrations.codecompanion.common")
43
local vc_config = require("vectorcode.config")
4+
local utils = require("vectorcode.utils")
55
local logger = vc_config.logger
66

77
---@type VectorCode.CodeCompanion.LsToolOpts
@@ -45,7 +45,7 @@ return function(opts)
4545
cb({ status = "success", data = result })
4646
else
4747
if type(error) == "table" then
48-
error = cc_common.flatten_table_to_string(error)
48+
error = utils.flatten_table_to_string(error, "Unknown error.")
4949
end
5050
cb({
5151
status = "error",

lua/vectorcode/integrations/codecompanion/prompts/init.lua

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ function M.register_prompt(opts)
6868

6969
assert(type(opts.name) == "string", "`name` cannot be `nil`.")
7070

71-
local cc_common = require("vectorcode.integrations.codecompanion.common")
7271
local constants = require("codecompanion.config").config.constants
7372
local prompts = {}
7473

@@ -132,14 +131,12 @@ Here's my question:
132131
vc_config.notify_opts
133132
)
134133
elseif err ~= nil then
135-
err = cc_common.flatten_table_to_string(err)
136-
if err ~= "" then
137-
vim.schedule_wrap(vim.notify)(
138-
err,
139-
vim.log.levels.WARN,
140-
vc_config.notify_opts
141-
)
142-
end
134+
err = utils.flatten_table_to_string(err, "Unknown error.")
135+
vim.schedule_wrap(vim.notify)(
136+
err,
137+
vim.log.levels.WARN,
138+
vc_config.notify_opts
139+
)
143140
end
144141
end
145142
)

0 commit comments

Comments
 (0)