Add a request for setting response prefix #16032
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, if a proc macro prints something to the stdout (
println!("stuff {{}}")
) the output mixes with theproc-macro-srv
protocol messages (proc-macro-srv
uses stdout to communicate withrust-analyzer
) andrust-analyzer
then can't distinguishproc-macro-srv
JSON messages from the output from the proc macro.My idea is to prepend
proc-macro-srv
protocol messages with some long string, and then skip theproc-macro-srv
process output inrust-analyzer
until that known string (a bit similar to how Ethernet framing works). I.e. theproc-macro-srv
message should look like "OsdgHOghs895whrhg598{response_fields: {...}}"I don't want to hardcode some specific string because it could be exploited by some macro, or that string could become a problem if we decide to place that string inside a macro in
rust-analyzer
itself. So I think we should generate a random string.I added a new requst type
msg::Request::SetExpanderSettings
withresponse_prefix
field in order to delegate random string generation to rust-analyzer (and keep theproc-macro-srv
implementation as simple as possible).In this PR I just change the
proc-macro-srv
part