user15716642
user15716642

Reputation: 560

How can you insert suggestions on a PR in Azure Devops?

I found this somewhat recent mention of experimental PR features, and they mentioned the ability to insert and apply suggestions from the PR itself.

That's a feature I've grown very accustomed to with other products, but I'm a bit lost as to how I can access this feature in Azure DevOps in the present day.

enter image description here

Here is what I actually see: No lightbulb icon, etc.

Upvotes: 25

Views: 21527

Answers (5)

Vesa Vainio
Vesa Vainio

Reputation: 171

If the part of code that you want to target with your suggestion is something else than one full line, it's good to notice that there are different views of the code with subtle differences. The difference comes from what you have selected in the Files tab file explorer (the tree with folders and files):

  • If you have the full tree selected (which is the default), or some folder selected: you only have the comment bubble available next to the line number, and by clicking that, you can only target one full line of text.

  • If you have a single file selected in the tree, the view is slightly different (although looks almost the same). In this mode you are able to mark some area of the text with your pointer and target that area with your comment and suggestion. In this mode you get the comment bubble shown in answer from @Tore Aurstad. You can select a part of line, or you can select multiple lines. This can be really useful, especially if you want to make a suggestion that changes multiple lines.

Upvotes: 0

jglathe
jglathe

Reputation: 346

I tried to use this feature, too, and found myself too dumb to do so. The important part is that you need to have the file selected in diff view, not full file view. In this case there are actually 2 bubbles that turn up: One for comment, one for suggestion on the marked part.

Upvotes: 1

Tore Aurstad
Tore Aurstad

Reputation: 3816

Here is a walkthrough of how to access the functionality of applying suggestions via comments in Pull Request in Azure Devops.

I can acccess the Insert a suggestion functionality in Azure Devops via the Light bulb icon in Pull requests by doing these steps:

  • Inside the Pull Request, click on the tab File

  • Select a file to insert a suggestion for

  • Switch to view mode Side-by-side or Modified content View modes for the diff of the file in Pull request

  • Select one or more lines inside the text editor showing the file. You can also choose arbitrary number of characters by click and drag inside the editor. Or you can click on the line numbers to the left and click and drag or choose multiple lines holding in Shift.

  • You can now click the icon to add a comment - the 'chat bubble' icon

  • comment to add suggestion

  • Click the Light bulb icon to add a suggestion Insert suggestion

  • You are ready to provide your suggestion. This will both add a suggestion and also a comment in the PR that can be resolved and it is possible to apply your code suggestion. In case you want to delete lines for examples, you can provide empty lines inside the suggestion markdown syntax that pops up after clicking the 'light bulb' icon.

Upvotes: 2

Bright Ran-MSFT
Bright Ran-MSFT

Reputation: 13564

The "Insert a suggestion" option is not for the comments to the changed files.

Basically it is used to suggest changes for the following things in a file:

  • A line of content in the file.
  • Multiple selected lines of content in the file.
  • Any selected content in the file.

enter image description here

Upvotes: 14

Yan Sklyarenko
Yan Sklyarenko

Reputation: 32250

This feature should be enabled by default.

Open any pull request, navigate to the Files tab, choose the file and click a tooltip to enter a comment:

enter image description here

Now in the form that opens you'll see the button to add a suggestion:

enter image description here

Upvotes: 21

Related Questions