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

Revert "Introduce share links in more places via a contrib" #177328

Merged
merged 1 commit into from Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions build/lib/i18n.resources.json
Expand Up @@ -194,10 +194,6 @@
"name": "vs/workbench/contrib/searchEditor",
"project": "vscode-workbench"
},
{
"name": "vs/workbench/contrib/share",
"project": "vscode-workbench"
},
{
"name": "vs/workbench/contrib/snippets",
"project": "vscode-workbench"
Expand Down
47 changes: 41 additions & 6 deletions extensions/github/package.json
Expand Up @@ -38,13 +38,16 @@
},
{
"command": "github.copyVscodeDevLink",
"enablement": "github.hasGitHubRepo && resourceScheme != untitled && remoteName != 'codespaces'",
"title": "Copy vscode.dev Link"
},
{
"command": "github.copyVscodeDevLinkFile",
"title": "Copy vscode.dev Link"
},
{
"command": "github.copyVscodeDevLinkWithoutRange",
"title": "Copy vscode.dev Link"
},
{
"command": "github.openOnVscodeDev",
"title": "Open in vscode.dev",
Expand Down Expand Up @@ -74,24 +77,56 @@
"command": "github.copyVscodeDevLinkFile",
"when": "false"
},
{
"command": "github.copyVscodeDevLinkWithoutRange",
"when": "false"
},
{
"command": "github.openOnVscodeDev",
"when": "false"
}
],
"share": [
"file/share": [
{
"command": "github.copyVscodeDevLinkFile",
"when": "github.hasGitHubRepo && remoteName != 'codespaces'",
"group": "0_vscode@0"
}
],
"editor/context/share": [
{
"command": "github.copyVscodeDevLink",
"when": "github.hasGitHubRepo && resourceScheme != untitled && remoteName != 'codespaces'",
"group": "0_vscode@0"
}
],
"explorer/context/share": [
{
"command": "github.copyVscodeDevLinkWithoutRange",
"when": "github.hasGitHubRepo && resourceScheme != untitled && remoteName != 'codespaces'",
"group": "0_vscode@0"
}
],
"editor/lineNumber/context": [
{
"command": "github.copyVscodeDevLink",
"when": "github.hasGitHubRepo && resourceScheme != untitled && activeEditor == workbench.editors.files.textFileEditor && config.editor.lineNumbers == on && remoteName != 'codespaces'",
"group": "1_cutcopypaste@2"
},
{
"command": "github.copyVscodeDevLink",
"title": "Copy vscode.dev Link"
"when": "github.hasGitHubRepo && resourceScheme != untitled && activeEditor == workbench.editor.notebook && remoteName != 'codespaces'",
"group": "1_cutcopypaste@2"
}
],
"file/share": [
"editor/title/context/share": [
{
"command": "github.copyVscodeDevLinkFile",
"when": "github.hasGitHubRepo && remoteName != 'codespaces'",
"command": "github.copyVscodeDevLinkWithoutRange",
"when": "github.hasGitHubRepo && resourceScheme != untitled && remoteName != 'codespaces'",
"group": "0_vscode@0"
}
]

},
"configuration": [
{
Expand Down
9 changes: 5 additions & 4 deletions extensions/github/src/commands.ts
Expand Up @@ -45,17 +45,18 @@ export function registerCommands(gitAPI: GitAPI): vscode.Disposable {
}
}));

disposables.add(vscode.commands.registerCommand('github.copyVscodeDevLink', async (context: LinkContext, ranges?: vscode.Range[]) => {
if (Array.isArray(ranges) && ranges.every((range) => 'start' in range && 'end' in range) && context instanceof vscode.Uri) {
context = { uri: context, ranges };
}
disposables.add(vscode.commands.registerCommand('github.copyVscodeDevLink', async (context: LinkContext) => {
return copyVscodeDevLink(gitAPI, true, context);
}));

disposables.add(vscode.commands.registerCommand('github.copyVscodeDevLinkFile', async (context: LinkContext) => {
return copyVscodeDevLink(gitAPI, false, context);
}));

disposables.add(vscode.commands.registerCommand('github.copyVscodeDevLinkWithoutRange', async (context: LinkContext) => {
return copyVscodeDevLink(gitAPI, true, context, false);
}));

disposables.add(vscode.commands.registerCommand('github.openOnVscodeDev', async () => {
return openVscodeDevLink(gitAPI);
}));
Expand Down
48 changes: 21 additions & 27 deletions extensions/github/src/links.ts
Expand Up @@ -40,41 +40,27 @@ interface INotebookPosition {
range: vscode.Range | undefined;
}

interface EditorContext {
uri: vscode.Uri;
ranges: vscode.Range[];
}

interface EditorLineNumberContext {
uri: vscode.Uri;
lineNumber: number;
}
export type LinkContext = vscode.Uri | EditorLineNumberContext | undefined;

interface ScmResourceContext {
resourceUri: vscode.Uri;
}

export type LinkContext = vscode.Uri | EditorContext | EditorLineNumberContext | undefined | ScmResourceContext;

function extractContext(context: LinkContext): { fileUri: vscode.Uri | undefined; ranges: vscode.Range[] | undefined } {
function extractContext(context: LinkContext): { fileUri: vscode.Uri | undefined; lineNumber: number | undefined } {
if (context instanceof vscode.Uri) {
return { fileUri: context, ranges: undefined };
} else if (context !== undefined && 'ranges' in context && 'uri' in context) {
return { fileUri: context.uri, ranges: context.ranges };
return { fileUri: context, lineNumber: undefined };
} else if (context !== undefined && 'lineNumber' in context && 'uri' in context) {
return { fileUri: context.uri, ranges: [new vscode.Range(context.lineNumber - 1, 0, context.lineNumber - 1, 1)] };
} else if (context !== undefined && 'resourceUri' in context) {
return { fileUri: context.resourceUri, ranges: undefined };
return { fileUri: context.uri, lineNumber: context.lineNumber };
} else {
return { fileUri: undefined, ranges: undefined };
return { fileUri: undefined, lineNumber: undefined };
}
}

function getFileAndPosition(context: LinkContext): IFilePosition | INotebookPosition | undefined {
let range: vscode.Range | undefined;

const { fileUri, ranges: selections } = extractContext(context);
const uri = fileUri;
const { fileUri, lineNumber } = extractContext(context);
const uri = fileUri ?? vscode.window.activeTextEditor?.document.uri;

if (uri) {
if (uri.scheme === 'vscode-notebook-cell' && vscode.window.activeNotebookEditor?.notebook.uri.fsPath === uri.fsPath) {
Expand All @@ -83,11 +69,11 @@ function getFileAndPosition(context: LinkContext): IFilePosition | INotebookPosi
const cell = vscode.window.activeNotebookEditor.notebook.getCells().find(cell => cell.document.uri.fragment === uri?.fragment);
const cellIndex = cell?.index ?? vscode.window.activeNotebookEditor.selection.start;

const range = selections?.[0];
const range = getRangeOrSelection(lineNumber);
return { type: LinkType.Notebook, uri, cellIndex, range };
} else {
// the active editor is a text editor
range = selections?.[0];
range = getRangeOrSelection(lineNumber);
return { type: LinkType.File, uri, range };
}
}
Expand All @@ -100,6 +86,12 @@ function getFileAndPosition(context: LinkContext): IFilePosition | INotebookPosi
return undefined;
}

function getRangeOrSelection(lineNumber: number | undefined) {
return lineNumber !== undefined && (!vscode.window.activeTextEditor || vscode.window.activeTextEditor.selection.isEmpty || !vscode.window.activeTextEditor.selection.contains(new vscode.Position(lineNumber - 1, 0)))
? new vscode.Range(lineNumber - 1, 0, lineNumber - 1, 1)
: vscode.window.activeTextEditor?.selection;
}

function rangeString(range: vscode.Range | undefined) {
if (!range) {
return '';
Expand Down Expand Up @@ -130,7 +122,10 @@ export function notebookCellRangeString(index: number | undefined, range: vscode
export function getLink(gitAPI: GitAPI, useSelection: boolean, hostPrefix?: string, linkType: 'permalink' | 'headlink' = 'permalink', context?: LinkContext, useRange?: boolean): string | undefined {
hostPrefix = hostPrefix ?? 'https://github.com';
const fileAndPosition = getFileAndPosition(context);
const uri = fileAndPosition?.uri;
if (!fileAndPosition) {
return;
}
const uri = fileAndPosition.uri;

// Use the first repo if we cannot determine a repo from the uri.
const gitRepo = (uri ? getRepositoryForFile(gitAPI, uri) : gitAPI.repositories[0]) ?? gitAPI.repositories[0];
Expand All @@ -155,10 +150,9 @@ export function getLink(gitAPI: GitAPI, useSelection: boolean, hostPrefix?: stri
}

const blobSegment = (gitRepo.state.HEAD?.ahead === 0) ? `/blob/${linkType === 'headlink' ? gitRepo.state.HEAD.name : gitRepo.state.HEAD?.commit}` : '';
const fileSegments = fileAndPosition && uri ? (fileAndPosition.type === LinkType.File
const fileSegments = fileAndPosition.type === LinkType.File
? (useSelection ? `${uri.path.substring(gitRepo.rootUri.path.length)}${useRange ? rangeString(fileAndPosition.range) : ''}` : '')
: (useSelection ? `${uri.path.substring(gitRepo.rootUri.path.length)}${useRange ? notebookCellRangeString(fileAndPosition.cellIndex, fileAndPosition.range) : ''}` : ''))
: '';
: (useSelection ? `${uri.path.substring(gitRepo.rootUri.path.length)}${useRange ? notebookCellRangeString(fileAndPosition.cellIndex, fileAndPosition.range) : ''}` : '');

return `${hostPrefix}/${repo.owner}/${repo.repo}${blobSegment
}${fileSegments}`;
Expand Down
4 changes: 4 additions & 0 deletions src/vs/editor/contrib/clipboard/browser/clipboard.ts
Expand Up @@ -16,6 +16,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import * as nls from 'vs/nls';
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';

Expand Down Expand Up @@ -107,6 +108,9 @@ export const CopyAction = supportsCopy ? registerCommand(new MultiCommand({

MenuRegistry.appendMenuItem(MenuId.MenubarEditMenu, { submenu: MenuId.MenubarCopy, title: { value: nls.localize('copy as', "Copy As"), original: 'Copy As', }, group: '2_ccp', order: 3 });
MenuRegistry.appendMenuItem(MenuId.EditorContext, { submenu: MenuId.EditorContextCopy, title: { value: nls.localize('copy as', "Copy As"), original: 'Copy As', }, group: CLIPBOARD_CONTEXT_MENU_GROUP, order: 3 });
MenuRegistry.appendMenuItem(MenuId.EditorContext, { submenu: MenuId.EditorContextShare, title: { value: nls.localize('share', "Share"), original: 'Share', }, group: '11_share', order: -1, when: ContextKeyExpr.and(ContextKeyExpr.notEquals('resourceScheme', 'output'), EditorContextKeys.editorTextFocus) });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { submenu: MenuId.EditorTitleContextShare, title: { value: nls.localize('share', "Share"), original: 'Share', }, group: '11_share', order: -1 });
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, { submenu: MenuId.ExplorerContextShare, title: { value: nls.localize('share', "Share"), original: 'Share', }, group: '11_share', order: -1 });

export const PasteAction = supportsPaste ? registerCommand(new MultiCommand({
id: 'editor.action.clipboardPasteAction',
Expand Down
13 changes: 1 addition & 12 deletions src/vs/editor/contrib/contextmenu/browser/contextmenu.ts
Expand Up @@ -161,18 +161,7 @@ export class ContextMenuController implements IEditorContribution {

// get menu groups
const menu = this._menuService.createMenu(menuId, this._contextKeyService);
const groups = menu.getActions({
arg: [model.uri, this._editor.getSelections()?.map((selection) => ({
start: {
line: selection.getStartPosition().lineNumber - 1,
character: selection.getStartPosition().column
},
end: {
line: selection.getEndPosition().lineNumber - 1,
character: selection.getEndPosition().column
}
}))]
});
const groups = menu.getActions({ arg: model.uri });
menu.dispose();

// translate them into other actions
Expand Down
7 changes: 1 addition & 6 deletions src/vs/platform/actions/common/actions.ts
Expand Up @@ -98,18 +98,15 @@ export class MenuId {
static readonly MenubarViewMenu = new MenuId('MenubarViewMenu');
static readonly MenubarHomeMenu = new MenuId('MenubarHomeMenu');
static readonly OpenEditorsContext = new MenuId('OpenEditorsContext');
static readonly OpenEditorsContextShare = new MenuId('OpenEditorsContextShare');
static readonly ProblemsPanelContext = new MenuId('ProblemsPanelContext');
static readonly SCMChangeContext = new MenuId('SCMChangeContext');
static readonly SCMResourceContext = new MenuId('SCMResourceContext');
static readonly SCMResourceContextShare = new MenuId('SCMResourceContextShare');
static readonly SCMResourceFolderContext = new MenuId('SCMResourceFolderContext');
static readonly SCMResourceGroupContext = new MenuId('SCMResourceGroupContext');
static readonly SCMSourceControl = new MenuId('SCMSourceControl');
static readonly SCMTitle = new MenuId('SCMTitle');
static readonly SearchContext = new MenuId('SearchContext');
static readonly SearchActionMenu = new MenuId('SearchActionContext');
static readonly Share = new MenuId('Share');
static readonly StatusBarWindowIndicatorMenu = new MenuId('StatusBarWindowIndicatorMenu');
static readonly StatusBarRemoteIndicatorMenu = new MenuId('StatusBarRemoteIndicatorMenu');
static readonly StickyScrollContext = new MenuId('StickyScrollContext');
Expand Down Expand Up @@ -480,9 +477,7 @@ export class MenuItemAction implements IAction {
run(...args: any[]): Promise<void> {
let runArgs: any[] = [];

if (this._options?.arg && Array.isArray(this._options.arg)) {
runArgs = [...runArgs, ...this._options.arg];
} else if (this._options?.arg) {
if (this._options?.arg) {
runArgs = [...runArgs, this._options.arg];
}

Expand Down
Expand Up @@ -88,6 +88,9 @@ export class EditorLineNumberContextMenu extends Disposable implements IEditorCo
actions.push(collectedActions);
}

const menuActions = menu.getActions({ arg: { lineNumber, uri: model.uri }, shouldForwardArgs: true });
actions.push(...menuActions.map(a => a[1]));

// if the current editor selections do not contain the target line number,
// set the selection to the clicked line number
if (e.target.type === MouseTargetType.GUTTER_LINE_NUMBERS) {
Expand All @@ -104,24 +107,11 @@ export class EditorLineNumberContextMenu extends Disposable implements IEditorCo
}
}

const ranges = this.editor.getSelections()?.map((selection) => ({
start: {
line: selection.getStartPosition().lineNumber - 1,
character: selection.getStartPosition().column
},
end: {
line: selection.getEndPosition().lineNumber - 1,
character: selection.getEndPosition().column
}
}));
const menuActions = menu.getActions({ arg: { lineNumber, uri: model.uri, ranges } });
actions.push(...menuActions.map(a => a[1]));

this.contextMenuService.showContextMenu({
getAnchor: () => anchor,
getActions: () => Separator.join(...actions),
menuActionOptions: { shouldForwardArgs: true },
getActionsContext: () => ({ lineNumber, uri: model.uri, ranges }),
getActionsContext: () => ({ lineNumber, uri: model.uri }),
onHide: () => menu.dispose(),
});
});
Expand Down
64 changes: 0 additions & 64 deletions src/vs/workbench/contrib/share/browser/share.contribution.ts

This file was deleted.