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

Keep track of trigger location for individual CompletionItem #55035

Merged
merged 4 commits into from
Jul 29, 2021

Conversation

genlu
Copy link
Member

@genlu genlu commented Jul 22, 2021

Fix committing completion item and expander in projection scenarios. Address #51702

@genlu genlu requested a review from a team as a code owner July 22, 2021 00:35
@genlu genlu changed the title Keep track of trigger location for individual TextBuffer Keep track of trigger location for individual CompletionItem Jul 23, 2021
Fix committing completion item and expander in projection scenarios
@genlu genlu requested review from a team as code owners July 23, 2021 20:39
@genlu genlu changed the base branch from main to release/dev16.11 July 23, 2021 20:39
@333fred 333fred removed request for a team July 23, 2021 21:30
var snapshotForDocument = data.InitialSortedList.FirstOrDefault(item => item.Properties.ContainsProperty(CompletionSource.TriggerLocation)) is VSCompletionItem firstItem &&
firstItem.Properties.GetProperty(CompletionSource.TriggerLocation) is SnapshotPoint triggerLocation
? triggerLocation.Snapshot
: data.Snapshot;
Copy link
Contributor

Choose a reason for hiding this comment

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

Data is captured here in the lambda, most of the other lambdas are static in the method here.

Copy link
Member

Choose a reason for hiding this comment

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

this is just really hard to read. can you make this a simple helper function.

Copy link
Member

Choose a reason for hiding this comment

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

which should always be available

If it shoudl always be available, we should either assert/contract so we get a stack when something breaks expectations. being defensive just means unexplainable bugs happen and we have no idea what is going on.

Copy link
Member Author

@genlu genlu Jul 26, 2021

Choose a reason for hiding this comment

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

Data is captured here in the lambda, most of the other lambdas are static in the method here.

I don't see anything got captured, but I did extract a local function here

If it shoudl always be available, we should either assert/contract so we get a stack when something breaks expectations. being defensive just means unexplainable bugs happen and we have no idea what is going on.

Add some comments to clarify

// since the intial trigger we are able to get from IAsyncCompletionSession might not be the same (e.g. in projection scenarios,)
// so when they are requested via expander later, we can retrieve it,.
// Techinically we should save the trigger location for each individual service that made such claim, but in reality , only Roslyn's completion service uses
// expander, so we can get away with not making such distinction.
Copy link
Member

Choose a reason for hiding this comment

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

i really don't get teh explanation.

Copy link
Member Author

Choose a reason for hiding this comment

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

i think this might actually be an issue with how Editor handle expander in old razor editor.

In the example below, when completion is triggered, our implementation of GetCompletionContextAsync is called twice, once with trigger location in C# buffer, another with trigger location in TS buffer. However, when user then hit expander, GetExpandedCompletionContextAsync is only called once with triggerLocation pointing to the HTML buffer, as a result we don't know which underlying document we should ask for expanded item for (i.e. cs vs ts).

image

But as mentioned in the comment, only Roslyn's provider actually use Expander, so in reality this will not cause any problem.

@genlu
Copy link
Member Author

genlu commented Jul 26, 2021

@jinujoseph @vatsalyaagrawal I think we should take this for 16.11. Please confirm then I will create a shiproom bug for it. Thanks

Copy link
Contributor

@allisonchou allisonchou left a comment

Choose a reason for hiding this comment

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

LGTM, although I'm not very familiar with the code so just basing my approval off what I can deduce from the PR 😃

genlu and others added 2 commits July 28, 2021 14:38
@genlu
Copy link
Member Author

genlu commented Jul 28, 2021

Thanks @allisonchou!

@genlu genlu merged commit e72f3c9 into dotnet:release/dev16.11 Jul 29, 2021
@genlu genlu deleted the fixRazorCompletion branch July 29, 2021 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants