Skip to content

Commit 1118ad9

Browse files
committed
make server path call as lua command
1 parent 23acc02 commit 1118ad9

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

lua/eca/server.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ end
100100
function M:start(opts)
101101
opts = opts or { initialize = true }
102102

103-
local custom_path = Config.server_path or ""
104-
105103
local this_file = debug.getinfo(1, "S").source:sub(2)
106104
local proj_root = vim.fn.fnamemodify(this_file, ":p:h:h:h")
107105
local script_path = proj_root .. "/scripts/server_path.lua"
@@ -112,7 +110,9 @@ function M:start(opts)
112110
nvim_exe = "nvim"
113111
end
114112

115-
local cmd = { nvim_exe, "-l", script_path, custom_path }
113+
local lua_cmd = string.format("lua ServerPath.run(%s)", Config.server_path or "")
114+
115+
local cmd = { nvim_exe, "--headless", "--noplugin", "-u", script_path, "-c", lua_cmd }
116116

117117
vim.system(cmd, { text = true }, function(out)
118118
if out.code ~= 0 then

scripts/server_path.lua

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
local PathFinder = require("eca.path_finder")
1+
local ServerPath = {}
22

3-
local custom_path = _G.arg[1] or ""
4-
local path_finder = PathFinder:new()
5-
local path
3+
-- Export module
4+
_G.ServerPath = ServerPath
65

7-
local ok, err = pcall(function()
8-
path = path_finder:find(custom_path)
9-
end)
6+
ServerPath.run = function(custom_path)
7+
local path_finder = require("eca.path_finder"):new()
8+
local path
109

11-
if not ok then
12-
io.stderr:write(tostring(err))
13-
os.exit(1)
10+
local ok, err = pcall(function()
11+
path = path_finder:find(custom_path)
12+
end)
13+
14+
if not ok then
15+
io.stderr:write(tostring(err))
16+
os.exit(1)
17+
end
18+
19+
io.stdout:write(tostring(path))
20+
os.exit(0)
1421
end
1522

16-
io.stdout:write(path)
23+
return ServerPath

0 commit comments

Comments
 (0)