Stream: t-compiler/rust-analyzer

Topic: Extract Module to File assist implementaion questions


sasurau4 (Dec 04 2020 at 12:44, on Zulip):

I'll try to implement the assist to automate https://github.com/rust-analyzer/rust-analyzer/issues/6522 and then do the conversion.
I have 2 questions to start it.

  1. Where is good to implement the assist? Inside test-util crate or create new one?
  2. Is there good example implementation or package to achieve it?
matklad (Dec 04 2020 at 12:51, on Zulip):

Assists go into the assists/src/handlers directory

matklad (Dec 04 2020 at 12:51, on Zulip):

https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/unwrap_block.rs might be a good example

sasurau4 (Dec 04 2020 at 12:57, on Zulip):

Thanks :thumbs_up:

sasurau4 (Dec 04 2020 at 14:22, on Zulip):

Does Rustdoc support multi-file code block like multi-file assist tests?

// ```
//- /foo.rs
// mod tests {<|>
//     #[test] fn t() {}
// }
// ```
// ->
// ```
//- /foo.rs
// mod tests;
//
//- /foo/tests.rs
// #[test] fn t() {}
// ```
bjorn3 (Dec 04 2020 at 14:23, on Zulip):

Probably not

Joshua Nelson (Dec 04 2020 at 14:35, on Zulip):

it does not

sasurau4 (Dec 07 2020 at 13:01, on Zulip):

I tried to implement, but faced with no value set for FileTextQuery(FileId(1)) when I use following as input for check_assist func.

   check_assist(
       extract_module_to_file,
       r#"
//- /foo.rs crate:foo
mod tests {<|>
    #[test] fn t() {}
}
"#,
       r#"
//- /foo.rs crate:foo
mod tests;
//- /foo/tests.rs
#[test] fn t() {}
"#,
   )

I think the the reason why this error is CreateFile doesn't update SourceRoot registered in SourceDatabaseExt in check func.
How to update SourceRoot with file creation?

matklad (Dec 07 2020 at 13:28, on Zulip):

I don't think we need to actively update anything when checking assists

matklad (Dec 07 2020 at 13:28, on Zulip):

Rather, somewhere around this line: https://github.com/rust-analyzer/rust-analyzer/blob/403ed489ff51e4b1d9b1bbde1ddb6f765ebcbd1f/crates/assists/src/tests.rs#L106

matklad (Dec 07 2020 at 13:28, on Zulip):

We should take a look at file_system_edits and use them to see if the expected resut makes sense

sasurau4 (Dec 07 2020 at 14:44, on Zulip):

I see. I'll try it :thumbs_up:

Last update: Jul 27 2021 at 22:00UTC