Repository navigation
Description
Re: #175676
Currently clicking on a line number in the editor selects the whole line, but right clicking on it does not show a context menu. To mirror the behavior that GitHub offers for generating deeplinks to a line in a file, we'd like to introduce a context menu attached to line numbers in an editor, like so:
This new proposed menu should integrate well with the existing menus that appear in the editor gutter. We currently have the breakpoint editor contribution, which shows a menu of breakpoint actions on a right click in the editor gutter. Additionally, when test decorations are rendered, we show both breakpoint actions as well as testing actions. There is already a menu ID for the gutter when a testing decoration is rendered, testing/item/gutter, which accepts contributions from extensions.
This is the behavior I'm currently looking to implement:
- If line numbers are enabled:
- Context menu for
editor/lineNumber/contextshould contain actions for:- Test
- Debug
- Copy
- Context menu for
- If line numbers are disabled:
- Context menu for
testing/item/guttershould contain actions for:- Test
- Debug
- Reasoning: it doesn't seem like a natural interaction to want Share actions from the gutter if line numbers are turned off
- Context menu for
In other words, I plan to contribute Copy __ Link actions to both editor/lineNumber/context and testing/item/gutter, and the when clause for the Copy contributions to the latter menu would be "when": "config.editor.lineNumbers != off".
(It's a little odd to have copy actions contributed to testing/item/gutter so I wonder if we could rename to editor/gutter/context and pull in any contributions to testing/item/gutter for backwards compatibility, cc Connor Peet (@connor4312))

Activity
connor4312 commentedon Mar 2, 2023
I think this is the way to go 👍
joyceerhl commentedon Mar 7, 2023
Feedback from API sync:
editor/lineNumber/contextoreditor/lineNumbers/context{ uri: vscode.Uri; lineNumber: number }, perhaps it should be{ uri: vscode.Uri, position: vscode.Position }alefragnani commentedon Mar 9, 2023
Hi,
First of all, thank you for starting this API proposal. It will be really useful for some extensions 🤝
I was able to play with it, and TBH, seems fairly simple to use. But, unless I'm missing something, the
whenclause seems limited for this API.I mean, similar to how
Breakpointsworks, I would like to only displayAdd BookmarkorRemove Bookmarkmenus if the current line has or not bookmarks. It doesn't seems possible today.I see two different approaches.
setContextwith thelineNumberthat the event should pass as parameter, evaluating if the line has bookmarks. And it would be used as regularwhenclauseslineNumbercontext. So, I could useinandnot inconditional operators, evaluating with the list of bookmarks that the current file has, like:Am I missing something here, some additional documentation for this proposal that I should look for, or is this scenario still not covered?
Thank you
eamodio commentedon Mar 9, 2023
Yeah I would assume you'd need to use the
inconditionals. This does kind of beg for another type of when clause to actually be an indexer. So that you could use thelineNumberas an index into an array or object/map in another context value. That way you could access the value of that lookup to make further conditionals without having to create many other mappingincalls.Maybe something that would be more possible with the new when clause parser.
eamodio commentedon Mar 9, 2023
What value would
positionprovide over just the number? Wouldn't the column value always be 0? Also I think being a position would make the usage ofinimpossible (since I don't think you could access the line property)alefragnani commentedon Mar 9, 2023
Right now, it only provides
lineNumberanduri. Something like:That's the reason why I suggested the
in/not inconditional operators as an alternativealefragnani commentedon Mar 9, 2023
In fact, I didn't remember there was
inandnot inconditional operators, up until the moment I noticed it wouldn't be possible to do what I need without something else. Then I navigated to the API documentation, in order to look for alternatives, and there it was. A good alternative, but that also requires additional info from the API.eamodio commentedon Mar 9, 2023
Alessandro Fragnani (@alefragnani) what does it need to work with the
inoperator? IslineNumbernot provided to the when context?alefragnani commentedon Mar 9, 2023
Not that I'm aware of.
Maybe it is called something else, but a quick look at the issues/PRs but didn't find anything that could confirm.
eamodio commentedon Mar 9, 2023
Ah I see.
Joyce Er (@joyceerhl) I think you need to do something like (untested):
Here: https://github.com/microsoft/vscode/blob/main/src/vs/workbench/contrib/codeEditor/browser/editorLineNumberMenu.ts#L64
Probably would also want to add other
resource*context keys similar to what gets set on the editor content menus:https://code.visualstudio.com/api/references/when-clause-contexts#available-contexts
Probably via:
vscode/src/vs/workbench/common/contextkeys.ts
Line 144 in b9eb472
joyceerhl commentedon Mar 9, 2023
It makes sense to make the line number available via a context overlay. I've opened a PR to add an
editorLineNumbercontext key and tested that it works to enable/disable actions in this context menu for a test extension: #176659Eric Amodio (@eamodio) in my testing it seems like the other
resource*context keys are already set because of the active editor, so I'm not sure explicitly setting that for the context menu is necessary--please correct me if I'm mistaken.2 remaining items
AffluentOwl commentedon Mar 18, 2023
I had a few ideas for gutter annotations, and am wondering if all of the following are now possible after this change. I think #7 and #8 may be of particular interest to Joyce Er (@joyceerhl)
Some of the numerous use cases by extensions to keep in mind when thinking through this feature:
Diffing
Visual - Show contiguous green / red / yellow lines for where code matches / doesn't match / partially matches.
Use Case - Extend VS diffing to allow diffing against arbitrary changes in the commit history, or between two arbitrary files the user is working on.
Left Click - Opens side by side diff or inline diff view
Right Click - Context menu to allow changing revision to diff against, or arbitrary file to diff against.
Hover - Revision or arbitrary file being diffed against
Performance Metrics
Visual - Heatmap using a gradient from Red to Blue showing CPU time or Wall time spent on each line of code. Alternative visual - Just a 🔥 glyph on lines above some threshold of resource usage.
Use Case - Allows devs to identify expensive lines, to either improve or be cautious about changing or adding to.
Left Click - Opens website with a flame chart of measured performance of that line of code. Alternative - Opens the flame chart in a pane owned by the extension.
Right Click - Context menu to change/drilldown/slice the backing data source. For example, which benchmarks triggered the annotations. Or for which services/users is this considered a hot line versus others it is not.
Hover - Shows a panel with the callstack that contributed most to the performance, with hyperlinks that will open those code locations in vs code. Also shows the backing data source.
Linters
You can imagine numerous different linters running (syntax error, style enforcement, common typos, banned words/regex, etc).
Diagnostics
Next to logging lines allows seeing a sampling of the values that were output at that line, along with drilling down and slicing those values.
Bookmarks
Unit Testing - Run/Debug test
joyceerhl commentedon Apr 4, 2023
Feedback from API sync:
editorLineNumberin the editor context menu (versus the editor line number context menu) in future, but that can be done independently of this proposalQuocTrung99-Pro commentedon Apr 25, 2023
Sorry, I do not clearly understand the current status of editor/lineNumber/context, can I use it for contributions point/menu, I downloaded vscode.proposed.contribEditorLineNumberMenu.d.ts but it is empty.
gjsjohnmurray commentedon Apr 25, 2023
@QuocTrung76 you should be able to reference the new menu in the
package.jsonof your extension provided it specifies 1.78 as its minimum VS Code version. That also means you will have to use Insiders until 1.78 ships as the standard release (aka Stable), which is due by the end of next week.jantimon commentedon May 16, 2023
Works great in
1.78.2👍