From 8d8ba961ccf32064bafd60b3e6c5847bb2d59fa7 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 2 Feb 2022 15:11:52 -0500 Subject: [PATCH] Changes DocumentSchemes to just Schemes --- src/codelens/codeLensProvider.ts | 18 +++++++++--------- src/commands/common.ts | 4 ++-- src/constants.ts | 4 ++-- src/env/node/git/localGitProvider.ts | 14 +++++++------- src/env/node/git/vslsGitProvider.ts | 6 +++--- src/git/fsProvider.ts | 4 ++-- src/git/gitProviderService.ts | 11 ++--------- src/git/gitUri.ts | 14 +++++++------- src/git/models/repository.ts | 4 ++-- src/premium/github/githubGitProvider.ts | 14 +++++--------- src/repositories.ts | 16 ++++++++-------- src/system/path.ts | 4 ++-- src/system/trie.ts | 12 ++++++------ src/views/nodes/fileHistoryTrackerNode.ts | 7 ++----- src/vsls/vsls.ts | 4 ++-- 15 files changed, 61 insertions(+), 75 deletions(-) diff --git a/src/codelens/codeLensProvider.ts b/src/codelens/codeLensProvider.ts index 4b45b6b..eb14905 100644 --- a/src/codelens/codeLensProvider.ts +++ b/src/codelens/codeLensProvider.ts @@ -35,7 +35,7 @@ import { configuration, FileAnnotationType, } from '../configuration'; -import { BuiltInCommands, DocumentSchemes } from '../constants'; +import { BuiltInCommands, Schemes } from '../constants'; import { Container } from '../container'; import type { GitUri } from '../git/gitUri'; import { GitBlame, GitBlameLines, GitCommit } from '../git/models'; @@ -86,14 +86,14 @@ export class GitAuthorsCodeLens extends CodeLens { export class GitCodeLensProvider implements CodeLensProvider { static selector: DocumentSelector = [ - { scheme: DocumentSchemes.File }, - { scheme: DocumentSchemes.Git }, - { scheme: DocumentSchemes.GitLens }, - { scheme: DocumentSchemes.PRs }, - { scheme: DocumentSchemes.Vsls }, - { scheme: DocumentSchemes.VslsScc }, - { scheme: DocumentSchemes.Virtual }, - { scheme: DocumentSchemes.GitHub }, + { scheme: Schemes.File }, + { scheme: Schemes.Git }, + { scheme: Schemes.GitLens }, + { scheme: Schemes.PRs }, + { scheme: Schemes.Vsls }, + { scheme: Schemes.VslsScc }, + { scheme: Schemes.Virtual }, + { scheme: Schemes.GitHub }, ]; private _onDidChangeCodeLenses = new EventEmitter(); diff --git a/src/commands/common.ts b/src/commands/common.ts index a76d149..74b8bed 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -14,7 +14,7 @@ import { workspace, } from 'vscode'; import type { Action, ActionContext } from '../api/gitlens'; -import { BuiltInCommands, DocumentSchemes, ImageMimetypes } from '../constants'; +import { BuiltInCommands, ImageMimetypes, Schemes } from '../constants'; import { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { @@ -714,7 +714,7 @@ export async function openEditor( uri = uri.documentUri(); } - if (uri.scheme === DocumentSchemes.GitLens && ImageMimetypes[extname(uri.fsPath)]) { + if (uri.scheme === Schemes.GitLens && ImageMimetypes[extname(uri.fsPath)]) { await commands.executeCommand(BuiltInCommands.Open, uri); return undefined; diff --git a/src/constants.ts b/src/constants.ts index 93de039..0598f70 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -88,7 +88,7 @@ export const enum Colors { UnpulledChangesIconColor = 'gitlens.unpulledChangesIconColor', } -export const enum DocumentSchemes { +export const enum Schemes { DebugConsole = 'debug', File = 'file', Git = 'git', @@ -119,7 +119,7 @@ export function isVisibleDocument(document: TextDocument): boolean { export function isTextEditor(editor: TextEditor): boolean { const scheme = editor.document.uri.scheme; - return scheme !== DocumentSchemes.Output && scheme !== DocumentSchemes.DebugConsole; + return scheme !== Schemes.Output && scheme !== Schemes.DebugConsole; } export function hasVisibleTextEditor(): boolean { diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 878ce95..95b7ee4 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -22,7 +22,7 @@ import type { GitExtension, } from '../../../@types/vscode.git'; import { configuration } from '../../../configuration'; -import { BuiltInGitConfiguration, DocumentSchemes, GlyphChars, WorkspaceState } from '../../../constants'; +import { BuiltInGitConfiguration, GlyphChars, Schemes, WorkspaceState } from '../../../constants'; import type { Container } from '../../../container'; import { StashApplyError, StashApplyErrorReason } from '../../../git/errors'; import { @@ -142,10 +142,10 @@ interface RepositoryInfo { export class LocalGitProvider implements GitProvider, Disposable { readonly descriptor: GitProviderDescriptor = { id: GitProviderId.Git, name: 'Git' }; readonly supportedSchemes: Set = new Set([ - DocumentSchemes.File, - DocumentSchemes.Git, - DocumentSchemes.GitLens, - DocumentSchemes.PRs, + Schemes.File, + Schemes.Git, + Schemes.GitLens, + Schemes.PRs, // DocumentSchemes.Vsls, ]); @@ -310,7 +310,7 @@ export class LocalGitProvider implements GitProvider, Disposable { } async discoverRepositories(uri: Uri): Promise { - if (uri.scheme !== DocumentSchemes.File) return []; + if (uri.scheme !== Schemes.File) return []; try { void (await this.ensureGit()); @@ -602,7 +602,7 @@ export class LocalGitProvider implements GitProvider, Disposable { }; const uri = Uri.from({ - scheme: DocumentSchemes.GitLens, + scheme: Schemes.GitLens, authority: encodeGitLensRevisionUriAuthority(metadata), path: path, query: ref ? JSON.stringify({ ref: GitRevision.shorten(ref) }) : undefined, diff --git a/src/env/node/git/vslsGitProvider.ts b/src/env/node/git/vslsGitProvider.ts index 7e934bc..67324e6 100644 --- a/src/env/node/git/vslsGitProvider.ts +++ b/src/env/node/git/vslsGitProvider.ts @@ -1,5 +1,5 @@ import { FileType, Uri, workspace } from 'vscode'; -import { DocumentSchemes } from '../../../constants'; +import { Schemes } from '../../../constants'; import { Container } from '../../../container'; import { GitCommandOptions } from '../../../git/commandOptions'; import { GitProviderDescriptor, GitProviderId } from '../../../git/gitProvider'; @@ -33,7 +33,7 @@ export class VslsGit extends Git { export class VslsGitProvider extends LocalGitProvider { override readonly descriptor: GitProviderDescriptor = { id: GitProviderId.Vsls, name: 'Live Share' }; - override readonly supportedSchemes: Set = new Set([DocumentSchemes.Vsls, DocumentSchemes.VslsScc]); + override readonly supportedSchemes: Set = new Set([Schemes.Vsls, Schemes.VslsScc]); override async discoverRepositories(uri: Uri): Promise { if (!this.supportedSchemes.has(uri.scheme)) return []; @@ -67,7 +67,7 @@ export class VslsGitProvider extends LocalGitProvider { const scheme = (typeof base !== 'string' ? base.scheme : undefined) ?? (typeof pathOrUri !== 'string' ? pathOrUri.scheme : undefined) ?? - DocumentSchemes.Vsls; + Schemes.Vsls; return super.getAbsoluteUri(pathOrUri, base).with({ scheme: scheme }); } diff --git a/src/git/fsProvider.ts b/src/git/fsProvider.ts index 2bec3b3..1a54160 100644 --- a/src/git/fsProvider.ts +++ b/src/git/fsProvider.ts @@ -11,7 +11,7 @@ import { workspace, } from 'vscode'; import { isLinux } from '@env/platform'; -import { DocumentSchemes } from '../constants'; +import { Schemes } from '../constants'; import { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { debug, Iterables, TernarySearchTree } from '../system'; @@ -31,7 +31,7 @@ export class GitFileSystemProvider implements FileSystemProvider, Disposable { constructor(private readonly container: Container) { this._disposable = Disposable.from( - workspace.registerFileSystemProvider(DocumentSchemes.GitLens, this, { + workspace.registerFileSystemProvider(Schemes.GitLens, this, { isCaseSensitive: isLinux, isReadonly: true, }), diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 94202c8..755c54a 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -16,14 +16,7 @@ import { } from 'vscode'; import { resetAvatarCache } from '../avatars'; import { configuration } from '../configuration'; -import { - BuiltInGitConfiguration, - ContextKeys, - DocumentSchemes, - GlyphChars, - setContext, - WorkspaceState, -} from '../constants'; +import { BuiltInGitConfiguration, ContextKeys, GlyphChars, Schemes, setContext, WorkspaceState } from '../constants'; import type { Container } from '../container'; import { ProviderNotFoundError } from '../errors'; import { Logger } from '../logger'; @@ -580,7 +573,7 @@ export class GitProviderService implements Disposable { let scheme; if (typeof repoPath === 'string') { - scheme = getScheme(repoPath) ?? DocumentSchemes.File; + scheme = getScheme(repoPath) ?? Schemes.File; } else { ({ scheme } = repoPath); } diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index 47ab665..0b42ad4 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -1,7 +1,7 @@ import { Uri } from 'vscode'; import { decodeUtf8Hex, encodeUtf8Hex } from '@env/hex'; import { UriComparer } from '../comparers'; -import { DocumentSchemes } from '../constants'; +import { Schemes } from '../constants'; import { Container } from '../container'; import { Logger } from '../logger'; import { GitHubAuthorityMetadata } from '../premium/remotehub'; @@ -56,7 +56,7 @@ export class GitUri extends (Uri as any as UriEx) { return; } - if (uri.scheme === DocumentSchemes.GitLens) { + if (uri.scheme === Schemes.GitLens) { super({ scheme: uri.scheme, authority: uri.authority, @@ -80,7 +80,7 @@ export class GitUri extends (Uri as any as UriEx) { return; } - if (uri.scheme === DocumentSchemes.Virtual || uri.scheme === DocumentSchemes.GitHub) { + if (uri.scheme === Schemes.Virtual || uri.scheme === Schemes.GitHub) { super(uri); const [, owner, repo] = uri.path.split('/', 3); @@ -254,10 +254,10 @@ export class GitUri extends (Uri as any as UriEx) { static async fromUri(uri: Uri): Promise { if (GitUri.is(uri)) return uri; if (!Container.instance.git.isTrackable(uri)) return new GitUri(uri); - if (uri.scheme === DocumentSchemes.GitLens) return new GitUri(uri); + if (uri.scheme === Schemes.GitLens) return new GitUri(uri); // If this is a git uri, find its repoPath - if (uri.scheme === DocumentSchemes.Git) { + if (uri.scheme === Schemes.Git) { let data: { path: string; ref: string } | undefined; try { data = JSON.parse(uri.query); @@ -295,7 +295,7 @@ export class GitUri extends (Uri as any as UriEx) { } } - if (uri.scheme === DocumentSchemes.PRs) { + if (uri.scheme === Schemes.PRs) { let data: | { baseCommit: string; @@ -432,7 +432,7 @@ export class GitUri extends (Uri as any as UriEx) { static git(path: string, repoPath?: string): Uri { const uri = Container.instance.git.getAbsoluteUri(path, repoPath); return Uri.from({ - scheme: DocumentSchemes.Git, + scheme: Schemes.Git, path: uri.path, query: JSON.stringify({ // Ensure we use the fsPath here, otherwise the url won't open properly diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index 4197d99..fc2eca4 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -14,7 +14,7 @@ import { import type { CreatePullRequestActionContext } from '../../api/gitlens'; import { executeActionCommand } from '../../commands'; import { configuration } from '../../configuration'; -import { BuiltInGitCommands, BuiltInGitConfiguration, DocumentSchemes, Starred, WorkspaceState } from '../../constants'; +import { BuiltInGitCommands, BuiltInGitConfiguration, Schemes, Starred, WorkspaceState } from '../../constants'; import { Container } from '../../container'; import { Logger } from '../../logger'; import { Messages } from '../../messages'; @@ -270,7 +270,7 @@ export class Repository implements Disposable { } get path(): string { - return this.uri.scheme === DocumentSchemes.File ? this.uri.fsPath : this.uri.toString(); + return this.uri.scheme === Schemes.File ? this.uri.fsPath : this.uri.toString(); } get etag(): number { diff --git a/src/premium/github/githubGitProvider.ts b/src/premium/github/githubGitProvider.ts index 9734706..f92d2a8 100644 --- a/src/premium/github/githubGitProvider.ts +++ b/src/premium/github/githubGitProvider.ts @@ -14,7 +14,7 @@ import { } from 'vscode'; import { encodeUtf8Hex } from '@env/hex'; import { configuration } from '../../configuration'; -import { DocumentSchemes } from '../../constants'; +import { Schemes } from '../../constants'; import type { Container } from '../../container'; import { AuthenticationError, @@ -95,11 +95,7 @@ interface RepositoryInfo { export class GitHubGitProvider implements GitProvider, Disposable { descriptor = { id: GitProviderId.GitHub, name: 'GitHub' }; - readonly supportedSchemes: Set = new Set([ - DocumentSchemes.Virtual, - DocumentSchemes.GitHub, - DocumentSchemes.PRs, - ]); + readonly supportedSchemes: Set = new Set([Schemes.Virtual, Schemes.GitHub, Schemes.PRs]); private _onDidChangeRepository = new EventEmitter(); get onDidChangeRepository(): Event { @@ -310,7 +306,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { try { const remotehub = await this.ensureRemoteHubApi(); - const rootUri = remotehub.getProviderRootUri(uri).with({ scheme: DocumentSchemes.Virtual }); + const rootUri = remotehub.getProviderRootUri(uri).with({ scheme: Schemes.Virtual }); return rootUri; } catch (ex) { if (!(ex instanceof ExtensionNotFoundError)) { @@ -2054,7 +2050,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { } return base.with({ - scheme: DocumentSchemes.Virtual, + scheme: Schemes.Virtual, authority: encodeAuthority('github', metadata), path: path ?? base.path, }); @@ -2064,7 +2060,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { const uri = this.createVirtualUri(base, ref, path); if (this._remotehub == null) { debugger; - return uri.scheme !== DocumentSchemes.Virtual ? uri : uri.with({ scheme: DocumentSchemes.GitHub }); + return uri.scheme !== Schemes.Virtual ? uri : uri.with({ scheme: Schemes.GitHub }); } return this._remotehub.getProviderUri(uri); diff --git a/src/repositories.ts b/src/repositories.ts index 3585897..dfa10a0 100644 --- a/src/repositories.ts +++ b/src/repositories.ts @@ -1,6 +1,6 @@ import { Uri } from 'vscode'; import { isLinux } from '@env/platform'; -import { DocumentSchemes } from './constants'; +import { Schemes } from './constants'; import { Repository } from './git/models/repository'; import { addVslsPrefixIfNeeded, normalizePath } from './system/path'; import { UriTrie } from './system/trie'; @@ -19,12 +19,12 @@ export function asRepoComparisonKey(uri: Uri): RepoComparisionKey { export function normalizeRepoUri(uri: Uri): { path: string; ignoreCase: boolean } { let path; switch (uri.scheme.toLowerCase()) { - case DocumentSchemes.File: + case Schemes.File: path = normalizePath(uri.fsPath); return { path: path, ignoreCase: !isLinux }; - case DocumentSchemes.Git: - case DocumentSchemes.GitLens: + case Schemes.Git: + case Schemes.GitLens: path = uri.path; if (path.charCodeAt(path.length - 1) === slash) { path = path.slice(1, -1); @@ -33,8 +33,8 @@ export function normalizeRepoUri(uri: Uri): { path: string; ignoreCase: boolean } return { path: path, ignoreCase: !isLinux }; - case DocumentSchemes.Virtual: - case DocumentSchemes.GitHub: { + case Schemes.Virtual: + case Schemes.GitHub: { path = uri.path; if (path.charCodeAt(path.length - 1) === slash) { path = path.slice(0, -1); @@ -44,8 +44,8 @@ export function normalizeRepoUri(uri: Uri): { path: string; ignoreCase: boolean const authority = uri.authority?.split('+', 1)[0]; return { path: authority ? `${authority}${path}` : path.slice(1), ignoreCase: false }; } - case DocumentSchemes.Vsls: - case DocumentSchemes.VslsScc: + case Schemes.Vsls: + case Schemes.VslsScc: // Check if this is a root live share folder, if so add the required prefix (required to match repos correctly) path = addVslsPrefixIfNeeded(uri.path); diff --git a/src/system/path.ts b/src/system/path.ts index 0baf8cd..b4404ef 100644 --- a/src/system/path.ts +++ b/src/system/path.ts @@ -1,7 +1,7 @@ import { isAbsolute as _isAbsolute, basename, dirname } from 'path'; import { Uri } from 'vscode'; import { isLinux, isWindows } from '@env/platform'; -import { DocumentSchemes } from '../constants'; +import { Schemes } from '../constants'; // TODO@eamodio don't import from string here since it will break the tests because of ESM dependencies // import { CharCode } from './string'; @@ -75,7 +75,7 @@ export function commonBaseIndex(s1: string, s2: string, delimiter: string, ignor } export function getBestPath(uri: Uri): string { - return normalizePath(uri.scheme === DocumentSchemes.File ? uri.fsPath : uri.path); + return normalizePath(uri.scheme === Schemes.File ? uri.fsPath : uri.path); } export function getScheme(path: string): string | undefined { diff --git a/src/system/trie.ts b/src/system/trie.ts index 2406176..9b9c2e2 100644 --- a/src/system/trie.ts +++ b/src/system/trie.ts @@ -1,6 +1,6 @@ import { Uri } from 'vscode'; import { isLinux } from '@env/platform'; -import { DocumentSchemes } from '../constants'; +import { Schemes } from '../constants'; import { filterMap } from './iterable'; import { normalizePath as _normalizePath } from './path'; // TODO@eamodio don't import from string here since it will break the tests because of ESM dependencies @@ -11,16 +11,16 @@ const slash = 47; //CharCode.Slash; function normalizeUri(uri: Uri): { path: string; ignoreCase: boolean } { let path; switch (uri.scheme.toLowerCase()) { - case DocumentSchemes.File: + case Schemes.File: path = normalizePath(uri.fsPath); return { path: path, ignoreCase: !isLinux }; - case DocumentSchemes.Git: + case Schemes.Git: path = normalizePath(uri.fsPath); // TODO@eamodio parse the ref out of the query return { path: path, ignoreCase: !isLinux }; - case DocumentSchemes.GitLens: + case Schemes.GitLens: path = uri.path; if (path.charCodeAt(path.length - 1) === slash) { path = path.slice(0, -1); @@ -32,8 +32,8 @@ function normalizeUri(uri: Uri): { path: string; ignoreCase: boolean } { return { path: uri.authority ? `${uri.authority}${path}` : path.slice(1), ignoreCase: false }; - case DocumentSchemes.Virtual: - case DocumentSchemes.GitHub: + case Schemes.Virtual: + case Schemes.GitHub: path = uri.path; if (path.charCodeAt(path.length - 1) === slash) { path = path.slice(0, -1); diff --git a/src/views/nodes/fileHistoryTrackerNode.ts b/src/views/nodes/fileHistoryTrackerNode.ts index 95dda78..3dc00eb 100644 --- a/src/views/nodes/fileHistoryTrackerNode.ts +++ b/src/views/nodes/fileHistoryTrackerNode.ts @@ -1,6 +1,6 @@ import { Disposable, FileType, TextEditor, TreeItem, TreeItemCollapsibleState, window, workspace } from 'vscode'; import { UriComparer } from '../../comparers'; -import { ContextKeys, DocumentSchemes, setContext } from '../../constants'; +import { ContextKeys, Schemes, setContext } from '../../constants'; import { GitCommitish, GitUri } from '../../git/gitUri'; import { GitReference, GitRevision } from '../../git/models'; import { Logger } from '../../logger'; @@ -238,10 +238,7 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode this.triggerChange(), 1500); } diff --git a/src/vsls/vsls.ts b/src/vsls/vsls.ts index 651b1c3..7c44449 100644 --- a/src/vsls/vsls.ts +++ b/src/vsls/vsls.ts @@ -1,6 +1,6 @@ import { Disposable, extensions, workspace } from 'vscode'; import type { LiveShare, LiveShareExtension, SessionChangeEvent } from '../@types/vsls'; -import { ContextKeys, DocumentSchemes, setContext } from '../constants'; +import { ContextKeys, Schemes, setContext } from '../constants'; import { Container } from '../container'; import { Logger } from '../logger'; import { debug } from '../system/decorators/log'; @@ -57,7 +57,7 @@ export class VslsController implements Disposable { private async initialize() { // If we have a vsls: workspace open, we might be a guest, so wait until live share transitions into a mode - if (workspace.workspaceFolders?.some(f => f.uri.scheme === DocumentSchemes.Vsls)) { + if (workspace.workspaceFolders?.some(f => f.uri.scheme === Schemes.Vsls)) { this.setReadonly(true); }