rust-analyzer/crates/ide-db/src
bors eeceba7480 Auto merge of #14065 - lowr:patch/generate-generic-function, r=Veykril
Support generic function in `generate_function` assist

Part of #3639

This PR adds support for generic function generation in `generate_function` assist. Now the assist looks for generic parameters and trait bounds in scope, filters out irrelevant ones, and generates new function with them.

See `fn_generic_params()` for the outline of the procedure, and see comments on `filter_unnecessary_bounds()` for criteria for filtering. I think it's good criteria for most cases, but I'm open to opinions and suggestions.

The diff is pretty big, but it should run in linear time w.r.t. the number of nodes we operate on and should be fast enough.

Some notes:
- When we generate function in an existing impl, generic parameters may cause name conflict. While we can detect the conflict and rename conflicting params, I didn't find it worthwhile mainly because it's really easy to resolve on IDE: use Rename functionality.
- I've implemented graph structure myself, because we don't have graph library as a dependency and we only need the simplest one.
  - Although `petgraph` is in our dependency graph and I was initially looking to use it, we don't actually depend on it AFAICT since it's only used in chalk's specialization graph handling, which we don't use. I'd be happy to replace my implementation with `petgraph` if it's okay to use it though.
- There are some caveats that I consider out of scope of this PR. See FIXME notes on added tests.
2023-02-02 09:06:22 +00:00
..
generated style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
imports remove unnecessary lazy evaluations 2023-01-02 15:02:54 +00:00
syntax_helpers test: fix arg_type test 2023-01-09 12:22:29 +01:00
test_data Encode the variants of HirFileId in a u32 with MSB as the tag 2022-11-25 23:28:35 +01:00
tests Inline all format arguments where possible 2022-12-24 14:36:10 -05:00
active_parameter.rs ⬆️ rust-analyzer 2022-09-13 15:38:11 +03:00
apply_change.rs ⬆️ rust-analyzer 2022-08-23 10:05:52 +03:00
assists.rs Inline all format arguments where possible 2022-12-24 14:36:10 -05:00
defs.rs Record method resolution for call expressions 2023-01-27 11:06:41 +01:00
famous_defs.rs Improve "Generate Deref impl" assist 2022-05-16 20:10:46 +02:00
helpers.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
items_locator.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
label.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
lib.rs Clippy-fix explicit auto-deref 2022-12-23 02:52:14 -05:00
line_index.rs Iterate over arrays dirrectly, instead of going through a slice 2023-01-14 13:02:28 +00:00
path_transform.rs Support generic function in generate_function assist 2023-01-31 21:05:25 +09:00
rename.rs fix 2023-01-24 23:22:30 +05:30
rust_doc.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
search.rs fix: Fix assoc item search finding unrelated definitions 2023-01-24 14:11:02 +01:00
source_change.rs ⬆️ rust-analyzer 2022-08-30 14:51:24 +03:00
symbol_index.rs collapse some nested blocks 2023-01-10 20:40:08 +00:00
traits.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
ty_filter.rs Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
use_trivial_contructor.rs add doc strings to use_trivial_contructor.rs 2022-06-22 16:49:50 +02:00