|
2 | 2 | local uv = vim.uv or vim.loop |
3 | 3 |
|
4 | 4 | local _is_win = vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1 |
| 5 | +local _is_linux = vim.fn.has("linux") == 1 |
5 | 6 |
|
6 | 7 | if vim.v.servername and #vim.v.servername > 0 then |
7 | 8 | pcall(vim.fn.serverstop, vim.v.servername) |
@@ -34,18 +35,27 @@ local function server_listen(server_socket, server_socket_path) |
34 | 35 | if tmpdir and #tmpdir > 0 then uv.fs_rmdir(tmpdir) end |
35 | 36 | end |
36 | 37 |
|
| 38 | + local finish = function() |
| 39 | + uv.close(receive_socket) |
| 40 | + uv.close(server_socket) |
| 41 | + -- on windows: ci fail when use uv.stop() |
| 42 | + -- on linux: zero event can freeze |
| 43 | + -- https://github.com/ibhagwan/fzf-lua/pull/1955#issuecomment-2785474217 |
| 44 | + -- uv.stop() |
| 45 | + os.exit(0) |
| 46 | + end |
| 47 | + |
| 48 | + if _is_linux then |
| 49 | + while true do |
| 50 | + local len = uv.fs_sendfile(1, receive_socket:fileno(), 0, 1024 * 1024) |
| 51 | + local eof = len == 0 |
| 52 | + if eof then finish() end |
| 53 | + end |
| 54 | + end |
| 55 | + |
37 | 56 | receive_socket:read_start(function(err, data) |
38 | 57 | assert(not err) |
39 | | - if not data then |
40 | | - uv.close(receive_socket) |
41 | | - uv.close(server_socket) |
42 | | - -- on windows: ci fail when use uv.stop() |
43 | | - -- on linux: zero event can freeze |
44 | | - -- https://github.com/ibhagwan/fzf-lua/pull/1955#issuecomment-2785474217 |
45 | | - -- uv.stop() |
46 | | - os.exit(0) |
47 | | - return |
48 | | - end |
| 58 | + if not data then finish() end |
49 | 59 | io.write(data) |
50 | 60 | end) |
51 | 61 | end) |
|
0 commit comments