Skip to content
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

Move import text edit calculation into a completion resolve request #6706

Merged
merged 21 commits into from
Dec 8, 2020

Conversation

SomeoneToIgnore
Copy link
Contributor

@SomeoneToIgnore SomeoneToIgnore commented Dec 3, 2020

Part of #6612 (presumably fixing it)
Part of #6366 (does not cover all possible resolve capabilities we can do)
Closes #6594

Further improves imports on completion performance by deferring the computations for import inserts.

To use the new mode, you have to have the experimental completions enabled and use the LSP 3.16-compliant client that reports additionalTextEdits in its CompletionItemCapabilityResolveSupport field in the client capabilities.
rust-analyzer VSCode extension does this already hence picks up the changes completely.

Performance implications are descrbed in: #6633 (comment)

@SomeoneToIgnore
Copy link
Contributor Author

While we at it, we can discuss the autocompletion flag name: #6631 (comment)

@SomeoneToIgnore SomeoneToIgnore marked this pull request as draft December 4, 2020 10:44
@SomeoneToIgnore SomeoneToIgnore marked this pull request as ready for review December 4, 2020 14:34
if let Some(import_edit) =
self.import_to_add.as_ref().and_then(|import_edit| import_edit.to_text_edit())
{
text_edit.union(import_edit).expect("Failed to unite import and completion edits");
Copy link
Contributor

Choose a reason for hiding this comment

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

I get nervous about panicing since I've seen it take down the server during assists. Is there any way we can avoid it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The question here is "what to do if not to panic?".
IMO we should not return a half-baked CompletionItem in such case at all, but if I change the return type to Option or Result, the change will touch a lot of other code, so I did not dare to do this in this PR.

But sure, I've adjusted the code to log an error instead and to return some completion nontheless.
I did not remove the panic on serialisation in handlers.rs , since the whole file is abundant with them anyway.

@kjeremy
Copy link
Contributor

kjeremy commented Dec 4, 2020

I think this looks pretty good but would like another set of eyes on it. Can we add some tests that do not go through the LSP layer?

@SomeoneToIgnore
Copy link
Contributor Author

Can we add some tests that do not go through the LSP layer?

They kind of function this way already by doing that eager import application, but I've added one more to check the completion when we have the corresponding resolve capability in the completion settings.
Not sure what other non-LSP tests I can add.

@SomeoneToIgnore
Copy link
Contributor Author

A follow-up of #6594 (comment) had been added before it's too late to change the things.

editors/code/package.json Outdated Show resolved Hide resolved
})
.collect_vec();

if !all_edits_are_disjoint(&original_completion, &additional_edits) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this case signify a bug in our code? Or is it sanity-check for misbehaving client which, eg, asks to resolve old completion after some changes to the fiels where done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both, yeah: I'm finding it hard to trust the incoming object, since there are no guarantees on its contents.

@matklad
Copy link
Member

matklad commented Dec 8, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Dec 8, 2020

@bors bors bot merged commit 4d4f119 into rust-lang:master Dec 8, 2020
@SomeoneToIgnore SomeoneToIgnore deleted the resolve-completions branch December 8, 2020 13:18
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.

Autoimport completion doesn't suggest std::env::var
4 participants