From 8127d140be3a3c85221830a26e3e86c794e5ccd0 Mon Sep 17 00:00:00 2001 From: linrongbin16 Date: Mon, 14 Aug 2023 10:18:20 +0800 Subject: [PATCH] fix: windows named pipe --- lua/fzfx/server.lua | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lua/fzfx/server.lua b/lua/fzfx/server.lua index cc3051bc6..a957f2864 100644 --- a/lua/fzfx/server.lua +++ b/lua/fzfx/server.lua @@ -34,23 +34,23 @@ function RpcRegistry:new(callback, user_context) end --- @return string|nil -local function get_pipe_name() - if constants.is_windows then - local result = vim.fn.trim( - string.format( - [[ \\.\pipe\nvim-pipe-%d-%d ]], - vim.fn.getpid(), - os.time() - ) - ) - log.debug( - "|fzfx.server - make_windows_pipe_name| result:%s", - vim.inspect(result) +local function get_windows_pipe_name() + log.ensure( + constants.is_windows, + "|fzfx.server - get_windows_pipe_name| error! must use this function in Windows!" + ) + local result = vim.fn.trim( + string.format( + [[ \\.\pipe\nvim-pipe-%d-%d ]], + vim.fn.getpid(), + os.time() ) - return result - else - return nil - end + ) + log.debug( + "|fzfx.server - make_windows_pipe_name| result:%s", + vim.inspect(result) + ) + return result end --- @class RpcServer @@ -64,7 +64,9 @@ local RpcServer = { --- @return RpcServer function RpcServer:new() --- @type string - local address = vim.fn.serverstart(get_pipe_name()) --[[@as string]] + local address = constants.is_windows + and vim.fn.serverstart(get_windows_pipe_name()) + or vim.fn.serverstart() --[[@as string]] log.debug( "|fzfx.server - RpcServer:new| start server on socket address:%s", vim.inspect(address)