-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto imports in completion #6553
Auto imports in completion #6553
Conversation
Cool! Can we add to the completion text that the module will be imported?
…On Sat, Nov 14, 2020, 2:25 PM Kirill Bulatov ***@***.***> wrote:
[image: completion]
<https://user-images.githubusercontent.com/2690773/99155339-ae4fb380-26bf-11eb-805a-655b1706ce70.gif>
Closes #1062 <#1062>
but does do anything about the completion order, since it's a separate task
for #4922 <#4922> ,
#4922 <#4922> and
maybe something else.
2 quirks in the current implementation:
- traits are not auto imported during method completion
If I understand the current situation right, we cannot search for traits
by a *part* of a method name, we need a full name with correct case to
get a trait for it.
- VSCode (?) autocompletion is not as rigid as in Intellij Rust as you
can notice on the animation.
Intellij is able to refresh the completions on every new symbol added, yet
VS Code does not query the completions in such case, if a new letter is
contained in the existing result.
So the only two ways to get an updated set of results is either to
manually retrigger it (Esc and Ctrl + Space) or input enough letters to
filter out all existing letters + one letter on top to query new
completions.
Despite the eerie latter bullet, the completion seems to work pretty fine
and fast nontheless, but if you have any ideas on how to make it more
smooth, I'll gladly try it out.
------------------------------
You can view, comment on, or merge this pull request online at:
#6553
Commit Summary
- Add imports in auto completion
- Use rewriter api to add both changes
- Tidy up the tests
- Add braces to functions and macros
- Allow to configure the merge behavior
- Rename the module
- Use imports_locator
- Reuse existing element rendering
- Tweak the search limits a bit
- Omit modules during autocompletion
- Move autoimport completion into the unqialified_path module
- Better filter mod paths
- Qualify autoimport completion suggestions
- Fix the other test
File Changes
- *M* Cargo.lock
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-13ee4b2252c9e516a0547f2891aa2105c3ca71c6d7a1e682c69be97998dfc87e>
(1)
- *M* crates/assists/src/handlers/auto_import.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-720c930e8cc45c08dea90bc1321a836f758043bd2661248399e4191fe8d792dd>
(3)
- *M* crates/assists/src/handlers/extract_struct_from_enum_variant.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-8d8fdde6339ba5b53b019e21a4fa326b4cc26ae77171b060acbf407eb97449ab>
(3)
- *M* crates/assists/src/handlers/replace_derive_with_manual_impl.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-88321a45d30694db91d30eb64e3deba8a219d77b6fd754d819f019e2de3ff322>
(28)
- *M* crates/assists/src/handlers/replace_qualified_name_with_use.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-6243a4d1c0aac21ce7815d910a7ca1eacdf07526479de075eb4dff7620383532>
(2)
- *M* crates/assists/src/utils.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-695923eec05b5abc411f01f5a2147d1e7302b322004b920c51a0d9bac2f889b7>
(3)
- *M* crates/assists/src/utils/import_assets.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-5fd5c9213bd564f39b89703cf3b12221b67e8ee9d997031d3fd718babccd61d9>
(34)
- *M* crates/assists/src/utils/insert_use.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-cbb69455e3211345e236e2c13c6646784914d898dbad233f80a71fa5e9ee56a2>
(14)
- *M* crates/completion/Cargo.toml
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-ca069489a2843b592e81afae6c044684d6a862d4f45f9615f79c0679df28f7a6>
(1)
- *M* crates/completion/src/completions/unqualified_path.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-4fd905fd8fa59b4a561f730d6fb39f9dd18f0940dad91493a16b8590112725c3>
(154)
- *M* crates/completion/src/config.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-f9588e3f83534cc23c3384e5a00767bf87e80a9ac356383f1bac1a95cb03bfd7>
(4)
- *M* crates/completion/src/item.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-6223301cabfcb7b47c1de8663dd2f42575e9919c3f60b82e310446411e3d03cc>
(21)
- *M* crates/completion/src/render.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-99bd9e8a359e507d61e83c1b3c812f0d1db53bc9e03b7976bae4447c2ed12f63>
(22)
- *M* crates/hir/src/code_model.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-944d99df715f999866d3a80e35878b60657395e2472b1715edd6dbbb43aa0663>
(10)
- *M* crates/hir/src/lib.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-9ded74602cbdce03cc0b20f094e733658a7b43d14ffe0f9167bc79a0851e7e53>
(1)
- *M* crates/ide_db/src/imports_locator.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-fdbc6dcb69246401fdfb0d438e1816972d8c429061492a4c2cc774c0f72815ba>
(60)
- *M* crates/text_edit/src/lib.rs
<https://github.com/rust-analyzer/rust-analyzer/pull/6553/files#diff-1bba1939d3d296c0cfa09156333e33190578dda5af98cf7933770fafaf81ee1d>
(4)
Patch Links:
- https://github.com/rust-analyzer/rust-analyzer/pull/6553.patch
- https://github.com/rust-analyzer/rust-analyzer/pull/6553.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#6553>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABBACRELAQYOIFWSVYYVVK3SP3KQ5ANCNFSM4TVXAQZA>
.
|
I've tried to emphasise this by adding a full qualifier to the completion label (we don't do that for anything else), but can add something else too, any particular ideas? |
60e5fe2
to
25e30c6
Compare
The last bullet is #6565 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I like how its' not that much code in the end: we did build some nice infrastructure for this!
crates/ide_db/src/imports_locator.rs
Outdated
local_query.limit(40); | ||
local_query | ||
}, | ||
ExternalImportablesQuery::new(name_to_import).anchor_end().case_sensitive().limit(40), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we don't set exact
for External imports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Query objects have different methods, this one has no exact
, but has achor_end
with the documentation:
/// Only returns items whose paths end with the (case-insensitive) query string as their last
/// segment.
If you mean the |
... we might need a separate index for that though, indexing traits by their contained methods. |
25e30c6
to
d4128be
Compare
And also the code that I've used, was very performant this time, no issues with the lookup at all.
I've meant that we miss this index, yes. |
I've rebased this PR on top and rechecked, looks like the behaviour did not change much. |
@SomeoneToIgnore I mean you need to flip |
Well, if we are doing good job, we shouldn't see those messages even if every IDE feature is horrible slow :-) This messages track not whether features are fast, but whether they block the main loop. |
bors r+ |
This is so amazing! Great work @SomeoneToIgnore |
My feelings are quite mixed when I hear this, so I'll allow myself a little praise on the topic once to explain why I as a contributor would prefer to be ignored in this situation. Since my early days of participation in this project, I wanted to implement this feature, it felt cool and charming to be able to deliver such magic to hundreds of people across the globe. Overall, I've taken 3 serious stabs at this issue and every time it was a different experience:
Almost 2 years since the original ticket, people were pursuing their own needs, investing into RA infra, their work was supported, PRs reviewed and merged. I think, this is a remarkable (and relatively rare) sign that we're on the right track and we need to thank everybody who participates in this development. |
@SomeoneToIgnore This appears to be the cause of the performance regression described in #6612. Reverting this PR, building and installing rust-analyzer locally fixed it for me. |
Can we move the work into completionItem/resolve for clients that support it? See #6366 |
I feel like an "experimental completions" toggle be quicker to add for me first, we'll need it anyway later. |
6650: Make completion and assists module independent r=matklad a=SomeoneToIgnore A follow-up of #6553 (comment) Move the common code for both assists and completion modules into a separate crate. Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Closes #1062 but does not handle the completion order, since it's a separate task for #4922 , #4922 and maybe something else.
2 quirks in the current implementation:
If I understand the current situation right, we cannot search for traits by a part of a method name, we need a full name with correct case to get a trait for it.
Intellij is able to refresh the completions on every new symbol added, yet VS Code does not query the completions on every symbol for me.
With a few debug prints placed in RA, I've observed the following behaviour: after the first set of completion suggestions is received, next symbol input does not trigger a server request, if the completions contain this symbol.
When more symbols added, the existing completion suggestions are filtered out until none are left and only then, on the next symbol it queries for completions.
It seems like the only alternative to get an updated set of results is to manually retrigger it with Esc and Ctrl + Space.
Despite the eerie latter bullet, the completion seems to work pretty fine and fast nontheless, but if you have any ideas on how to make it more smooth, I'll gladly try it out.