Skip to content

Commit 7be9782

Browse files
committed
add another test case for inexistent server path and other small fixes
1 parent 3ae5940 commit 7be9782

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

lua/eca/path_finder.lua

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,10 @@ end
187187
function M:find(custom_path)
188188
-- Check for custom server path first
189189
if custom_path and custom_path:gsub("%s+", "") ~= "" then
190-
if Utils.file_exists(custom_path) then
191-
Logger.debug("Using custom server path: " .. custom_path)
192-
return custom_path
193-
else
194-
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)
195192
end
193+
return custom_path
196194
end
197195

198196
local server_path = self:_get_extension_server_path()

lua/eca/server.lua

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

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

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

@@ -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

tests/test_server_integration.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,20 @@ T["server"]["start without initialize"] = function()
6363
eq(child.lua_get("_G.server.initialized"), false)
6464
end
6565

66+
T["server"]["start with inexistent path"] = function()
67+
child.lua([[
68+
Config = require("eca.config")
69+
Config.setup({ server_path = "non-existing-path" } )
70+
_G.server:start()
71+
]])
72+
child.lua([[
73+
_G.server_started = vim.wait(1000, function()
74+
return _G.server and _G.server:is_running()
75+
end, 100)
76+
]])
77+
eq(string.find(child.lua_get("_G.notifications[1].message"), "non-existing-path", 1 , true) ~= nil, true)
78+
eq(child.lua_get("_G.server_started"), false)
79+
eq(child.lua_get("_G.server.initialized"), false)
80+
end
81+
6682
return T

0 commit comments

Comments
 (0)