What's the best way to send requests to a rust-analyzer instance programmatically?

I am working on a proc macro, and would like to be able to write some tests to ensure it's playing nice with rust-analyzer (e.g. correct localized diagnostics).

Ideally, my testing suite would look something like this:

  1. Start rust-analyzer pointed at a test crate
  2. Send some JSON-RPC requests to the server over stdin
  3. Read the response and check to see the result is as expected

So in principal, I should be able to do all of this, but as not to re-invent the wheel I am wondering how much of this might already exist. For instance, is there a crate, or maybe an existing utility which is part of the rust-analyzer project, for setting up an LSP client like this and handling requests?

I'd suggest maybe just testing with GitHub - Manishearth/compiletest-rs: An extraction of the compiletest utility from the Rust compiler that the macro produces correct diagnostic. rust-analyzer-specific code in macros is a bit of an anti-pattern -- ideally rust-analyzer just works with whatever is accepted by the compiler.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.