Skip to content

Mark import completion items as complex#52332

Merged
333fred merged 2 commits intodotnet:mainfrom
333fred:mark-import-expensive
Apr 2, 2021
Merged

Mark import completion items as complex#52332
333fred merged 2 commits intodotnet:mainfrom
333fred:mark-import-expensive

Conversation

@333fred
Copy link
Member

@333fred 333fred commented Apr 1, 2021

Currently, import completion items are not marked as complex. This changes that to be marked as complex. Fixes #52331, and additionally adds verification of the flag for existing scenarios.

333fred added 2 commits March 31, 2021 21:51
Currently, import completion items are not marked as complex. This changes that to be marked as complex. Fixes dotnet#52331, and additionally adds verification of the flag for existing scenarios.
@ghost ghost added the Area-IDE label Apr 1, 2021
@CyrusNajmabadi
Copy link
Contributor

@allisonchou @genlu for if this flag is correct to use in this case. @allisonchou you needed this for things like override completion. But did you not need it for import completion? If so, i'm curious why not.

@allisonchou
Copy link
Contributor

I wasn't aware of import completion having a significant perf impact. If it does, I think it makes sense to mark it as a complex text edit. The primary downside is that it will block the UI thread.

@CyrusNajmabadi
Copy link
Contributor

The primary downside is that it will block the UI thread.

Can you expand on that @allisonchou that's a fairly big deal for me :-)

@CyrusNajmabadi
Copy link
Contributor

(please don't merge on this just yet. Thanks!)

@333fred
Copy link
Member Author

333fred commented Apr 1, 2021

I didn't think the flag was checked in non-lsp scenarios (and lsp doesn't do import completion today)?

@333fred
Copy link
Member Author

333fred commented Apr 1, 2021

Looking through our source, the only references to IsComplexTextEdit come from the CompletionHandler and the CompletionResolveHandler, and those turn off import completion: https://github.com/dotnet/roslyn/blob/main/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionHandler.cs#L348-L359.

@333fred 333fred marked this pull request as ready for review April 1, 2021 17:13
@333fred 333fred requested a review from a team as a code owner April 1, 2021 17:13
@allisonchou
Copy link
Contributor

allisonchou commented Apr 1, 2021

Ahh right, I forgot import completion is ignored. Then in that case I don't think this change affects the CompletionHandler at all, ignore my earlier comment.

@CyrusNajmabadi
Copy link
Contributor

CyrusNajmabadi commented Apr 1, 2021

Let me rephrase. First, if we enabled import completion for LSP (why is it off btw?), would we want this flag set on this or not? Thanks! :)

If we would want this flag, then i'm totally ok with this PR.

@genlu
Copy link
Member

genlu commented Apr 1, 2021

What's the intention of isComplexTextEdit? To mark items do more than inserting a string at current cursor location? And why do we need it?

Also note there are cases when import completion would insert fully qualified type name instead of add using (which is determined at commit time though).
http://sourceroslyn.io/#Microsoft.CodeAnalysis.Features/Completion/Providers/ImportCompletionProvider/AbstractImportCompletionProvider.cs,3bbcba1ee029cc87,references

@allisonchou
Copy link
Contributor

Let me rephrase. First, if we enabled import completion for LSP (why is it off btw?), would we want this flag set on this or not?

If import completion has significant perf concerns (it sounds like from Fred it does), then I think we'd want the flag on. It would make the overall completion experience faster, but would make resolving individual items slower since resolving the item would require the UI thread.

(why is it off btw?)

I believe it's off due to parity issues, e.g. there's no way to display namespaces today on the right-hand side of the list. More details are in https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1076759.

What's the intention of isComplexTextEdit? To mark items do more than inserting a string at current cursor location? And why do we need it?

isComplexTextEdit is used in VS LSP to indicate if computing the text changes for a completion item may have significant perf concerns. If isComplexTextEdit is set to true, then we delay computing the text changes until the user selects the item in the list. This way we can pop up the completion list faster. The downside is resolving the item later requires the UI thread, hence we don't want to do this for most items if we can help it.

@CyrusNajmabadi
Copy link
Contributor

The downside is resolving the item later requires the UI thread,

Why does it require the UI thread?

@dibarbet
Copy link
Member

dibarbet commented Apr 1, 2021

I believe it's off due to parity issues, e.g. there's no way to display namespaces today on the right-hand side of the list. More details are in https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1076759.

That, and perf concerns with huge completion list size and serialization. However this may have been mitigated by Taylor's recent changes with optimized completion lists and less resolve data.

So I think once the work item to show the detail text is resolved we should try turning on import completion for LSP and evaluate the perf.

@genlu
Copy link
Member

genlu commented Apr 1, 2021

OK, if LSP needs to compute text change from ALL items up front when creating completion list, then we absolutely need to mark unimported items as isComplexTextEdit.

@333fred
Copy link
Member Author

333fred commented Apr 1, 2021

OK, if LSP needs to compute text change from ALL items up front when creating completion list, then we absolutely need to mark unimported items as isComplexTextEdit.

Some certainly do (such as vscode).

@333fred
Copy link
Member Author

333fred commented Apr 2, 2021

@CyrusNajmabadi any more concerns with this change?

@CyrusNajmabadi
Copy link
Contributor

Nope! LGTM. Just a request for LSP folks to work on integrating this functionality.

@333fred 333fred merged commit db4b3ea into dotnet:main Apr 2, 2021
@ghost ghost added this to the Next milestone Apr 2, 2021
@333fred 333fred deleted the mark-import-expensive branch April 2, 2021 05:29
@dibarbet dibarbet modified the milestones: Next, 16.10.P3 Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CompletionItem.IsComplexTextEdit does not return true for import completion

5 participants