Skip to content

Commit f201bf1

Browse files
committed
Rework message handling logic.
The current implementation handles server messages in various different places. The sidebar does a lot of it. There are also many levels of `send_message`, `send_request`, `send_chat_message`-type methods that all do kind-of the same thing and (IMO) redundant and confusing. - add `.deps` to gitignore. - remove `deps` from git history - remove the `EcaServerStatus` command and the corresponding server status functionality. I don't think it adds anything and makes the server more complex. We could always add it back in. - remove `rpc.lua`, all of that functionality lives in `server.lua` now. - remove `eca.status_bar` - schedule some functions when we are in a fast event context, used in logging and in UI functions that change the state of a buffer, for example - server has `on_start`, `on_initialized`, `on_stop` callbacks - `server:stop()` sends a `shutdown` and `exit` request to ECA, or sends SIGTERM - `server:start()` uses `vim.system` instead of `jobstart` and `chan_send` - all message handling is done in `server.on_stdout()` which can delegate to other handlers - pathfinder can be injected into the server constructor - `message_handler.lua` parses incoming message from the server - `handle_content` still calls out to sidebar but that will be refactored out later - add tests
1 parent 49074d5 commit f201bf1

File tree

12 files changed

+712
-895
lines changed

12 files changed

+712
-895
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
deps/
1+
deps/
2+
.eca/

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ require("eca").setup({
168168
| `:EcaServerStart` | Starts ECA server manually | `:EcaServerStart` |
169169
| `:EcaServerStop` | Stops ECA server | `:EcaServerStop` |
170170
| `:EcaServerRestart` | Restarts ECA server | `:EcaServerRestart` |
171-
| `:EcaServerStatus` | Shows detailed server status | `:EcaServerStatus` |
172171
| `:EcaSend <message>` | Sends message directly | `:EcaSend Explain this function` |
173172

174173
## ⌨️ Keyboard Shortcuts
@@ -459,9 +458,6 @@ Consider readability and maintainability.
459458
#### Server Management
460459

461460
```vim
462-
" Check status
463-
:EcaServerStatus
464-
465461
" Restart if there are issues
466462
:EcaServerRestart
467463
@@ -515,7 +511,6 @@ Consider readability and maintainability.
515511

516512
- Check if `curl` and `unzip` are installed
517513
- Try setting `server_path` manually with absolute path
518-
- Run `:EcaServerStatus` for diagnostics
519514
- Check logs with `debug = true` in configuration
520515
- Try `:EcaServerRestart`
521516

lua/eca/commands.lua

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -157,34 +157,6 @@ function M.setup()
157157
desc = "Restart ECA server",
158158
})
159159

160-
vim.api.nvim_create_user_command("EcaServerStatus", function()
161-
local eca = require("eca")
162-
local status = eca.server and eca.server:status() or "Not initialized"
163-
local status_icon = ""
164-
165-
if status == "Running" then
166-
status_icon = ""
167-
elseif status == "Starting" then
168-
status_icon = ""
169-
elseif status == "Failed" then
170-
status_icon = ""
171-
end
172-
173-
Logger.notify("ECA Server Status: " .. status .. " " .. status_icon, vim.log.levels.INFO)
174-
175-
-- Also show path info if available
176-
if eca.server and eca.server._path_finder then
177-
local config = require("eca.config")
178-
if config.server_path and config.server_path ~= "" then
179-
Logger.notify("Server path: " .. config.server_path .. " (custom)", vim.log.levels.INFO)
180-
else
181-
Logger.notify("Server path: auto-detected/downloaded", vim.log.levels.INFO)
182-
end
183-
end
184-
end, {
185-
desc = "Show ECA server status with details",
186-
})
187-
188160
vim.api.nvim_create_user_command("EcaLogs", function(opts)
189161
local Api = require("eca.api")
190162
local subcommand = opts.args and opts.args:match("%S+") or "show"
@@ -293,8 +265,6 @@ function M.setup()
293265
desc = "Emergency stop for infinite loops or runaway responses",
294266
})
295267

296-
297-
298268
vim.api.nvim_create_user_command("EcaFixTreesitter", function()
299269
local Utils = require("eca.utils")
300270

lua/eca/init.lua

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ local Logger = require("eca.logger")
66
local Sidebar = require("eca.sidebar")
77
local Config = require("eca.config")
88
local Server = require("eca.server")
9-
local StatusBar = require("eca.status_bar")
109

1110
---@class Eca
1211
local M = {
@@ -16,8 +15,6 @@ local M = {
1615
current = { sidebar = nil },
1716
---@type eca.Server
1817
server = nil,
19-
---@type eca.StatusBar
20-
status_bar = nil,
2118
}
2219

2320
M.did_setup = false
@@ -245,23 +242,9 @@ function M.setup(opts)
245242
H.signs()
246243

247244
-- Initialize status bar
248-
M.status_bar = StatusBar:new()
249245

250246
-- Initialize the ECA server with callbacks
251-
M.server = Server:new({
252-
on_started = function(connection)
253-
M.status_bar:update("Running")
254-
Logger.debug("ECA server started and ready!")
255-
end,
256-
on_status_changed = function(status)
257-
M.status_bar:update(status)
258-
if status == "Failed" then
259-
Logger.notify("ECA server failed to start. Check :messages for details.", vim.log.levels.ERROR)
260-
elseif status == "Starting" then
261-
Logger.debug("Starting ECA server...")
262-
end
263-
end,
264-
})
247+
M.server = Server.new()
265248

266249
-- Start server automatically in background
267250
vim.defer_fn(function()

lua/eca/logger.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ end
8989
---@param message string
9090
---@param level integer
9191
function M.log(message, level)
92+
if vim.in_fast_event() then
93+
return vim.schedule(function()
94+
M.log(message, level)
95+
end)
96+
end
97+
9298
if not M.config then
9399
return
94100
end
@@ -98,6 +104,7 @@ function M.log(message, level)
98104
end
99105

100106
local log_path = M.get_log_path()
107+
101108
vim.fn.mkdir(vim.fn.fnamemodify(log_path, ":h"), "p")
102109

103110
local timestamp = os.date("%Y-%m-%d %H:%M:%S")

lua/eca/message_handler.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
local M = {}
2+
3+
--- Parse raw messages coming from the ECA server
4+
---@param data string
5+
---@return {content_length: integer, content: string}[]
6+
function M.parse_raw_messages(data)
7+
local messages = {}
8+
local seek_head = 1
9+
while true do
10+
local first, last, capture = string.find(data, "Content%-Length: (%d+)[\r\n]+", seek_head)
11+
if not first then
12+
break
13+
end
14+
capture = tonumber(capture)
15+
seek_head = last + capture
16+
table.insert(messages, { content_length = capture, content = string.sub(data, last + 1, seek_head) })
17+
end
18+
return messages
19+
end
20+
21+
return M

lua/eca/rpc.lua

Lines changed: 0 additions & 186 deletions
This file was deleted.

0 commit comments

Comments
 (0)