mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-16 01:25:42 -05:00
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
'use strict';
|
|
import { Arrays } from '../system';
|
|
import { commands, Range, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
|
import { ActiveEditorCommand, Commands } from './common';
|
|
import { GitService, GitUri } from '../gitService';
|
|
import { Logger } from '../logger';
|
|
|
|
export class OpenFileInRemoteCommand extends ActiveEditorCommand {
|
|
|
|
constructor(private git: GitService) {
|
|
super(Commands.OpenFileInRemote);
|
|
}
|
|
|
|
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri) {
|
|
if (!(uri instanceof Uri)) {
|
|
if (!editor || !editor.document) return undefined;
|
|
uri = editor.document.uri;
|
|
}
|
|
|
|
if (!uri) return undefined;
|
|
|
|
const gitUri = await GitUri.fromUri(uri, this.git);
|
|
if (!gitUri.repoPath) return undefined;
|
|
|
|
const branch = await this.git.getBranch(gitUri.repoPath);
|
|
|
|
try {
|
|
const remotes = Arrays.uniqueBy(await this.git.getRemotes(gitUri.repoPath), _ => _.url, _ => !!_.provider);
|
|
const range = editor && new Range(editor.selection.start.with({ line: editor.selection.start.line + 1 }), editor.selection.end.with({ line: editor.selection.end.line + 1 }));
|
|
return commands.executeCommand(Commands.OpenInRemote, uri, remotes, 'file', [gitUri.getRelativePath(), branch.name, gitUri.sha, range]);
|
|
}
|
|
catch (ex) {
|
|
Logger.error(ex, 'OpenFileInRemoteCommand');
|
|
return window.showErrorMessage(`Unable to open file in remote provider. See output channel for more details`);
|
|
}
|
|
}
|
|
} |