-
Notifications
You must be signed in to change notification settings - Fork 30k
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
editor/lineNumber/context
proposed menu
#175945
Comments
I think this is the way to go 👍 |
Feedback from API sync:
|
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 I mean, similar to how I see two different approaches.
"editor/lineNumber/context": [
{
"command": "_bookmarks.addAtLine",
"when": "!bookmarks.hasBookmarkAtLine"
},
{
"command": "_bookmarks.removeAtLine",
"when": "bookmarks.hasBookmarkAtLine"
}
],
"editor/lineNumber/context": [
{
"command": "_bookmarks.addAtLine",
"when": "lineNumber not in bookmarks.linesWithBookmarks"
},
{
"command": "_bookmarks.removeAtLine",
"when": "lineNumber in bookmarks.linesWithBookmarks"
}
], 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 |
Yeah I would assume you'd need to use the Maybe something that would be more possible with the new when clause parser. |
What value would |
Right now, it only provides interface EditorLineNumberContextParams {
lineNumber: number,
uri: Uri
} That's the reason why I suggested the |
In fact, I didn't remember there was |
@alefragnani what does it need to work with the |
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. |
Ah I see. @joyceerhl I think you need to do something like (untested): public show(e: IEditorMouseEvent) {
// on macOS ctrl+click is interpreted as right click
if (!e.event.rightButton && !(isMacintosh && e.event.leftButton && e.event.ctrlKey)) {
return;
}
const model = this.editor.getModel();
if (!e.target.position || !model || e.target.type !== MouseTargetType.GUTTER_LINE_NUMBERS && e.target.type !== MouseTargetType.GUTTER_GLYPH_MARGIN) {
return;
}
const anchor = { x: e.event.posx, y: e.event.posy };
const lineNumber = e.target.position.lineNumber;
const contextKeyService = this.contextKeyService.createOverlay([
['line', lineNumber],
]);
const menu = this.menuService.createMenu(MenuId.EditorLineNumberContext, contextKeyService);
const actions: IAction[][] = [];
this.instantiationService.invokeFunction(accessor => {
for (const generator of GutterActionsRegistry.getGutterActionsGenerators()) {
const collectedActions: IAction[] = [];
generator({ lineNumber, editor: this.editor, accessor }, { push: (action: IAction) => collectedActions.push(action) });
actions.push(collectedActions);
}
const menuActions = menu.getActions({ arg: { lineNumber, uri: model.uri }, shouldForwardArgs: true });
actions.push(...menuActions.map(a => a[1]));
this.contextMenuService.showContextMenu({
getAnchor: () => anchor,
getActions: () => Separator.join(...actions),
menuActionOptions: { shouldForwardArgs: true },
getActionsContext: () => ({ lineNumber, uri: model.uri }),
onHide: () => menu.dispose(),
});
});
} Probably would also want to add other vscode/src/vs/workbench/common/contextkeys.ts Line 144 in b9eb472
|
It makes sense to make the line number available via a context overlay. I've opened a PR to add an @eamodio in my testing it seems like the other |
Hi @joyceerhl, Just to let you know, the new
Thank you! |
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 @joyceerhl
Some of the numerous use cases by extensions to keep in mind when thinking through this feature: DiffingVisual - 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 MetricsVisual - 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. LintersYou can imagine numerous different linters running (syntax error, style enforcement, common typos, banned words/regex, etc). DiagnosticsNext to logging lines allows seeing a sampling of the values that were output at that line, along with drilling down and slicing those values. BookmarksUnit Testing - Run/Debug test |
Feedback from API sync:
|
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. |
@QuocTrung76 you should be able to reference the new menu in the |
Works great in |
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:
editor/lineNumber/context
should contain actions for:testing/item/gutter
should contain actions for:In other words, I plan to contribute
Copy __ Link
actions to botheditor/lineNumber/context
andtesting/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 toeditor/gutter/context
and pull in any contributions totesting/item/gutter
for backwards compatibility, cc @connor4312)The text was updated successfully, but these errors were encountered: