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
12 changes: 6 additions & 6 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ require("eca").setup({
usage_string_format = "{messageCost} / {sessionCost}",

-- === BEHAVIOR ===
behaviour = {
behavior = {
-- Set keymaps automatically
auto_set_keymaps = true,

-- Focus sidebar automatically when opening
auto_focus_sidebar = true,

-- Start server automatically
auto_start_server = true,
auto_start_server = false,

-- Download server automatically if not found
auto_download = true,
Expand Down Expand Up @@ -114,7 +114,7 @@ require("eca").setup({
### Minimalist
```lua
require("eca").setup({
behaviour = { show_status_updates = false },
behavior = { show_status_updates = false },
windows = { width = 30 },
chat = {
headers = {
Expand All @@ -128,7 +128,7 @@ require("eca").setup({
### Visual/UX focused
```lua
require("eca").setup({
behaviour = { auto_focus_sidebar = true },
behavior = { auto_focus_sidebar = true },
windows = {
width = 50,
wrap = true,
Expand All @@ -149,7 +149,7 @@ require("eca").setup({
require("eca").setup({
debug = true,
server_args = "--log-level debug",
behaviour = {
behavior = {
auto_start_server = true,
show_status_updates = true,
},
Expand All @@ -164,7 +164,7 @@ require("eca").setup({
### Performance-oriented
```lua
require("eca").setup({
behaviour = {
behavior = {
auto_focus_sidebar = false,
show_status_updates = false,
},
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Advanced setup example:
opts = {
debug = false,
server_path = "",
behaviour = {
behavior = {
auto_set_keymaps = true,
auto_focus_sidebar = true,
},
Expand Down
4 changes: 2 additions & 2 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Solutions:
Symptoms: `<leader>ec` doesn't open chat

Solutions:
- Ensure `behaviour.auto_set_keymaps = true`
- Ensure `behavior.auto_set_keymaps = true`
- Confirm your `<leader>` key (default: `\`)
- Configure shortcuts manually:

Expand All @@ -61,5 +61,5 @@ Symptoms: Lag when typing, slow responses

Solutions:
- Reduce window width: `windows.width = 25`
- Disable visual updates: `behaviour.show_status_updates = false`
- Disable visual updates: `behavior.show_status_updates = false`
- Use the minimalist configuration preset
5 changes: 5 additions & 0 deletions lua/eca/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ local M = {}
function M.chat(opts)
opts = opts or {}
local eca = require("eca")

if not M.is_server_running() then
M.start_server()
end

eca.open_sidebar(opts)
end

Expand Down
4 changes: 2 additions & 2 deletions lua/eca/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ M._defaults = {
file = "",
max_file_size_mb = 10, -- Maximum log file size in MB before warning
},
behaviour = {
behavior = {
auto_set_keymaps = true,
auto_focus_sidebar = true,
auto_start_server = true, -- Automatically start server on setup
auto_start_server = false, -- Automatically start server on setup
auto_download = true, -- Automatically download server if not found
show_status_updates = true, -- Show status updates in notifications
},
Expand Down
12 changes: 7 additions & 5 deletions lua/eca/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function H.keymaps()
require("eca.api").focus()
end, { noremap = true })

if Config.behaviour.auto_set_keymaps then
if Config.behavior and Config.behavior.auto_set_keymaps then
Utils.safe_keymap_set({ "n", "v" }, Config.mappings.chat, function()
require("eca.api").chat()
end, { desc = "eca: open chat" })
Expand Down Expand Up @@ -245,10 +245,12 @@ function M.setup(opts)
M.state = require("eca.state").new()
M.server = Server.new()
M.mediator = require("eca.mediator").new(M.server, M.state)
-- Start server automatically in background
vim.defer_fn(function()
M.server:start()
end, 100) -- Small delay to ensure everything is loaded

if Config.behavior and Config.behavior.auto_start_server then
vim.defer_fn(function()
M.server:start()
end, 100) -- Small delay to ensure everything is loaded
end

M.did_setup = true
end
Expand Down
43 changes: 21 additions & 22 deletions lua/eca/path_finder.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local uv = vim.uv or vim.loop
local Utils = require("eca.utils")
local Config = require("eca.config")
local Logger = require("eca.logger")

---@class eca.PathFinder
Expand Down Expand Up @@ -100,7 +99,7 @@ function M:_write_version_file(version)
file:write(version)
file:close()
else
Logger.notify("Could not write version file: " .. self._version_file, vim.log.levels.WARN)
Logger.warn("Could not write version file: " .. self._version_file)
end
end

Expand Down Expand Up @@ -136,7 +135,7 @@ function M:_download_latest_server(server_path, version)

local download_path = self._cache_dir .. "/" .. artifact_name

Logger.notify("Downloading latest ECA server version from: " .. download_url, vim.log.levels.INFO)
Logger.debug("Downloading latest ECA server version from: " .. download_url)

-- Ensure cache directory exists
vim.fn.mkdir(self._cache_dir, "p")
Expand All @@ -150,8 +149,7 @@ function M:_download_latest_server(server_path, version)

local download_result = os.execute(download_cmd)
if download_result ~= 0 then
Logger.notify("Failed to download ECA server from: " .. download_url, vim.log.levels.ERROR)
return false
error("Failed to download ECA server from: " .. download_url)
end

-- Extract if it's a zip file
Expand All @@ -161,42 +159,38 @@ function M:_download_latest_server(server_path, version)

local extract_result = os.execute(extract_cmd)
if extract_result ~= 0 then
Logger.notify("Failed to extract ECA server", vim.log.levels.ERROR)
return false
error("Failed to extract ECA server")
end

-- Remove the zip file after extraction
os.remove(download_path)
end

-- Make executable (if not Windows)
if not vim.loop.os_uname().sysname:lower():match("windows") then
if not uv.os_uname().sysname:lower():match("windows") then
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct use of 'uv' global may not be available in all Neovim versions. Consider using 'vim.uv' or 'vim.loop' for better compatibility.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uv is defined as local uv = vim.uv or vim.loop in the first line of the file

os.execute("chmod +x " .. vim.fn.shellescape(server_path))
end

if not Utils.file_exists(server_path) then
Logger.notify("ECA server binary not found after download and extraction", vim.log.levels.ERROR)
return false
error("ECA server binary not found after download and extraction")
end

-- Write version file
self:_write_version_file(version)

Logger.notify("ECA server downloaded successfully", vim.log.levels.INFO)
Logger.debug("ECA server downloaded successfully")

return true
end

---@return string
function M:find()
function M:find(custom_path)
-- Check for custom server path first
local custom_path = Config.server_path
if custom_path and custom_path:gsub("%s+", "") ~= "" then
if Utils.file_exists(custom_path) then
Logger.debug("Using custom server path: " .. custom_path)
return custom_path
else
Logger.notify("Custom server path does not exist: " .. custom_path, vim.log.levels.WARN)
if not Utils.file_exists(custom_path) then
error("Custom server path does not exist: " .. custom_path)
end
return custom_path
end

local server_path = self:_get_extension_server_path()
Expand All @@ -215,13 +209,18 @@ function M:find()
-- Download if server doesn't exist or version is outdated
if not server_exists or (latest_version and current_version ~= latest_version) then
if not latest_version then
Logger.notify("Could not check for latest version, using existing server", vim.log.levels.WARN)
Logger.warn("Could not check for latest version, using existing server")
return server_path
end

local success = self:_download_latest_server(server_path, latest_version)
if not success then
error("Failed to download ECA server")
local success

local ok, err = pcall(function()
success = self:_download_latest_server(server_path, latest_version)
end)

if not ok or not success then
error((err and tostring(err)) or "Failed to download ECA server")
end
end

Expand Down
Loading
Loading