forked from gitkraken/vscode-gitlens
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes gitkraken#2515 - Adds openFileByRevision command
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 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,80 @@ | ||
import type { TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; | ||
import type { FileAnnotationType } from '../config'; | ||
import { Commands } from '../constants'; | ||
import type { Container } from '../container'; | ||
import { openFileAtRevision, pickFileAtRevision } from '../git/actions/commit'; | ||
import { GitUri } from '../git/gitUri'; | ||
import { showNoRepositoryWarningMessage } from '../messages'; | ||
import { showReferencePicker } from '../quickpicks/referencePicker'; | ||
import { command } from '../system/command'; | ||
import { ActiveEditorCommand, getCommandUri } from './base'; | ||
|
||
export interface OpenFileByRevisionCommandArgs { | ||
revisionUri?: Uri; | ||
|
||
line?: number; | ||
showOptions?: TextDocumentShowOptions; | ||
annotationType?: FileAnnotationType; | ||
} | ||
|
||
@command() | ||
export class OpenFileByRevisionCommand extends ActiveEditorCommand { | ||
constructor(private readonly container: Container) { | ||
super([ | ||
Commands.OpenFileByRevision /*, Commands.OpenFileByRevisionInDiffLeft, Commands.OpenFileByRevisionInDiffRight*/, | ||
]); | ||
} | ||
|
||
async execute(editor?: TextEditor, uri?: Uri, args?: OpenFileByRevisionCommandArgs) { | ||
uri = getCommandUri(uri, editor); | ||
if (uri == null) return; | ||
|
||
const gitUri = await GitUri.fromUri(uri); | ||
if (!gitUri.repoPath) { | ||
void showNoRepositoryWarningMessage('Unable to determine repository path'); | ||
return; | ||
} | ||
|
||
args = { ...args }; | ||
|
||
if (args.revisionUri == null) { | ||
let resolveKeyboardPickPromise: (reference: Uri) => void; | ||
const keyboardPickPromise = new Promise<Uri>(resolve => { resolveKeyboardPickPromise = resolve; }); | ||
const referencePickPromise = showReferencePicker( | ||
gitUri.repoPath, | ||
`Select Branch or Tag to browse for File`, | ||
'Choose a branch or tag', | ||
{ | ||
allowEnteringRefs: true, | ||
keys: ['right', 'alt+right', 'ctrl+right'], | ||
onDidPressKey: (key, quickpick) => { | ||
const [item] = quickpick.activeItems; | ||
if (item != null) { | ||
const refUri = this.container.git.getRevisionUri(item.ref, gitUri.fsPath, gitUri.repoPath!); | ||
resolveKeyboardPickPromise(refUri); | ||
} | ||
}, | ||
}, | ||
).then(commit => { | ||
return commit ? new GitUri(gitUri, commit) : undefined; | ||
}); | ||
const revision = await Promise.race([keyboardPickPromise, referencePickPromise]); | ||
if (revision == null) return; | ||
args.revisionUri = revision; | ||
} | ||
|
||
const revUri = await GitUri.fromUri(args.revisionUri); | ||
const file = await pickFileAtRevision(revUri, { | ||
title: 'Select File to open', | ||
initialPath: gitUri.relativePath, | ||
}); | ||
|
||
if (!file) return; | ||
|
||
await openFileAtRevision(file, { | ||
annotationType: args.annotationType, | ||
line: args.line, | ||
...args.showOptions, | ||
}); | ||
} | ||
} |
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