Browse Source

Fixes changes hover diff in revisions

main
Eric Amodio 4 years ago
parent
commit
d6519fea19
2 changed files with 17 additions and 17 deletions
  1. +2
    -2
      src/hovers/hovers.ts
  2. +15
    -15
      src/hovers/lineHoverController.ts

+ 2
- 2
src/hovers/hovers.ts View File

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

+ 15
- 15
src/hovers/lineHoverController.ts View File

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

Loading…
Cancel
Save