mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-15 09:35:42 -05:00
Adds line support to Open File in Remote command
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
'use strict';
|
||||
import { Range } from 'vscode';
|
||||
import { RemoteProvider } from './provider';
|
||||
|
||||
export class BitbucketService extends RemoteProvider {
|
||||
@@ -19,9 +20,19 @@ export class BitbucketService extends RemoteProvider {
|
||||
return `${this.baseUrl}/commits/${sha}`;
|
||||
}
|
||||
|
||||
protected getUrlForFile(fileName: string, branch?: string, sha?: string): string {
|
||||
if (sha) return `${this.baseUrl}/src/${sha}/${fileName}`;
|
||||
if (branch) return `${this.baseUrl}/src/${branch}/${fileName}`;
|
||||
return `${this.baseUrl}?path=${fileName}`;
|
||||
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
|
||||
let line: string = '';
|
||||
if (range) {
|
||||
if (range.start.line === range.end.line) {
|
||||
line = `#${fileName}-${range.start.line}`;
|
||||
}
|
||||
else {
|
||||
line = `#${fileName}-${range.start.line}:${range.end.line}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (sha) return `${this.baseUrl}/src/${sha}/${fileName}${line}`;
|
||||
if (branch) return `${this.baseUrl}/src/${branch}/${fileName}${line}`;
|
||||
return `${this.baseUrl}?path=${fileName}${line}`;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
'use strict';
|
||||
import { Range } from 'vscode';
|
||||
import { RemoteProvider } from './provider';
|
||||
|
||||
export class GitHubService extends RemoteProvider {
|
||||
@@ -19,9 +20,19 @@ export class GitHubService extends RemoteProvider {
|
||||
return `${this.baseUrl}/commit/${sha}`;
|
||||
}
|
||||
|
||||
protected getUrlForFile(fileName: string, branch?: string, sha?: string): string {
|
||||
if (sha) return `${this.baseUrl}/blob/${sha}/${fileName}`;
|
||||
if (branch) return `${this.baseUrl}/blob/${branch}/${fileName}`;
|
||||
return `${this.baseUrl}?path=${fileName}`;
|
||||
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
|
||||
let line: string = '';
|
||||
if (range) {
|
||||
if (range.start.line === range.end.line) {
|
||||
line = `#L${range.start.line}`;
|
||||
}
|
||||
else {
|
||||
line = `#L${range.start.line}-L${range.end.line}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (sha) return `${this.baseUrl}/blob/${sha}/${fileName}${line}`;
|
||||
if (branch) return `${this.baseUrl}/blob/${branch}/${fileName}${line}`;
|
||||
return `${this.baseUrl}?path=${fileName}${line}`;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
import { commands, Uri } from 'vscode';
|
||||
import { commands, Range, Uri } from 'vscode';
|
||||
import { BuiltInCommands } from '../../constants';
|
||||
|
||||
export type RemoteOpenType = 'branch' | 'commit' | 'file' | 'working-file';
|
||||
@@ -16,7 +16,7 @@ export abstract class RemoteProvider {
|
||||
|
||||
protected abstract getUrlForBranch(branch: string): string;
|
||||
protected abstract getUrlForCommit(sha: string): string;
|
||||
protected abstract getUrlForFile(fileName: string, branch: string, sha?: string): string;
|
||||
protected abstract getUrlForFile(fileName: string, branch: string, sha?: string, range?: Range): string;
|
||||
|
||||
private async _openUrl(url: string): Promise<{}> {
|
||||
return url && commands.executeCommand(BuiltInCommands.Open, Uri.parse(url));
|
||||
@@ -24,9 +24,9 @@ export abstract class RemoteProvider {
|
||||
|
||||
open(type: 'branch', branch: string): Promise<{}>;
|
||||
open(type: 'commit', sha: string): Promise<{}>;
|
||||
open(type: 'file', fileName: string, branch?: string, sha?: string): Promise<{}>;
|
||||
open(type: RemoteOpenType, ...args: string[]): Promise<{}>;
|
||||
open(type: RemoteOpenType, branchOrShaOrFileName: string, fileBranch?: string, fileSha?: string): Promise<{}> {
|
||||
open(type: 'file', fileName: string, branch?: string, sha?: string, range?: Range): Promise<{}>;
|
||||
open(type: RemoteOpenType, ...args: any[]): Promise<{}>;
|
||||
open(type: RemoteOpenType, branchOrShaOrFileName: string, fileBranch?: string, fileSha?: string, fileRange?: Range): Promise<{}> {
|
||||
switch (type) {
|
||||
case 'branch':
|
||||
return this.openBranch(branchOrShaOrFileName);
|
||||
@@ -34,7 +34,7 @@ export abstract class RemoteProvider {
|
||||
return this.openCommit(branchOrShaOrFileName);
|
||||
case 'file':
|
||||
case 'working-file':
|
||||
return this.openFile(branchOrShaOrFileName, fileBranch, fileSha);
|
||||
return this.openFile(branchOrShaOrFileName, fileBranch, fileSha, fileRange);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export abstract class RemoteProvider {
|
||||
return this._openUrl(this.getUrlForCommit(sha));
|
||||
}
|
||||
|
||||
openFile(fileName: string, branch?: string, sha?: string) {
|
||||
return this._openUrl(this.getUrlForFile(fileName, branch, sha));
|
||||
openFile(fileName: string, branch?: string, sha?: string, range?: Range) {
|
||||
return this._openUrl(this.getUrlForFile(fileName, branch, sha, range));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
'use strict';
|
||||
import { Range } from 'vscode';
|
||||
import { RemoteProvider } from './provider';
|
||||
|
||||
export class VisualStudioService extends RemoteProvider {
|
||||
@@ -19,9 +20,19 @@ export class VisualStudioService extends RemoteProvider {
|
||||
return `${this.baseUrl}/commit/${sha}`;
|
||||
}
|
||||
|
||||
protected getUrlForFile(fileName: string, branch?: string, sha?: string): string {
|
||||
if (sha) return `${this.baseUrl}/commit/${sha}/?_a=contents&path=%2F${fileName}`;
|
||||
if (branch) return `${this.baseUrl}/?path=%2F${fileName}&version=GB${branch}&_a=contents`;
|
||||
return `${this.baseUrl}?path=%2F${fileName}`;
|
||||
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
|
||||
let line: string = '';
|
||||
if (range) {
|
||||
if (range.start.line === range.end.line) {
|
||||
line = `&line=${range.start.line}`;
|
||||
}
|
||||
else {
|
||||
line = `&line=${range.start.line}&lineEnd=${range.end.line}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (sha) return `${this.baseUrl}/commit/${sha}/?_a=contents&path=%2F${fileName}${line}`;
|
||||
if (branch) return `${this.baseUrl}/?path=%2F${fileName}&version=GB${branch}&_a=contents${line}`;
|
||||
return `${this.baseUrl}?path=%2F${fileName}${line}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user