Skip to content

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

Closed

Description

@mjbvz

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)

Activity

  1. mjbvz commented on Nov 29, 2023

    @mjbvz
    ContributorAuthor
  2. justschen commented on Nov 29, 2023

    @justschen
    Collaborator

    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
  3. tjx666 commented on Jan 6, 2024

    @tjx666
    Contributor

    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
  4. added this to the milestone on Jan 18, 2024
  5. justschen commented on Jan 18, 2024

    @justschen
    Collaborator

    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[];
    	}
    }
  6. RedCMD commented on Jan 18, 2024

    @RedCMD
    Contributor

    could something similar be added to [F2] Rename?

  7. added
    unreleasedPatch has not yet been released in VS Code Insiders
    insiders-releasedPatch has been released in VS Code Insiders
    and removed
    unreleasedPatch has not yet been released in VS Code Insiders
    on Jan 18, 2024
  8. locked and limited conversation to collaborators on Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions