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

Test: let Code Actions contribute highlight range #203092

Closed
3 tasks done
justschen opened this issue Jan 22, 2024 · 2 comments
Closed
3 tasks done

Test: let Code Actions contribute highlight range #203092

justschen opened this issue Jan 22, 2024 · 2 comments

Comments

@justschen
Copy link
Contributor

justschen commented Jan 22, 2024

Refs: #199608

Complexity: 3

Create Issue

Create Issue


Overview

A proposed API that allows Code Actions to contribute a Range for affected lines in the editor, which will highlight those affectd lines.

The following is the structure of the proposed API:

	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[];
	}
}

dts can be found at https://github.com/microsoft/vscode/blob/main/src/vscode-dts/vscode.proposed.codeActionRanges.d.ts

You can use this in your extension by adding this to your extension manifest (package.json):

"enabledApiProposals": [
    "codeActionRanges"
  ],

and then run: npx vscode-dts dev which will fetch the proposed API and allow you to see types.

To test

  1. Must have an external extension with this API adopted, contributing a Code Action. If you have a personal extension to test on, fantastic. If not, check out this extension's implementation
  2. Once the extension is installed/adopted the API, double check that when highlighting with cursor, the selected lines are highlighted. Note: if there is no code in that line, it will not be highlighted.

Some things to make sure:

  • Due to how Range is implemented, the contributed Range is 0-based, while IRange (which it is converted to) starts at 1.
     

Let me know what you think overall!

Note: you must adopt this in an external extension (not a built-in to VS Code one)

Helpful links

@vscodenpa vscodenpa added this to the December / January 2024 milestone Jan 22, 2024
alexr00 added a commit to microsoft/vscode-pull-request-github that referenced this issue Jan 23, 2024
@alexr00
Copy link
Member

alexr00 commented Jan 23, 2024

This is a nice API addition. It makes it much clearer for the todo code action provider that the reason we're suggesting the action is because there's a "todo" comment.

@alexr00 alexr00 removed their assignment Jan 23, 2024
@paulacamargo25 paulacamargo25 removed their assignment Jan 23, 2024
@paulacamargo25
Copy link
Contributor

Agree with Alex, this way the code actions are easier to understand and the user has a way to see what has been modified. Great job 👍

@bamurtaugh bamurtaugh removed their assignment Jan 23, 2024
alexr00 added a commit to microsoft/vscode-pull-request-github that referenced this issue Feb 1, 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 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants