diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-19 05:54:04 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-19 05:54:04 +0100 |
commit | 3f432730dfc7df83fed2d78a97d3d0cf97ffc282 (patch) | |
tree | 6b284cf75eccc23a2dcaf398767bb939ea5f077e /crates/ide_db/src/helpers.rs | |
parent | 7570212a544b8e973a7d57be3657aae6465028a7 (diff) | |
parent | 3d1ca786f6355041de9205cadd0a235581dd5af3 (diff) |
Merge #8467
8467: Adds impl Deref assist r=jhgg a=jhgg
This PR adds a new `generate_deref` assist that automatically generates a deref impl for a given struct field.
Check out this gif:
![2021-04-11_00-33-33](https://user-images.githubusercontent.com/5489149/114296006-b38e1000-9a5d-11eb-9112-807c01b8fd0a.gif)
--
I have a few Q's:
- [x] Should I write more tests, if so, what precisely should I test for?
- [x] I have an inline question on line 65, can someone provide guidance? :)
- [x] I can implement this for `ast::TupleField` too. But should it be a separate assist fn, or should I try and jam both into the `generate_deref`?
- [x] I want to follow this up with an assist on `impl $0Deref for T {` which would automatically generate a `DerefMut` impl that mirrors the Deref as well, however, I could probably use some pointers on how to do that, since I'll have to reach into the ast of `fn deref` to grab the field that it's referencing for the `DerefMut` impl.
Co-authored-by: jake <[email protected]>
Diffstat (limited to 'crates/ide_db/src/helpers.rs')
-rw-r--r-- | crates/ide_db/src/helpers.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs index 66798ea3a..83a665b37 100644 --- a/crates/ide_db/src/helpers.rs +++ b/crates/ide_db/src/helpers.rs | |||
@@ -113,6 +113,10 @@ impl FamousDefs<'_, '_> { | |||
113 | self.find_module("core:iter") | 113 | self.find_module("core:iter") |
114 | } | 114 | } |
115 | 115 | ||
116 | pub fn core_ops_Deref(&self) -> Option<Trait> { | ||
117 | self.find_trait("core:ops:Deref") | ||
118 | } | ||
119 | |||
116 | fn find_trait(&self, path: &str) -> Option<Trait> { | 120 | fn find_trait(&self, path: &str) -> Option<Trait> { |
117 | match self.find_def(path)? { | 121 | match self.find_def(path)? { |
118 | hir::ScopeDef::ModuleDef(hir::ModuleDef::Trait(it)) => Some(it), | 122 | hir::ScopeDef::ModuleDef(hir::ModuleDef::Trait(it)) => Some(it), |