-
Notifications
You must be signed in to change notification settings - Fork 29k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Share menu and a share vscode.dev command (#152765)
* Add a share menu Fixes #146309 * Add vscod.dev command in github extension * Make share menu proposed * Add share submenu into editor context * Add proposed to editor share menu
- Loading branch information
Showing
13 changed files
with
191 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { API as GitAPI, Repository } from './typings/git'; | ||
import { getRepositoryFromUrl } from './util'; | ||
|
||
export function isFileInRepo(repository: Repository, file: vscode.Uri): boolean { | ||
return file.path.toLowerCase() === repository.rootUri.path.toLowerCase() || | ||
(file.path.toLowerCase().startsWith(repository.rootUri.path.toLowerCase()) && | ||
file.path.substring(repository.rootUri.path.length).startsWith('/')); | ||
} | ||
|
||
export function getRepositoryForFile(gitAPI: GitAPI, file: vscode.Uri): Repository | undefined { | ||
for (const repository of gitAPI.repositories) { | ||
if (isFileInRepo(repository, file)) { | ||
return repository; | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
function getFileAndPosition(): { uri: vscode.Uri | undefined; range: vscode.Range | undefined } { | ||
let uri: vscode.Uri | undefined; | ||
let range: vscode.Range | undefined; | ||
if (vscode.window.activeTextEditor) { | ||
uri = vscode.window.activeTextEditor.document.uri; | ||
range = vscode.window.activeTextEditor.selection; | ||
} | ||
return { uri, range }; | ||
} | ||
|
||
function rangeString(range: vscode.Range | undefined) { | ||
if (!range) { | ||
return ''; | ||
} | ||
let hash = `#L${range.start.line + 1}`; | ||
if (range.start.line !== range.end.line) { | ||
hash += `-L${range.end.line + 1}`; | ||
} | ||
return hash; | ||
} | ||
|
||
export function getPermalink(gitAPI: GitAPI, hostPrefix?: string): string | undefined { | ||
hostPrefix = hostPrefix ?? 'https:'; | ||
const { uri, range } = getFileAndPosition(); | ||
if (!uri) { | ||
return; | ||
} | ||
const gitRepo = getRepositoryForFile(gitAPI, uri); | ||
if (!gitRepo) { | ||
return; | ||
} | ||
let repo: { owner: string; repo: string } | undefined; | ||
gitRepo.state.remotes.find(remote => { | ||
if (remote.fetchUrl) { | ||
const foundRepo = getRepositoryFromUrl(remote.fetchUrl); | ||
if (foundRepo && (remote.name === gitRepo.state.HEAD?.upstream?.remote)) { | ||
repo = foundRepo; | ||
return; | ||
} else if (foundRepo && !repo) { | ||
repo = foundRepo; | ||
} | ||
} | ||
return; | ||
}); | ||
if (!repo) { | ||
return; | ||
} | ||
|
||
const commitHash = gitRepo.state.HEAD?.commit; | ||
const pathSegment = uri.path.substring(gitRepo.rootUri.path.length); | ||
|
||
return `${hostPrefix}/${repo.owner}/${repo.repo}/blob/${commitHash | ||
}${pathSegment}${rangeString(range)}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// empty placeholder declaration for the `file/share`-submenu contribution point |