Skip to content

Conversation

@edwin0cheng
Copy link
Contributor

@edwin0cheng edwin0cheng commented Mar 26, 2020

This PR add the actual client logic for ra_proc_macro crate:

  1. Define all necessary rpc serialization data structure, which include ra_tt related data and some task messages. Although adding Serialize and Deserialize trait to ra_tt directly seem to be much easier, we deliberately duplicate the ra_tt struct with #[serde(with = "XXDef")] for separation of code responsibility.
  2. Define a simplified version of lsp base protocol for rpc, which basically copy from lsp-server code base.
  3. Implement the actual IO for the client side progress spawning and message passing.

Copy link
Contributor

@Veetaha Veetaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took quick and dirty look.
I wonder how should we handle running proc macros for code with syntax errors? Do we remove some parts of code or fix it by inserting missing syntax?

return Ok(None);
}
if !buf.ends_with("\r\n") {
return Err(invalid_data!("malformed header: {:?}", buf));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider using anyhow for error-handling?

Copy link
Contributor Author

@edwin0cheng edwin0cheng Mar 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as below, I just copy and paste from https://github.com/rust-analyzer/lsp-server/blob/master/src/msg.rs , but I am okay to change it if you want.

@edwin0cheng edwin0cheng force-pushed the add-proc-macro-client-logic branch from 617f2cd to 26f7270 Compare March 27, 2020 05:05
@flodiebold
Copy link
Member

I wonder how should we handle running proc macros for code with syntax errors? Do we remove some parts of code or fix it by inserting missing syntax?

In general, I don't think we can, since we have no information about what structure the proc macro expects :( For attribute proc macros in particular though, we should probably try to 'complete' erroneous code before passing it to the proc macro somehow. At least in easy cases.

@edwin0cheng edwin0cheng force-pushed the add-proc-macro-client-logic branch from d8c859d to 799bcba Compare March 30, 2020 12:44
@edwin0cheng
Copy link
Contributor Author

Conflicts fixed.

@edwin0cheng edwin0cheng force-pushed the add-proc-macro-client-logic branch from 799bcba to 0f48ab4 Compare March 31, 2020 02:14
code: ErrorCode::ServerErrorEnd,
message: "Server closed".into(),
});
if result_tx.send(res.into()).is_err() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, lets make this an unwrap, and make sure that the opposite side of the channel is not dropped to early

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

The recv side of this channel would not be dropped as it was passed by the task channel:

https://github.com/rust-analyzer/rust-analyzer/blob/eb84838e2c0344acd6b007365ef7fea9fc30759e/crates/ra_proc_macro/src/process.rs#L136-L140

@matklad
Copy link
Contributor

matklad commented Mar 31, 2020

lets land this, so that it doesn't conflict with other stuff...

bors r+

bors bot added a commit that referenced this pull request Mar 31, 2020
3738: Implement ra_proc_macro client logic r=matklad a=edwin0cheng

This PR add the actual client logic for `ra_proc_macro` crate:

1. Define all necessary rpc serialization data structure, which include `ra_tt` related data and some task messages. Although adding `Serialize` and `Deserialize` trait to ra_tt directly seem to be much easier,   we deliberately duplicate the `ra_tt` struct with `#[serde(with = "XXDef")]` for separation of  code responsibility. 
2. Define a simplified version of lsp base protocol for rpc, which basically copy from lsp-server code base. 
3. Implement the actual `IO` for the client side progress spawning and message passing.

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
@edwin0cheng
Copy link
Contributor Author

bors r-

@bors
Copy link
Contributor

bors bot commented Mar 31, 2020

Canceled

@matklad
Copy link
Contributor

matklad commented Mar 31, 2020

ouch, sorry, this might now actually conflict with #3790, which I intended to land after this PR, but messed up :(

Anyway, r=me

@edwin0cheng edwin0cheng force-pushed the add-proc-macro-client-logic branch from 94a068b to 3bc1670 Compare March 31, 2020 14:20
@edwin0cheng
Copy link
Contributor Author

bors r=matklad

bors bot added a commit that referenced this pull request Mar 31, 2020
3738: Implement ra_proc_macro client logic r=matklad a=edwin0cheng

This PR add the actual client logic for `ra_proc_macro` crate:

1. Define all necessary rpc serialization data structure, which include `ra_tt` related data and some task messages. Although adding `Serialize` and `Deserialize` trait to ra_tt directly seem to be much easier,   we deliberately duplicate the `ra_tt` struct with `#[serde(with = "XXDef")]` for separation of  code responsibility. 
2. Define a simplified version of lsp base protocol for rpc, which basically copy from lsp-server code base. 
3. Implement the actual `IO` for the client side progress spawning and message passing.

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
@bors
Copy link
Contributor

bors bot commented Mar 31, 2020

Build failed

@edwin0cheng
Copy link
Contributor Author

bors retry

@bors
Copy link
Contributor

bors bot commented Mar 31, 2020

@bors bors bot merged commit 7a54649 into rust-lang:master Mar 31, 2020
@edwin0cheng edwin0cheng deleted the add-proc-macro-client-logic branch March 31, 2020 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants