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

4

19

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.

Anglo answered 11/8, 2021 at 16:9 Comment(1)
Although this is several years old, and there are several answers here, what I don't see mentioned is that on the Files tab, where you have the side by side view, you only get the Suggestion icon (the lightbulb) if you comment in the right hand pane. In the screenshot above, it very much looks like OP is commenting in the left hand pane.Oder
R
12

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

Ripple answered 13/8, 2021 at 13:57 Comment(3)
My issue was that I was clicking on lines in files that were removed and for comments on a file itself (derp). I realized my mistake yesterday, but if you can add a note about removed files then this will be a pretty good answer. I believe this is supported in other git-based source control systems but I get that it's very difficult to properly implement as it'd have to restore the file as well.Anglo
Just to note here - The above GIF does show it but it's not super obvious and gets me every time. When selecting multiple lines, DevOps shows the comment button near the margin, but there is another identical-looking button on the margin itself. You want the rightmost button to leave suggestions otherwise the suggestion only applies to one lineJeanettajeanette
Another note: I can only add a multi line comment, if I select a single file on the file tree on the left and not in the overview of all files changed. Tested on Azure DevOps Server 2020 Update 1.Aristotle
Q
15

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

Quintuplet answered 11/8, 2021 at 16:38 Comment(3)
What does it mean if I don't have this option?Anglo
@Anglo Do you have Azure DevOps Server (hosted on-prem) or are you using Azure DevOps Services (cloud version)? If it's on-prem, then it might be of an older version than the one this feature arrived with. Otherwise, if it's the cloud version, the feature should be there. I failed to find a special flag to turn it on/off.Quintuplet
By reading the answer from @jglathe, I got access to the Light bulb icon. The functionality is only visible for me in the Inline View mode or Modified content mode when watching the files in the Pull Request.Octofoil
R
12

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

Ripple answered 13/8, 2021 at 13:57 Comment(3)
My issue was that I was clicking on lines in files that were removed and for comments on a file itself (derp). I realized my mistake yesterday, but if you can add a note about removed files then this will be a pretty good answer. I believe this is supported in other git-based source control systems but I get that it's very difficult to properly implement as it'd have to restore the file as well.Anglo
Just to note here - The above GIF does show it but it's not super obvious and gets me every time. When selecting multiple lines, DevOps shows the comment button near the margin, but there is another identical-looking button on the margin itself. You want the rightmost button to leave suggestions otherwise the suggestion only applies to one lineJeanettajeanette
Another note: I can only add a multi line comment, if I select a single file on the file tree on the left and not in the overview of all files changed. Tested on Azure DevOps Server 2020 Update 1.Aristotle
T
1

I tried to use this feature, too, and found myself too dumb to do so. The importsant 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.

Treadle answered 31/1, 2024 at 16:58 Comment(0)
O
1

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.

Octofoil answered 15/3, 2024 at 16:15 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.