Bläddra i källkod

Changes DocumentSchemes to just Schemes

main
Eric Amodio 2 år sedan
förälder
incheckning
8d8ba961cc
15 ändrade filer med 61 tillägg och 75 borttagningar
  1. +9
    -9
      src/codelens/codeLensProvider.ts
  2. +2
    -2
      src/commands/common.ts
  3. +2
    -2
      src/constants.ts
  4. +7
    -7
      src/env/node/git/localGitProvider.ts
  5. +3
    -3
      src/env/node/git/vslsGitProvider.ts
  6. +2
    -2
      src/git/fsProvider.ts
  7. +2
    -9
      src/git/gitProviderService.ts
  8. +7
    -7
      src/git/gitUri.ts
  9. +2
    -2
      src/git/models/repository.ts
  10. +5
    -9
      src/premium/github/githubGitProvider.ts
  11. +8
    -8
      src/repositories.ts
  12. +2
    -2
      src/system/path.ts
  13. +6
    -6
      src/system/trie.ts
  14. +2
    -5
      src/views/nodes/fileHistoryTrackerNode.ts
  15. +2
    -2
      src/vsls/vsls.ts

+ 9
- 9
src/codelens/codeLensProvider.ts Visa fil

@ -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<void>();

+ 2
- 2
src/commands/common.ts Visa fil

@ -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;

+ 2
- 2
src/constants.ts Visa fil

@ -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 {

+ 7
- 7
src/env/node/git/localGitProvider.ts Visa fil

@ -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<string> = 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<Repository[]> {
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,

+ 3
- 3
src/env/node/git/vslsGitProvider.ts Visa fil

@ -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<string> = new Set([DocumentSchemes.Vsls, DocumentSchemes.VslsScc]);
override readonly supportedSchemes: Set<string> = new Set([Schemes.Vsls, Schemes.VslsScc]);
override async discoverRepositories(uri: Uri): Promise<Repository[]> {
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 });
}

+ 2
- 2
src/git/fsProvider.ts Visa fil

@ -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,
}),

+ 2
- 9
src/git/gitProviderService.ts Visa fil

@ -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);
}

+ 7
- 7
src/git/gitUri.ts Visa fil

@ -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<GitUri> {
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

+ 2
- 2
src/git/models/repository.ts Visa fil

@ -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 {

+ 5
- 9
src/premium/github/githubGitProvider.ts Visa fil

@ -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<string> = new Set([
DocumentSchemes.Virtual,
DocumentSchemes.GitHub,
DocumentSchemes.PRs,
]);
readonly supportedSchemes: Set<string> = new Set([Schemes.Virtual, Schemes.GitHub, Schemes.PRs]);
private _onDidChangeRepository = new EventEmitter<RepositoryChangeEvent>();
get onDidChangeRepository(): Event<RepositoryChangeEvent> {
@ -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<GitHubAuthorityMetadata>('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);

+ 8
- 8
src/repositories.ts Visa fil

@ -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);

+ 2
- 2
src/system/path.ts Visa fil

@ -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 {

+ 6
- 6
src/system/trie.ts Visa fil

@ -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);

+ 2
- 5
src/views/nodes/fileHistoryTrackerNode.ts Visa fil

@ -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
// If we are losing the active editor, give more time before assuming its really gone
// For virtual repositories the active editor event takes a while to fire
// Ultimately we need to be using the upcoming Tabs api to avoid this
if (
editor == null &&
(this._uri?.scheme === DocumentSchemes.Virtual || this._uri?.scheme === DocumentSchemes.GitHub)
) {
if (editor == null && (this._uri?.scheme === Schemes.Virtual || this._uri?.scheme === Schemes.GitHub)) {
if (this._triggerChangeDebounced == null) {
this._triggerChangeDebounced = debounce(() => this.triggerChange(), 1500);
}

+ 2
- 2
src/vsls/vsls.ts Visa fil

@ -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);
}

Laddar…
Avbryt
Spara