Browse Source

Adds supported schemes declaration

main
Eric Amodio 3 years ago
parent
commit
5167762616
3 changed files with 24 additions and 11 deletions
  1. +10
    -10
      src/env/node/git/localGitProvider.ts
  2. +1
    -0
      src/git/gitProvider.ts
  3. +13
    -1
      src/git/gitProviderService.ts

+ 10
- 10
src/env/node/git/localGitProvider.ts View File

@ -33,7 +33,7 @@ import {
RepositoryInitWatcher,
ScmRepository,
} from '../../../git/gitProvider';
import { GitProviderService } from '../../../git/gitProviderService';
import { GitProviderDescriptor, GitProviderService } from '../../../git/gitProviderService';
import { GitUri } from '../../../git/gitUri';
import {
BranchSortOptions,
@ -120,7 +120,14 @@ const mappedAuthorRegex = /(.+)\s<(.+)>/;
const reflogCommands = ['merge', 'pull'];
export class LocalGitProvider implements GitProvider, Disposable {
descriptor = { id: GitProviderId.Git, name: 'Git' };
readonly descriptor: GitProviderDescriptor = { id: GitProviderId.Git, name: 'Git' };
readonly supportedSchemes: string[] = [
DocumentSchemes.File,
DocumentSchemes.Git,
DocumentSchemes.GitLens,
DocumentSchemes.PRs,
DocumentSchemes.Vsls,
];
private _onDidChangeRepository = new EventEmitter<RepositoryChangeEvent>();
get onDidChangeRepository(): Event<RepositoryChangeEvent> {
@ -3415,14 +3422,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
isTrackable(uri: Uri): boolean {
const { scheme } = uri;
return (
scheme === DocumentSchemes.File ||
scheme === DocumentSchemes.Git ||
scheme === DocumentSchemes.GitLens ||
scheme === DocumentSchemes.PRs ||
scheme === DocumentSchemes.Vsls
);
return this.supportedSchemes.includes(uri.scheme);
}
private async isTracked(filePath: string, repoPath?: string, ref?: string): Promise<boolean>;

+ 1
- 0
src/git/gitProvider.ts View File

@ -68,6 +68,7 @@ export interface GitProvider {
get onDidChangeRepository(): Event<RepositoryChangeEvent>;
readonly descriptor: GitProviderDescriptor;
readonly supportedSchemes: string[];
discoverRepositories(uri: Uri): Promise<Repository[]>;
createRepository(

+ 13
- 1
src/git/gitProviderService.ts View File

@ -99,6 +99,11 @@ export type RepositoriesChangeEvent = {
readonly removed: readonly Repository[];
};
export interface GitProviderResult {
provider: GitProvider;
path: string;
}
export class GitProviderService implements Disposable {
private readonly _onDidChangeProviders = new EventEmitter<GitProvidersChangeEvent>();
get onDidChangeProviders(): Event<GitProvidersChangeEvent> {
@ -156,6 +161,7 @@ export class GitProviderService implements Disposable {
private readonly _disposable: Disposable;
private readonly _providers = new Map<GitProviderId, GitProvider>();
private readonly _repositories = new Map<string, Repository>();
private readonly _supportedSchemes = new Set<string>();
constructor(private readonly container: Container) {
this._disposable = Disposable.from(
@ -318,6 +324,9 @@ export class GitProviderService implements Disposable {
if (this._providers.has(id)) throw new Error(`Provider '${id}' has already been registered`);
this._providers.set(id, provider);
for (const scheme of provider.supportedSchemes) {
this._supportedSchemes.add(scheme);
}
const disposables = [];
@ -550,7 +559,7 @@ export class GitProviderService implements Disposable {
void updateRemoteContext.call(this);
}
private getProvider(repoPath: string | Uri): { provider: GitProvider; path: string } {
private getProvider(repoPath: string | Uri): GitProviderResult {
const id = GitProviderService.getProviderId(repoPath);
const provider = this._providers.get(id);
@ -1720,6 +1729,9 @@ export class GitProviderService implements Disposable {
}
isTrackable(uri: Uri): boolean {
const { scheme } = uri;
if (!this._supportedSchemes.has(scheme)) return false;
const { provider } = this.getProvider(uri);
return provider.isTrackable(uri);
}

Loading…
Cancel
Save