Skip to content

Commit

Permalink
Fixes changes hover diff in revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jul 31, 2020
1 parent 2bdccf5 commit d6519fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/hovers/hovers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export namespace Hovers {
ref = documentRef;
}
} else {
ref = commit.sha;
ref = documentRef ? commit.previousSha : commit.sha;
}

const line = editorLine + 1;
Expand All @@ -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) {
Expand Down
30 changes: 15 additions & 15 deletions src/hovers/lineHoverController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}
}
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d6519fe

Please sign in to comment.