forked from Davidyz/VectorCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
40 lines (38 loc) · 2.23 KB
/
Copy pathinit.lua
File metadata and controls
40 lines (38 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local utils = require("vectorcode.utils")
--- A class for calling vectorcode commands that aims at providing a unified API for both LSP and command-line backend.
--- Implementations exist for both direct command-line execution (`cmd.lua`) and LSP (`lsp.lua`).
--- For the format of the `result`, see https://github.com/Davidyz/VectorCode/blob/main/docs/cli.md#for-developers
---@class VectorCode.JobRunner
--- Runs a vectorcode command asynchronously.
--- Executes the command specified by `args`. Upon completion, if `callback` is provided,
--- it's invoked with the result table (decoded JSON from stdout) and error table (stderr lines).
--- The `bufnr` is used for context, potentially to find the project root or attach LSP clients.
--- Returns a job handle (e.g., PID or LSP request ID) or nil if the job couldn't be started.
---@field run_async fun(args: string[], callback:fun(result: table, error: table)?, bufnr: integer):(job_handle:integer?)
--- Runs a vectorcode command synchronously, blocking until completion or timeout.
--- Executes the command specified by `args`. Waits for up to `timeout_ms` milliseconds.
--- The `bufnr` is used for context, potentially to find the project root or attach LSP clients.
--- Returns the result table (decoded JSON from stdout) and error table (stderr lines).
---@field run fun(args: string[], timeout_ms: integer?, bufnr: integer):(result:table, error:table)
--- Checks if a job associated with the given handle is currently running.
--- Returns true if the job is running, false otherwise.
---@field is_job_running fun(job_handle: integer):boolean
--- Attempts to stop or cancel the job associated with the given handle.
---@field stop_job fun(job_handle: integer)
--- Optional initialization function. Some runners (like LSP) might require an initialization step.
---@field init function?
return {
--- Automatically find project_root from buffer path if it's not already specified.
---@param args string[]
---@param bufnr integer
---@return string[]
find_root = function(args, bufnr)
if not vim.list_contains(args, "--project_root") then
local find_root = utils.find_root(bufnr)
if find_root then
vim.list_extend(args, { "--project_root", find_root })
end
end
return args
end,
}