From 58c53b578d88d116fa0196ed56753da2f38f18e4 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 30 Mar 2022 12:42:30 -0400 Subject: [PATCH] Fixes CodeLens jumping on virtual files --- src/codelens/codeLensProvider.ts | 4 ++++ src/git/gitProviderService.ts | 2 +- src/git/gitUri.ts | 3 ++- src/plus/github/githubGitProvider.ts | 15 +++++++++++++-- src/system/utils.ts | 4 ++++ src/views/nodes/fileHistoryTrackerNode.ts | 5 +++-- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/codelens/codeLensProvider.ts b/src/codelens/codeLensProvider.ts index c1663e7..6fb04db 100644 --- a/src/codelens/codeLensProvider.ts +++ b/src/codelens/codeLensProvider.ts @@ -41,6 +41,7 @@ import { Logger } from '../logger'; import { asCommand, executeCoreCommand } from '../system/command'; import { is, once } from '../system/function'; import { filterMap, find, first, join, map } from '../system/iterable'; +import { isVirtualUri } from '../system/utils'; export class GitRecentChangeCodeLens extends CodeLens { constructor( @@ -106,6 +107,9 @@ export class GitCodeLensProvider implements CodeLensProvider { } async provideCodeLenses(document: TextDocument, token: CancellationToken): Promise { + // Since we can't currently blame edited virtual documents, don't even attempt anything if dirty + if (document.isDirty && isVirtualUri(document.uri)) return []; + const trackedDocument = await this.container.tracker.getOrAdd(document); if (!trackedDocument.isBlameable) return []; diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 3fe42a2..e0abcfb 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -834,7 +834,7 @@ export class GitProviderService implements Disposable { throw new ProviderNotFoundError(repoPath); // let id = !isWeb ? GitProviderId.Git : undefined; - // if (typeof repoPath !== 'string' && repoPath.scheme === DocumentSchemes.Virtual) { + // if (typeof repoPath !== 'string' && repoPath.scheme === Schemes.Virtual) { // if (repoPath.authority.startsWith('github')) { // id = GitProviderId.GitHub; // } else { diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index a571ded..8bd19b9 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -10,6 +10,7 @@ import { memoize } from '../system/decorators/memoize'; import { formatPath } from '../system/formatPath'; import { basename, getBestPath, normalizePath, relativeDir, splitPath } from '../system/path'; // import { CharCode } from '../system/string'; +import { isVirtualUri } from '../system/utils'; import type { RevisionUriData } from './gitProvider'; import { GitFile, GitRevision } from './models'; @@ -83,7 +84,7 @@ export class GitUri extends (Uri as any as UriEx) { return; } - if (uri.scheme === Schemes.Virtual || uri.scheme === Schemes.GitHub) { + if (isVirtualUri(uri)) { super(uri); const [, owner, repo] = uri.path.split('/', 3); diff --git a/src/plus/github/githubGitProvider.ts b/src/plus/github/githubGitProvider.ts index 2f25581..40be0d0 100644 --- a/src/plus/github/githubGitProvider.ts +++ b/src/plus/github/githubGitProvider.ts @@ -2369,8 +2369,19 @@ export class GitHubGitProvider implements GitProvider, Disposable { return this.supportedSchemes.has(uri.scheme); } - isTracked(uri: Uri): Promise { - return Promise.resolve(this.isTrackable(uri) && this.container.git.getRepository(uri) != null); + async isTracked(uri: Uri): Promise { + if (!this.isTrackable(uri) || this.container.git.getRepository(uri) == null) return false; + + // Don't call out to RemoteHub to keep things more performant, since we only work with GitHub here + // const remotehub = await this.ensureRemoteHubApi(); + // if (remotehub == null) return false; + + // const providerUri = remotehub.getProviderUri(uri); + // if (providerUri == null) return false; + + const providerUri = uri.with({ scheme: Schemes.GitHub }); + const stats = await workspace.fs.stat(providerUri); + return stats != null; } @log() diff --git a/src/system/utils.ts b/src/system/utils.ts index fb98717..8eed3f6 100644 --- a/src/system/utils.ts +++ b/src/system/utils.ts @@ -71,6 +71,10 @@ export function isActiveDocument(document: TextDocument): boolean { return editor != null && editor.document === document; } +export function isVirtualUri(uri: Uri): boolean { + return uri.scheme === Schemes.Virtual || uri.scheme === Schemes.GitHub; +} + export function isVisibleDocument(document: TextDocument): boolean { if (window.visibleTextEditors.length === 0) return false; diff --git a/src/views/nodes/fileHistoryTrackerNode.ts b/src/views/nodes/fileHistoryTrackerNode.ts index 61d9d23..d188488 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, Schemes } from '../../constants'; +import { ContextKeys } from '../../constants'; import { setContext } from '../../context'; import { GitCommitish, GitUri } from '../../git/gitUri'; import { GitReference, GitRevision } from '../../git/models'; @@ -9,6 +9,7 @@ import { ReferencePicker } from '../../quickpicks/referencePicker'; import { gate } from '../../system/decorators/gate'; import { debug, log } from '../../system/decorators/log'; import { debounce, Deferrable } from '../../system/function'; +import { isVirtualUri } from '../../system/utils'; import { FileHistoryView } from '../fileHistoryView'; import { FileHistoryNode } from './fileHistoryNode'; import { ContextValues, SubscribeableViewNode, ViewNode } from './viewNode'; @@ -239,7 +240,7 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode this.triggerChange(), 1500); }