Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Testing small projects - sending data to goto_def example results in error #45

@Amar1729

Description

@Amar1729

I'm a bit new to LSP programs and trying to test a small one sample right now. I'm running cargo run --example goto_def, but can't seem to figure out how to actually send commands to a stdio connection.

I saw pr #27 , and I've tried copying JSON-rpc commands and piping them to the command but neither seem to work properly:

$ cargo run --example goto_def

    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/examples/goto_def`
starting generic LSP server
{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"capabilities":{}}}
Error: ProtocolError("expected initialize request, got error: receiving on an empty and disconnected channel")

$  cat send1                                                                     

{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"capabilities":{}}}

$  cat send1|cargo run --example goto_def                                              

    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/goto_def`
starting generic LSP server
Error: ProtocolError("expected initialize request, got error: receiving on an empty and disconnected channel")

$   cargo run --example goto_def < send1                                           

    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/examples/goto_def`
starting generic LSP server
Error: ProtocolError("expected initialize request, got error: receiving on an empty and disconnected channel")

I changed the sample to use sockets, but run into a different error here:

diff examples/goto_def.rs
-    let (connection, io_threads) = Connection::stdio();
+    let (connection, io_threads) = Connection::listen("127.0.0.1:5555")?;

$ cargo run                                                                         

    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/lumos-lsp`
starting generic LSP server
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: InvalidData, error: "malformed header: \"POST / HTTP/1.1\"" }', /Users/paula1/.cargo/registry/src/github.com-1ecc6299db9ec823/lsp-server-0.6.0/src/socket.rs:27:60
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: ProtocolError("expected initialize request, got error: receiving on an empty and disconnected channel")

# sent this curl cmd from a different tty during run
 $ curl -vv -XPOST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"capabilities":{}}}' http://localhost:5555

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 5555 (#0)
> POST / HTTP/1.1
> Host: localhost:5555
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 75
>
* upload completely sent off: 75 out of 75 bytes
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
* Closing connection 0

Am I missing something basic here about communication with the server?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions