Skip to content

Commit dc066c4

Browse files
committed
Merge branch 'async-server-download' into select-model-and-behavior
2 parents 50b5c90 + 59bf0f2 commit dc066c4

File tree

14 files changed

+153
-88
lines changed

14 files changed

+153
-88
lines changed

docs/configuration.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ require("eca").setup({
2121
usage_string_format = "{messageCost} / {sessionCost}",
2222

2323
-- === BEHAVIOR ===
24-
behaviour = {
24+
behavior = {
2525
-- Set keymaps automatically
2626
auto_set_keymaps = true,
2727

2828
-- Focus sidebar automatically when opening
2929
auto_focus_sidebar = true,
3030

3131
-- Start server automatically
32-
auto_start_server = true,
32+
auto_start_server = false,
3333

3434
-- Download server automatically if not found
3535
auto_download = true,
@@ -114,7 +114,7 @@ require("eca").setup({
114114
### Minimalist
115115
```lua
116116
require("eca").setup({
117-
behaviour = { show_status_updates = false },
117+
behavior = { show_status_updates = false },
118118
windows = { width = 30 },
119119
chat = {
120120
headers = {
@@ -128,7 +128,7 @@ require("eca").setup({
128128
### Visual/UX focused
129129
```lua
130130
require("eca").setup({
131-
behaviour = { auto_focus_sidebar = true },
131+
behavior = { auto_focus_sidebar = true },
132132
windows = {
133133
width = 50,
134134
wrap = true,
@@ -149,7 +149,7 @@ require("eca").setup({
149149
require("eca").setup({
150150
debug = true,
151151
server_args = "--log-level debug",
152-
behaviour = {
152+
behavior = {
153153
auto_start_server = true,
154154
show_status_updates = true,
155155
},
@@ -164,7 +164,7 @@ require("eca").setup({
164164
### Performance-oriented
165165
```lua
166166
require("eca").setup({
167-
behaviour = {
167+
behavior = {
168168
auto_focus_sidebar = false,
169169
show_status_updates = false,
170170
},

docs/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Advanced setup example:
5353
opts = {
5454
debug = false,
5555
server_path = "",
56-
behaviour = {
56+
behavior = {
5757
auto_set_keymaps = true,
5858
auto_focus_sidebar = true,
5959
},

docs/troubleshooting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Solutions:
3636
Symptoms: `<leader>ec` doesn't open chat
3737

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

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

6262
Solutions:
6363
- Reduce window width: `windows.width = 25`
64-
- Disable visual updates: `behaviour.show_status_updates = false`
64+
- Disable visual updates: `behavior.show_status_updates = false`
6565
- Use the minimalist configuration preset

lua/eca/api.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ local M = {}
1111
function M.chat(opts)
1212
opts = opts or {}
1313
local eca = require("eca")
14+
15+
if not M.is_server_running() then
16+
M.start_server()
17+
end
18+
1419
eca.open_sidebar(opts)
1520
end
1621

lua/eca/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ M._defaults = {
2020
file = "",
2121
max_file_size_mb = 10, -- Maximum log file size in MB before warning
2222
},
23-
behaviour = {
23+
behavior = {
2424
auto_set_keymaps = true,
2525
auto_focus_sidebar = true,
2626
auto_start_server = false, -- Automatically start server on setup

lua/eca/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function H.keymaps()
3232
require("eca.api").focus()
3333
end, { noremap = true })
3434

35-
if Config.behaviour.auto_set_keymaps then
35+
if Config.behavior and Config.behavior.auto_set_keymaps then
3636
Utils.safe_keymap_set({ "n", "v" }, Config.mappings.chat, function()
3737
require("eca.api").chat()
3838
end, { desc = "eca: open chat" })
@@ -246,7 +246,7 @@ function M.setup(opts)
246246
M.server = Server.new()
247247
M.mediator = require("eca.mediator").new(M.server, M.state)
248248

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

lua/eca/path_finder.lua

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local uv = vim.uv or vim.loop
22
local Utils = require("eca.utils")
3-
local Config = require("eca.config")
43
local Logger = require("eca.logger")
54

65
---@class eca.PathFinder
@@ -188,12 +187,10 @@ end
188187
function M:find(custom_path)
189188
-- Check for custom server path first
190189
if custom_path and custom_path:gsub("%s+", "") ~= "" then
191-
if Utils.file_exists(custom_path) then
192-
Logger.debug("Using custom server path: " .. custom_path)
193-
return custom_path
194-
else
195-
Logger.notify("Custom server path does not exist: " .. custom_path, vim.log.levels.WARN)
190+
if not Utils.file_exists(custom_path) then
191+
error("Custom server path does not exist: " .. custom_path)
196192
end
193+
return custom_path
197194
end
198195

199196
local server_path = self:_get_extension_server_path()

lua/eca/server.lua

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ function M:start(opts)
110110
nvim_exe = "nvim"
111111
end
112112

113-
local lua_cmd = string.format("lua ServerPath.run(%s)", Config.server_path or "")
113+
local lua_cmd = string.format("lua ServerPath.run(%s)", Utils.lua_quote(Config.server_path or ""))
114114

115-
local cmd = { nvim_exe, "--headless", "--noplugin", "-u", script_path, "-c", lua_cmd }
115+
local cmd = { nvim_exe, "--headless", "--noplugin", "--clean", "-u", script_path, "-c", lua_cmd }
116116

117117
vim.system(cmd, { text = true }, function(out)
118118
if out.code ~= 0 then
@@ -253,12 +253,6 @@ end
253253
---@param params table
254254
---@param callback? function
255255
function M:send_request(method, params, callback)
256-
if not self:is_running() then
257-
Logger.error("ECA server is not running")
258-
if callback then
259-
callback("Server not running", nil)
260-
end
261-
end
262256
local id = self:get_next_id()
263257
local message = {
264258
jsonrpc = "2.0",
@@ -272,6 +266,15 @@ function M:send_request(method, params, callback)
272266

273267
local json = vim.json.encode(message)
274268
table.insert(self.messages, { content = json, content_length = #json })
269+
270+
if not self:is_running() then
271+
Logger.error("ECA server is not running")
272+
if callback then
273+
callback("Server not running", nil)
274+
end
275+
return
276+
end
277+
275278
local content = string.format("Content-Length: %d\r\n\r\n%s", #json, json)
276279
self.process:write(content)
277280
end

lua/eca/sidebar.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ function M:_update_welcome_content()
12231223
local cfg_msg = (cfg.message and cfg.message ~= "" and cfg.message) or nil
12241224
local welcome_message = cfg_msg or (self.mediator and self.mediator:welcome_message() or nil)
12251225

1226-
local lines = { "Waiting for welcome message from ECA server..." }
1226+
local lines = { "Waiting for server to start..." }
12271227

12281228
if welcome_message and welcome_message ~= "" then
12291229
lines = Utils.split_lines(welcome_message)

lua/eca/utils.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,11 @@ function M.constants()
118118
return CONSTANTS
119119
end
120120

121+
---@param str string
122+
---@return string
123+
function M.lua_quote(str)
124+
-- Escape backslashes and double quotes for Lua string literal
125+
return '"' .. tostring(str):gsub('\\', '\\\\'):gsub('"', '\\"') .. '"'
126+
end
127+
121128
return M

0 commit comments

Comments
 (0)