Coder Social home page Coder Social logo

Comments (5)

pogyomo avatar pogyomo commented on September 22, 2024 1

@mfussenegger I just try it with #28507 and found vim.lsp.rpc.connect works correctly so that vim.lsp.get_clients returns client infomation.

from neovim.

TheLeoP avatar TheLeoP commented on September 22, 2024

This may be related to this regression. Maybe the problem isn't only with named pipes, but with windows being slower in general to connect to named pipes and TCP.

The problem is that Neovim sends the initialization request here

function lsp.start_client(config)
local client = require('vim.lsp.client').create(config)
if not client then
return
end
--- @diagnostic disable-next-line: invisible
table.insert(client._on_exit_cbs, on_client_exit)
all_clients[client.id] = client
client:initialize()
return client.id
end

which may happen before the TCP/named pipe connection has been stablished here

if port == nil then
handle:connect(host_or_path, on_connect)
else
handle:connect(host_or_path, port, on_connect)
end

from neovim.

TheLeoP avatar TheLeoP commented on September 22, 2024

Using a command works because it handles the body since the command is launched

local stdout_handler = M.create_read_loop(handle_body, nil, function(err)
client:on_error(M.client_errors.READ_ERROR, err)
end)

local ok, sysobj_or_err = pcall(vim.system, cmd, {
stdin = true,
stdout = stdout_handler,
stderr = stderr_handler,
cwd = extra_spawn_params.cwd,
env = extra_spawn_params.env,
detach = detached,
}, function(obj)
dispatchers.on_exit(obj.code, obj.signal)
end)

while connecting via TCP/named pipe starts handling the body once the connection has been established:

handle:read_start(M.create_read_loop(handle_body, transport.terminate, function(read_err)
client:on_error(M.client_errors.READ_ERROR, read_err)
end))

from neovim.

TheLeoP avatar TheLeoP commented on September 22, 2024

Would there be a prefered aproach for a PR addressing this? I can think of:

  • Using vim.schedule_wrap to ensure the initialization request is made after the TCP/named pipe connection has been stablished (it's a workaround and may cause more problems in the future)
  • Refactor the code to send the initialization request inside a callback provided by client. vim.lsp.rpc.start would use this callback inmedeatly after calling vim.system if everithing is ok and vim.lsp.rpc.connect would do the same inside the on_connect callback, after initializing the read loop

from neovim.

mfussenegger avatar mfussenegger commented on September 22, 2024

@pogyomo can you try with #28507 ?

from neovim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.