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

Let code actions highlight a range of code they apply to #199608

Closed
mjbvz opened this issue Nov 29, 2023 · 5 comments · Fixed by #202197
Closed

Let code actions highlight a range of code they apply to #199608

mjbvz opened this issue Nov 29, 2023 · 5 comments · Fixed by #202197
Assignees
Labels
api api-proposal editor-code-actions Editor inplace actions (Ctrl + .) insiders-released Patch has been released in VS Code Insiders on-testplan

Comments

@mjbvz
Copy link
Collaborator

mjbvz commented Nov 29, 2023

Problem

For refactoring such as extract method or move to file, it's not always clear which code the action will apply to. This is especially true for languages like TS that try to intelligently expand the user's current selection

Proposal

Let code actions provide one (or potentially many) ranges that they will apply to. This range can then be highlighted as the user arrows through the code action list

For refactorings, this range would be the code in the current file that will be effected by the refactoring

For quick fixes, this range could be the range of the diagnostics that will be fixed (or we could just highlight the diagnostics directly since code actions already provide this info in CodeAction.diagnostics)

@mjbvz mjbvz added api editor-code-actions Editor inplace actions (Ctrl + .) labels Nov 29, 2023
@mjbvz
Copy link
Collaborator Author

mjbvz commented Nov 29, 2023

/cc @MariaSolOs

@justschen
Copy link
Contributor

justschen commented Nov 29, 2023

I like this actually (so it'll be kind of similar to the nearby quick fixes menu which highlights when not on specific code).

some smol thoughts related to the ui:

  • In some cases, the user is already highlighting what will be extracted, or moved, etc. so it might be a second highlight on top of that (in a diff color to differentiate what is user selected, and what is contributed by the code action to be change)
  • often times the quick fix menu, refactor menu, or menu from the lightbulb widget will block the highlighted code - maybe find a good workaround and move where it renders so we can actually see what is highlighted

highlights needs to explore:

  • Pick a forever theme color for the quick fix highlight and allow styling both background and borders

@tjx666
Copy link
Contributor

tjx666 commented Jan 6, 2024

Also, please consider provide a way to highlight the added code like:

https://github.com/p42ai/js-assistant

2024-01-06.10.58.18.mov

@justschen justschen added this to the December / January 2024 milestone Jan 18, 2024
@justschen
Copy link
Contributor

justschen commented Jan 18, 2024

shape of the API atm:

declare module 'vscode' {

	export interface CodeAction {
		/**
		 *
		 * The range to which this Code Action applies to, which will be highlighted.
		 *
		 * Ex: A refactoring action will highlight the range of text that will be affected.
		 */
		ranges?: Range[];
	}
}

@RedCMD
Copy link
Contributor

RedCMD commented Jan 18, 2024

could something similar be added to [F2] Rename?

@vscodenpa vscodenpa added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Jan 18, 2024
@aiday-mar aiday-mar added this to the December / January 2024 milestone Feb 6, 2024
@microsoft microsoft locked and limited conversation to collaborators Jun 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api api-proposal editor-code-actions Editor inplace actions (Ctrl + .) insiders-released Patch has been released in VS Code Insiders on-testplan
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants