Skip to content

API allowing CodeActionProviders to reliably get the current editor selection#49081

Merged
mjbvz merged 5 commits intomicrosoft:masterfrom
mjbvz:code-action-selection-api
May 10, 2018
Merged

API allowing CodeActionProviders to reliably get the current editor selection#49081
mjbvz merged 5 commits intomicrosoft:masterfrom
mjbvz:code-action-selection-api

Conversation

@mjbvz
Copy link
Collaborator

@mjbvz mjbvz commented May 2, 2018

Fixes #49024
Fixes #49060

See #49024 for details on the problem.

@mjbvz mjbvz self-assigned this May 2, 2018
@mjbvz mjbvz requested a review from jrieken May 2, 2018 21:08
@mjbvz mjbvz changed the title Add api so code action provider can reliable get current selection API allowing CodeActionProviders to reliably get the current editor selection May 2, 2018
Copy link
Member

Choose a reason for hiding this comment

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

undefined instead Undefined

Copy link
Member

Choose a reason for hiding this comment

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

We should explain when there is no selection, e.g. there is always a selection with an editor but we should point out that providers aren't always called without the document being shown inside an editor

Copy link
Member

Choose a reason for hiding this comment

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

You really wanna use strictNull-check, right?

@jrieken
Copy link
Member

jrieken commented May 3, 2018

Overall, still not sure if we should pass the selection instead of the range, e.g. range: Range | Selection, when calling the provider. Now we have somewhat competing information

@mjbvz mjbvz force-pushed the code-action-selection-api branch from c46c005 to 2d30e84 Compare May 7, 2018 23:06
Fixes microsoft#49024
Fixes microsoft#49060

See microsoft#49024 for details on the problem. Adds an optional `selection` property to `CodeActionContext`. This property has the original editor selection
@mjbvz mjbvz force-pushed the code-action-selection-api branch from 2d30e84 to 11c9ae2 Compare May 7, 2018 23:07
@mjbvz mjbvz force-pushed the code-action-selection-api branch from 11c9ae2 to dcbad16 Compare May 7, 2018 23:16
@mjbvz
Copy link
Collaborator Author

mjbvz commented May 7, 2018

@jrieken Pushed an update that goes to the range | Selection approach instead. This required tweaking some other logic and tests so please let me know if you have any concerns about the changes

return undefined;
}

private _getRangeOfSelectionUnlessWhitespaceEnclosed(): Selection {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unclear to me if we still want this check or not. The current logic always forwards the exact selection to the providers

Copy link
Member

@jrieken jrieken May 8, 2018

Choose a reason for hiding this comment

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

Yeah, I remember we had that for a very specific reason... Needs some deeper thinking but I believe it was to prevent the lightbulb from showing 'randomly' while clicking into the void/whitespace....

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I'll restore it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript refactorprovider provider uses activeTextEditor's selection API that allows code action providers to reliably get the current selection

2 participants