Skip to content

Commit

Permalink
Adds comments and clarifies forceSingleLine param
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jan 9, 2022
1 parent 5385e29 commit da9f5f7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/env/node/git/localGitProvider.ts
Expand Up @@ -24,7 +24,7 @@ import type {
} from '../../../@types/vscode.git';
import { configuration } from '../../../configuration';
import { BuiltInGitConfiguration, DocumentSchemes, GlyphChars } from '../../../constants';
import { Container } from '../../../container';
import type { Container } from '../../../container';
import { StashApplyError, StashApplyErrorReason } from '../../../git/errors';
import {
GitProvider,
Expand Down Expand Up @@ -729,7 +729,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return promise;
}

async getBlameForFileContentsCore(
private async getBlameForFileContentsCore(
uri: GitUri,
contents: string,
document: TrackedDocument<GitDocumentState>,
Expand Down Expand Up @@ -774,10 +774,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
@log()
async getBlameForLine(
uri: GitUri,
editorLine: number, // editor lines are 0-based
options: { skipCache?: boolean } = {},
editorLine: number,
options?: { forceSingleLine?: boolean },
): Promise<GitBlameLine | undefined> {
if (!options.skipCache && this.useCaching) {
if (!options?.forceSingleLine && this.useCaching) {
const blame = await this.getBlameForFile(uri);
if (blame == null) return undefined;

Expand Down Expand Up @@ -824,11 +824,11 @@ export class LocalGitProvider implements GitProvider, Disposable {
@log<LocalGitProvider['getBlameForLineContents']>({ args: { 2: '<contents>' } })
async getBlameForLineContents(
uri: GitUri,
editorLine: number, // editor lines are 0-based
editorLine: number,
contents: string,
options: { skipCache?: boolean } = {},
options?: { forceSingleLine?: boolean },
): Promise<GitBlameLine | undefined> {
if (!options.skipCache && this.useCaching) {
if (!options?.forceSingleLine && this.useCaching) {
const blame = await this.getBlameForFileContents(uri, contents);
if (blame == null) return undefined;

Expand Down
24 changes: 22 additions & 2 deletions src/git/gitProvider.ts
Expand Up @@ -104,18 +104,38 @@ export interface GitProvider {
remote?: string | undefined;
},
): Promise<void>;
/**
* Returns the blame of a file
* @param uri The uri of the file to blame
*/
getBlameForFile(uri: GitUri): Promise<GitBlame | undefined>;
/**
* Returns the blame of a file, using the editor contents (for dirty editors)
* @param uri The uri of the file to blame
* @param contents The editor contents to use
*/
getBlameForFileContents(uri: GitUri, contents: string): Promise<GitBlame | undefined>;
/**
* Returns the blame of a single line
* @param uri The uri of the file to blame
* @param line The editor line number (0-based) to blame (Git is 1-based)
*/
getBlameForLine(
uri: GitUri,
editorLine: number,
options?: { skipCache?: boolean | undefined },
options?: { forceSingleLine?: boolean },
): Promise<GitBlameLine | undefined>;
/**
* Returns the blame of a single line, using the editor contents (for dirty editors)
* @param uri The uri of the file to blame
* @param line The editor line number (0-based) to blame (Git is 1-based)
* @param contents The editor contents to use
*/
getBlameForLineContents(
uri: GitUri,
editorLine: number,
contents: string,
options?: { skipCache?: boolean | undefined },
options?: { forceSingleLine?: boolean },
): Promise<GitBlameLine | undefined>;
getBlameForRange(uri: GitUri, range: Range): Promise<GitBlameLines | undefined>;
getBlameForRangeContents(uri: GitUri, range: Range, contents: string): Promise<GitBlameLines | undefined>;
Expand Down
30 changes: 25 additions & 5 deletions src/git/gitProviderService.ts
Expand Up @@ -25,7 +25,7 @@ import {
setContext,
WorkspaceState,
} from '../constants';
import { Container } from '../container';
import type { Container } from '../container';
import { ProviderNotFoundError } from '../errors';
import { Logger } from '../logger';
import { Arrays, debug, gate, Iterables, log, Paths, Promises, Strings } from '../system';
Expand Down Expand Up @@ -764,33 +764,53 @@ export class GitProviderService implements Disposable {
}

@log()
/**
* Returns the blame of a file
* @param uri The uri of the file to blame
*/
async getBlameForFile(uri: GitUri): Promise<GitBlame | undefined> {
const { provider } = this.getProvider(uri);
return provider.getBlameForFile(uri);
}

@log<GitProviderService['getBlameForFileContents']>({ args: { 1: '<contents>' } })
/**
* Returns the blame of a file, using the editor contents (for dirty editors)
* @param uri The uri of the file to blame
* @param contents The editor contents to use
*/
async getBlameForFileContents(uri: GitUri, contents: string): Promise<GitBlame | undefined> {
const { provider } = this.getProvider(uri);
return provider.getBlameForFileContents(uri, contents);
}

@log()
/**
* Returns the blame of a single line
* @param uri The uri of the file to blame
* @param line The editor line number (0-based) to blame (Git is 1-based)
*/
async getBlameForLine(
uri: GitUri,
editorLine: number, // editor lines are 0-based
options?: { skipCache?: boolean },
editorLine: number,
options?: { forceSingleLine?: boolean },
): Promise<GitBlameLine | undefined> {
const { provider } = this.getProvider(uri);
return provider.getBlameForLine(uri, editorLine, options);
}

@log<GitProviderService['getBlameForLineContents']>({ args: { 2: '<contents>' } })
/**
* Returns the blame of a single line, using the editor contents (for dirty editors)
* @param uri The uri of the file to blame
* @param line The editor line number (0-based) to blame (Git is 1-based)
* @param contents The editor contents to use
*/
async getBlameForLineContents(
uri: GitUri,
editorLine: number, // editor lines are 0-based
editorLine: number,
contents: string,
options?: { skipCache?: boolean },
options?: { forceSingleLine?: boolean },
): Promise<GitBlameLine | undefined> {
const { provider } = this.getProvider(uri);
return provider.getBlameForLineContents(uri, editorLine, contents, options);
Expand Down

0 comments on commit da9f5f7

Please sign in to comment.