Skip to content

Commit ad26f36

Browse files
authored
Merge pull request #49 from editor-code-assistant/revert-async-server-download
Revert async server download
2 parents 9c90bad + fb4327d commit ad26f36

19 files changed

+156
-614
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-
behavior = {
24+
behaviour = {
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 = false,
32+
auto_start_server = true,
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-
behavior = { show_status_updates = false },
117+
behaviour = { 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-
behavior = { auto_focus_sidebar = true },
131+
behaviour = { 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-
behavior = {
152+
behaviour = {
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-
behavior = {
167+
behaviour = {
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-
behavior = {
56+
behaviour = {
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 `behavior.auto_set_keymaps = true`
39+
- Ensure `behaviour.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: `behavior.show_status_updates = false`
64+
- Disable visual updates: `behaviour.show_status_updates = false`
6565
- Use the minimalist configuration preset

lua/eca/api.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ 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-
1914
eca.open_sidebar(opts)
2015
end
2116

lua/eca/commands.lua

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -343,50 +343,6 @@ function M.setup()
343343
desc = "Emergency fix for treesitter issues in ECA chat",
344344
})
345345

346-
vim.api.nvim_create_user_command("EcaChatSelectModel", function()
347-
local eca = require("eca")
348-
349-
if not eca or not eca.current or not eca.current.sidebar then
350-
Logger.notify("No active ECA sidebar found", vim.log.levels.WARN)
351-
return
352-
end
353-
354-
local chat = eca.current.sidebar
355-
local models = chat.mediator:models()
356-
357-
vim.ui.select(models, {
358-
prompt = "Select ECA Chat Model:",
359-
}, function(choice)
360-
if choice then
361-
chat.mediator:update_selected_model(choice)
362-
end
363-
end)
364-
end, {
365-
desc = "Select current ECA Chat model",
366-
})
367-
368-
vim.api.nvim_create_user_command("EcaChatSelectBehavior", function()
369-
local eca = require("eca")
370-
371-
if not eca or not eca.current or not eca.current.sidebar then
372-
Logger.notify("No active ECA sidebar found", vim.log.levels.WARN)
373-
return
374-
end
375-
376-
local chat = eca.current.sidebar
377-
local behaviors = chat.mediator:behaviors()
378-
379-
vim.ui.select(behaviors, {
380-
prompt = "Select ECA Chat Behavior:",
381-
}, function(choice)
382-
if choice then
383-
chat.mediator:update_selected_behavior(choice)
384-
end
385-
end)
386-
end, {
387-
desc = "Select current ECA Chat behavior",
388-
})
389-
390346
Logger.debug("ECA commands registered")
391347
end
392348

lua/eca/config.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ M._defaults = {
2020
file = "",
2121
max_file_size_mb = 10, -- Maximum log file size in MB before warning
2222
},
23-
behavior = {
23+
behaviour = {
2424
auto_set_keymaps = true,
2525
auto_focus_sidebar = true,
26-
auto_start_server = false, -- Automatically start server on setup
26+
auto_start_server = true, -- Automatically start server on setup
2727
auto_download = true, -- Automatically download server if not found
2828
show_status_updates = true, -- Show status updates in notifications
2929
},

lua/eca/init.lua

Lines changed: 5 additions & 7 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.behavior and Config.behavior.auto_set_keymaps then
35+
if Config.behaviour.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" })
@@ -245,12 +245,10 @@ function M.setup(opts)
245245
M.state = require("eca.state").new()
246246
M.server = Server.new()
247247
M.mediator = require("eca.mediator").new(M.server, M.state)
248-
249-
if Config.behavior and Config.behavior.auto_start_server then
250-
vim.defer_fn(function()
251-
M.server:start()
252-
end, 100) -- Small delay to ensure everything is loaded
253-
end
248+
-- Start server automatically in background
249+
vim.defer_fn(function()
250+
M.server:start()
251+
end, 100) -- Small delay to ensure everything is loaded
254252

255253
M.did_setup = true
256254
end

lua/eca/mediator.lua

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,14 @@ function mediator:send(method, params, callback)
2626
self.server:send_request(method, params, callback)
2727
end
2828

29-
function mediator:behaviors()
30-
return self.state.config.behaviors.list
31-
end
32-
3329
function mediator:selected_behavior()
3430
return self.state.config.behaviors.selected
3531
end
3632

37-
function mediator:update_selected_behavior(behavior)
38-
self.state:update_selected_behavior(behavior)
39-
end
40-
41-
function mediator:models()
42-
return self.state.config.models.list
43-
end
44-
4533
function mediator:selected_model()
4634
return self.state.config.models.selected
4735
end
4836

49-
function mediator:update_selected_model(model)
50-
self.state:update_selected_model(model)
51-
end
52-
5337
function mediator:tokens_session()
5438
return self.state.usage.tokens.session
5539
end

lua/eca/path_finder.lua

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

56
---@class eca.PathFinder
@@ -99,7 +100,7 @@ function M:_write_version_file(version)
99100
file:write(version)
100101
file:close()
101102
else
102-
Logger.warn("Could not write version file: " .. self._version_file)
103+
Logger.notify("Could not write version file: " .. self._version_file, vim.log.levels.WARN)
103104
end
104105
end
105106

@@ -135,7 +136,7 @@ function M:_download_latest_server(server_path, version)
135136

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

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

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

150151
local download_result = os.execute(download_cmd)
151152
if download_result ~= 0 then
152-
error("Failed to download ECA server from: " .. download_url)
153+
Logger.notify("Failed to download ECA server from: " .. download_url, vim.log.levels.ERROR)
154+
return false
153155
end
154156

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

160162
local extract_result = os.execute(extract_cmd)
161163
if extract_result ~= 0 then
162-
error("Failed to extract ECA server")
164+
Logger.notify("Failed to extract ECA server", vim.log.levels.ERROR)
165+
return false
163166
end
164167

165168
-- Remove the zip file after extraction
166169
os.remove(download_path)
167170
end
168171

169172
-- Make executable (if not Windows)
170-
if not uv.os_uname().sysname:lower():match("windows") then
173+
if not vim.loop.os_uname().sysname:lower():match("windows") then
171174
os.execute("chmod +x " .. vim.fn.shellescape(server_path))
172175
end
173176

174177
if not Utils.file_exists(server_path) then
175-
error("ECA server binary not found after download and extraction")
178+
Logger.notify("ECA server binary not found after download and extraction", vim.log.levels.ERROR)
179+
return false
176180
end
177181

178182
-- Write version file
179183
self:_write_version_file(version)
180184

181-
Logger.debug("ECA server downloaded successfully")
182-
185+
Logger.notify("ECA server downloaded successfully", vim.log.levels.INFO)
183186
return true
184187
end
185188

186189
---@return string
187-
function M:find(custom_path)
190+
function M:find()
188191
-- Check for custom server path first
192+
local custom_path = Config.server_path
189193
if custom_path and custom_path:gsub("%s+", "") ~= "" then
190-
if not Utils.file_exists(custom_path) then
191-
error("Custom server path does not exist: " .. custom_path)
194+
if Utils.file_exists(custom_path) then
195+
Logger.debug("Using custom server path: " .. custom_path)
196+
return custom_path
197+
else
198+
Logger.notify("Custom server path does not exist: " .. custom_path, vim.log.levels.WARN)
192199
end
193-
return custom_path
194200
end
195201

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

216-
local success
217-
218-
local ok, err = pcall(function()
219-
success = self:_download_latest_server(server_path, latest_version)
220-
end)
221-
222-
if not ok or not success then
223-
error((err and tostring(err)) or "Failed to download ECA server")
222+
local success = self:_download_latest_server(server_path, latest_version)
223+
if not success then
224+
error("Failed to download ECA server")
224225
end
225226
end
226227

0 commit comments

Comments
 (0)