From d6519fea195912d5563a952c23474ae74297bbaa Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 31 Jul 2020 02:44:36 -0400 Subject: [PATCH] Fixes changes hover diff in revisions --- src/hovers/hovers.ts | 4 ++-- src/hovers/lineHoverController.ts | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/hovers/hovers.ts b/src/hovers/hovers.ts index 3b1979f..87bbdec 100644 --- a/src/hovers/hovers.ts +++ b/src/hovers/hovers.ts @@ -34,7 +34,7 @@ export namespace Hovers { ref = documentRef; } } else { - ref = commit.sha; + ref = documentRef ? commit.previousSha : commit.sha; } const line = editorLine + 1; @@ -49,7 +49,7 @@ export namespace Hovers { editorLine = commitLine.originalLine - 1; // TODO: Doesn't work with dirty files -- pass in editor? or contents? - hunkLine = await Container.git.getDiffForLine(uri, editorLine, ref, undefined, originalFileName); + hunkLine = await Container.git.getDiffForLine(uri, editorLine, ref, uri.sha, originalFileName); // If we didn't find a diff & ref is undefined (meaning uncommitted), check for a staged diff if (hunkLine == null && ref == null) { diff --git a/src/hovers/lineHoverController.ts b/src/hovers/lineHoverController.ts index b298e64..341f3af 100644 --- a/src/hovers/lineHoverController.ts +++ b/src/hovers/lineHoverController.ts @@ -68,7 +68,7 @@ export class LineHoverController implements Disposable { private onActiveLinesChanged(e: LinesChangeEvent) { if (e.pending) return; - if (e.editor === undefined || e.lines === undefined) { + if (e.editor == null || e.lines == null) { this.unregister(); return; @@ -94,8 +94,8 @@ export class LineHoverController implements Disposable { if (!Container.lineTracker.includes(position.line)) return undefined; const lineState = Container.lineTracker.getState(position.line); - const commit = lineState !== undefined ? lineState.commit : undefined; - if (commit === undefined) return undefined; + const commit = lineState?.commit; + if (commit == null) return undefined; // Avoid double annotations if we are showing the whole-file hover blame annotations if (Container.config.hovers.annotations.details) { @@ -113,17 +113,17 @@ export class LineHoverController implements Disposable { if (!wholeLine && range.start.character !== position.character) return undefined; // Get the full commit message -- since blame only returns the summary - let logCommit = lineState !== undefined ? lineState.logCommit : undefined; - if (logCommit === undefined && !commit.isUncommitted) { + let logCommit = lineState?.logCommit; + if (logCommit == null && !commit.isUncommitted) { logCommit = await Container.git.getCommitForFile(commit.repoPath, commit.uri.fsPath, { ref: commit.sha, }); - if (logCommit !== undefined) { + if (logCommit != null) { // Preserve the previous commit from the blame commit logCommit.previousSha = commit.previousSha; logCommit.previousFileName = commit.previousFileName; - if (lineState !== undefined) { + if (lineState != null) { lineState.logCommit = logCommit; } } @@ -135,7 +135,7 @@ export class LineHoverController implements Disposable { editorLine = commitLine.originalLine - 1; const trackedDocument = await Container.tracker.get(document); - if (trackedDocument === undefined) return undefined; + if (trackedDocument == null) return undefined; const message = await Hovers.detailsMessage( logCommit ?? commit, @@ -161,8 +161,8 @@ export class LineHoverController implements Disposable { if (!Container.lineTracker.includes(position.line)) return undefined; const lineState = Container.lineTracker.getState(position.line); - const commit = lineState !== undefined ? lineState.commit : undefined; - if (commit === undefined) return undefined; + const commit = lineState?.commit; + if (commit == null) return undefined; // Avoid double annotations if we are showing the whole-file hover blame annotations if (Container.config.hovers.annotations.changes) { @@ -180,22 +180,22 @@ export class LineHoverController implements Disposable { if (!wholeLine && range.start.character !== position.character) return undefined; const trackedDocument = await Container.tracker.get(document); - if (trackedDocument === undefined) return undefined; + if (trackedDocument == null) return undefined; const message = await Hovers.changesMessage(commit, trackedDocument.uri, position.line); - if (message === undefined) return undefined; + if (message == null) return undefined; return new Hover(message, range); } private isRegistered(uri: Uri | undefined) { - return this._hoverProviderDisposable !== undefined && UriComparer.equals(this._uri, uri); + return this._hoverProviderDisposable != null && UriComparer.equals(this._uri, uri); } private register(editor: TextEditor | undefined) { this.unregister(); - if (editor === undefined) return; + if (editor == null) return; const cfg = Container.config.hovers; if (!cfg.enabled || !cfg.currentLine.enabled || (!cfg.currentLine.details && !cfg.currentLine.changes)) return; @@ -229,7 +229,7 @@ export class LineHoverController implements Disposable { private unregister() { this._uri = undefined; - if (this._hoverProviderDisposable !== undefined) { + if (this._hoverProviderDisposable != null) { this._hoverProviderDisposable.dispose(); this._hoverProviderDisposable = undefined; }