Repository navigation
Async server download #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
cc8aaf4
e879e40
23acc02
1118ad9
47423e0
46e331a
895b674
1d46629
d837c4a
0356e45
4c59602
3ae5940
7be9782
ccca242
6a3cdad
59bf0f2
abffd15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,5 @@ | ||||||||||||||||
| local Utils = require("eca.utils") | ||||||||||||||||
| local Config = require("eca.config") | ||||||||||||||||
| local PathFinder = require("eca.path_finder") | ||||||||||||||||
| local Logger = require("eca.logger") | ||||||||||||||||
|
|
||||||||||||||||
| ---@class eca.Server | ||||||||||||||||
|
|
@@ -13,16 +12,17 @@ local Logger = require("eca.logger") | |||||||||||||||
| ---@field on_stop function Callback when the server stops | ||||||||||||||||
| ---Called when a notification is received(message without an ID) | ||||||||||||||||
| ---@field on_notification fun(server: eca.Server, message: table) | ||||||||||||||||
| ---@field private path_finder eca.PathFinder Server path finder | ||||||||||||||||
| ---@field pending_requests {id: fun(err, data)} -- outgoing requests with callbacks | ||||||||||||||||
| ---@field cwd string Current working directory for the server process | ||||||||||||||||
| ---@field workspace_folders {name: string, uri: string}[] Workspace folders to send on initialize | ||||||||||||||||
| local M = {} | ||||||||||||||||
|
|
||||||||||||||||
| ---@param opts? table | ||||||||||||||||
| ---@return eca.Server | ||||||||||||||||
| function M.new(opts) | ||||||||||||||||
| opts = vim.tbl_extend("keep", opts or {}, { | ||||||||||||||||
| on_start = function(pid) | ||||||||||||||||
| require("eca.logger").notify("Started server with pid " .. pid, vim.log.levels.INFO) | ||||||||||||||||
| require("eca.logger").debug("Started server with pid " .. pid) | ||||||||||||||||
| end, | ||||||||||||||||
| on_initialize = function() | ||||||||||||||||
| require("eca.logger").notify("Server ready to receive messages", vim.log.levels.INFO) | ||||||||||||||||
|
|
@@ -37,7 +37,13 @@ function M.new(opts) | |||||||||||||||
| require("eca.observer").notify(message) | ||||||||||||||||
| end) | ||||||||||||||||
| end, | ||||||||||||||||
| path_finder = PathFinder:new(), | ||||||||||||||||
| cwd = vim.fn.getcwd(), | ||||||||||||||||
| workspace_folders = { | ||||||||||||||||
| { | ||||||||||||||||
| name = vim.fn.fnamemodify(Utils.get_project_root(), ":t"), | ||||||||||||||||
| uri = "file://" .. Utils.get_project_root(), | ||||||||||||||||
| }, | ||||||||||||||||
| }, | ||||||||||||||||
| }) | ||||||||||||||||
|
|
||||||||||||||||
| return setmetatable({ | ||||||||||||||||
|
|
@@ -46,11 +52,12 @@ function M.new(opts) | |||||||||||||||
| on_initialize = opts.on_initialize, | ||||||||||||||||
| on_stop = opts.on_stop, | ||||||||||||||||
| on_notification = opts.on_notification, | ||||||||||||||||
| path_finder = opts.path_finder, | ||||||||||||||||
| messages = {}, | ||||||||||||||||
| pending_requests = {}, | ||||||||||||||||
| initialized = false, | ||||||||||||||||
| next_id = 0, | ||||||||||||||||
| cwd = opts.cwd, | ||||||||||||||||
| workspace_folders = opts.workspace_folders, | ||||||||||||||||
| }, { __index = M }) | ||||||||||||||||
| end | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -93,70 +100,79 @@ end | |||||||||||||||
| function M:start(opts) | ||||||||||||||||
| opts = opts or { initialize = true } | ||||||||||||||||
|
|
||||||||||||||||
| local server_path | ||||||||||||||||
| local ok, path_finder_error = pcall(function() | ||||||||||||||||
| server_path = self.path_finder:find() | ||||||||||||||||
| end) | ||||||||||||||||
| local this_file = debug.getinfo(1, "S").source:sub(2) | ||||||||||||||||
| local proj_root = vim.fn.fnamemodify(this_file, ":p:h:h:h") | ||||||||||||||||
| local script_path = proj_root .. "/scripts/server_path.lua" | ||||||||||||||||
|
|
||||||||||||||||
| if not ok or not server_path then | ||||||||||||||||
| Logger.notify("Could not find or download ECA server" .. tostring(path_finder_error), vim.log.levels.ERROR) | ||||||||||||||||
| return | ||||||||||||||||
| local nvim_exe = vim.fn.exepath("nvim") | ||||||||||||||||
|
|
||||||||||||||||
| if not nvim_exe or nvim_exe == "" then | ||||||||||||||||
| nvim_exe = "nvim" | ||||||||||||||||
| end | ||||||||||||||||
|
|
||||||||||||||||
| Logger.debug("Starting ECA server: " .. server_path) | ||||||||||||||||
| local lua_cmd = string.format("lua ServerPath.run(%s)", Config.server_path or "") | ||||||||||||||||
|
|
||||||||||||||||
|
||||||||||||||||
| local lua_cmd = string.format("lua ServerPath.run(%s)", Config.server_path or "") | |
| local function lua_quote(str) | |
| -- Escape backslashes and double quotes for Lua string literal | |
| return '"' .. tostring(str):gsub('\\', '\\\\'):gsub('"', '\\"') .. '"' | |
| end | |
| local lua_cmd = string.format("lua ServerPath.run(%s)", lua_quote(Config.server_path or "")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, I added this to utils.lua
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||
| local ServerPath = {} | ||||
|
|
||||
| -- Export module | ||||
| _G.ServerPath = ServerPath | ||||
|
|
||||
|
||||
| _G.ServerPath = ServerPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was moved to a condition that consider the --headless execution of neovim, it should make sense now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct use of 'uv' global may not be available in all Neovim versions. Consider using 'vim.uv' or 'vim.loop' for better compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uv is defined as
local uv = vim.uv or vim.loopin the first line of the file