mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 18:48:45 -05:00
Constrains the active line hover to the start/end of a line
This commit is contained in:
@@ -1,302 +1,302 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Functions, Objects } from './system';
|
import { Functions, Objects } from './system';
|
||||||
import { DecorationOptions, DecorationInstanceRenderOptions, DecorationRenderOptions, Disposable, ExtensionContext, Range, StatusBarAlignment, StatusBarItem, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window, workspace } from 'vscode';
|
import { DecorationOptions, DecorationInstanceRenderOptions, DecorationRenderOptions, Disposable, ExtensionContext, Range, StatusBarAlignment, StatusBarItem, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window, workspace } from 'vscode';
|
||||||
import { BlameAnnotationController } from './blameAnnotationController';
|
import { BlameAnnotationController } from './blameAnnotationController';
|
||||||
import { BlameAnnotationFormat, BlameAnnotationFormatter } from './blameAnnotationFormatter';
|
import { BlameAnnotationFormat, BlameAnnotationFormatter } from './blameAnnotationFormatter';
|
||||||
import { TextEditorComparer } from './comparers';
|
import { TextEditorComparer } from './comparers';
|
||||||
import { IBlameConfig, IConfig, StatusBarCommand } from './configuration';
|
import { IBlameConfig, IConfig, StatusBarCommand } from './configuration';
|
||||||
import { DocumentSchemes, ExtensionKey } from './constants';
|
import { DocumentSchemes, ExtensionKey } from './constants';
|
||||||
import { BlameabilityChangeEvent, GitCommit, GitContextTracker, GitService, GitUri, IGitCommitLine } from './gitService';
|
import { BlameabilityChangeEvent, GitCommit, GitContextTracker, GitService, GitUri, IGitCommitLine } from './gitService';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
|
||||||
const activeLineDecoration: TextEditorDecorationType = window.createTextEditorDecorationType({
|
const activeLineDecoration: TextEditorDecorationType = window.createTextEditorDecorationType({
|
||||||
after: {
|
after: {
|
||||||
margin: '0 0 0 4em'
|
margin: '0 0 0 4em'
|
||||||
}
|
}
|
||||||
} as DecorationRenderOptions);
|
} as DecorationRenderOptions);
|
||||||
|
|
||||||
export class BlameActiveLineController extends Disposable {
|
export class BlameActiveLineController extends Disposable {
|
||||||
|
|
||||||
private _activeEditorLineDisposable: Disposable | undefined;
|
private _activeEditorLineDisposable: Disposable | undefined;
|
||||||
private _blameable: boolean;
|
private _blameable: boolean;
|
||||||
private _config: IConfig;
|
private _config: IConfig;
|
||||||
private _currentLine: number = -1;
|
private _currentLine: number = -1;
|
||||||
private _disposable: Disposable;
|
private _disposable: Disposable;
|
||||||
private _editor: TextEditor | undefined;
|
private _editor: TextEditor | undefined;
|
||||||
private _statusBarItem: StatusBarItem | undefined;
|
private _statusBarItem: StatusBarItem | undefined;
|
||||||
private _updateBlameDebounced: (line: number, editor: TextEditor) => Promise<void>;
|
private _updateBlameDebounced: (line: number, editor: TextEditor) => Promise<void>;
|
||||||
private _uri: GitUri;
|
private _uri: GitUri;
|
||||||
|
|
||||||
constructor(context: ExtensionContext, private git: GitService, private gitContextTracker: GitContextTracker, private annotationController: BlameAnnotationController) {
|
constructor(context: ExtensionContext, private git: GitService, private gitContextTracker: GitContextTracker, private annotationController: BlameAnnotationController) {
|
||||||
super(() => this.dispose());
|
super(() => this.dispose());
|
||||||
|
|
||||||
this._updateBlameDebounced = Functions.debounce(this._updateBlame, 250);
|
this._updateBlameDebounced = Functions.debounce(this._updateBlame, 250);
|
||||||
|
|
||||||
this._onConfigurationChanged();
|
this._onConfigurationChanged();
|
||||||
|
|
||||||
const subscriptions: Disposable[] = [];
|
const subscriptions: Disposable[] = [];
|
||||||
|
|
||||||
subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigurationChanged, this));
|
subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigurationChanged, this));
|
||||||
subscriptions.push(git.onDidChangeGitCache(this._onGitCacheChanged, this));
|
subscriptions.push(git.onDidChangeGitCache(this._onGitCacheChanged, this));
|
||||||
subscriptions.push(annotationController.onDidToggleBlameAnnotations(this._onBlameAnnotationToggled, this));
|
subscriptions.push(annotationController.onDidToggleBlameAnnotations(this._onBlameAnnotationToggled, this));
|
||||||
|
|
||||||
this._disposable = Disposable.from(...subscriptions);
|
this._disposable = Disposable.from(...subscriptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
this._editor && this._editor.setDecorations(activeLineDecoration, []);
|
this._editor && this._editor.setDecorations(activeLineDecoration, []);
|
||||||
|
|
||||||
this._activeEditorLineDisposable && this._activeEditorLineDisposable.dispose();
|
this._activeEditorLineDisposable && this._activeEditorLineDisposable.dispose();
|
||||||
this._statusBarItem && this._statusBarItem.dispose();
|
this._statusBarItem && this._statusBarItem.dispose();
|
||||||
this._disposable && this._disposable.dispose();
|
this._disposable && this._disposable.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onConfigurationChanged() {
|
private _onConfigurationChanged() {
|
||||||
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
|
||||||
|
|
||||||
let changed: boolean = false;
|
let changed: boolean = false;
|
||||||
|
|
||||||
if (!Objects.areEquivalent(cfg.statusBar, this._config && this._config.statusBar)) {
|
if (!Objects.areEquivalent(cfg.statusBar, this._config && this._config.statusBar)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
if (cfg.statusBar.enabled) {
|
if (cfg.statusBar.enabled) {
|
||||||
const alignment = cfg.statusBar.alignment !== 'left' ? StatusBarAlignment.Right : StatusBarAlignment.Left;
|
const alignment = cfg.statusBar.alignment !== 'left' ? StatusBarAlignment.Right : StatusBarAlignment.Left;
|
||||||
if (this._statusBarItem !== undefined && this._statusBarItem.alignment !== alignment) {
|
if (this._statusBarItem !== undefined && this._statusBarItem.alignment !== alignment) {
|
||||||
this._statusBarItem.dispose();
|
this._statusBarItem.dispose();
|
||||||
this._statusBarItem = undefined;
|
this._statusBarItem = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._statusBarItem = this._statusBarItem || window.createStatusBarItem(alignment, alignment === StatusBarAlignment.Right ? 1000 : 0);
|
this._statusBarItem = this._statusBarItem || window.createStatusBarItem(alignment, alignment === StatusBarAlignment.Right ? 1000 : 0);
|
||||||
this._statusBarItem.command = cfg.statusBar.command;
|
this._statusBarItem.command = cfg.statusBar.command;
|
||||||
}
|
}
|
||||||
else if (!cfg.statusBar.enabled && this._statusBarItem) {
|
else if (!cfg.statusBar.enabled && this._statusBarItem) {
|
||||||
this._statusBarItem.dispose();
|
this._statusBarItem.dispose();
|
||||||
this._statusBarItem = undefined;
|
this._statusBarItem = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Objects.areEquivalent(cfg.blame.annotation.activeLine, this._config && this._config.blame.annotation.activeLine)) {
|
if (!Objects.areEquivalent(cfg.blame.annotation.activeLine, this._config && this._config.blame.annotation.activeLine)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
if (cfg.blame.annotation.activeLine !== 'off' && this._editor) {
|
if (cfg.blame.annotation.activeLine !== 'off' && this._editor) {
|
||||||
this._editor.setDecorations(activeLineDecoration, []);
|
this._editor.setDecorations(activeLineDecoration, []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Objects.areEquivalent(cfg.blame.annotation.activeLineDarkColor, this._config && this._config.blame.annotation.activeLineDarkColor) ||
|
if (!Objects.areEquivalent(cfg.blame.annotation.activeLineDarkColor, this._config && this._config.blame.annotation.activeLineDarkColor) ||
|
||||||
!Objects.areEquivalent(cfg.blame.annotation.activeLineLightColor, this._config && this._config.blame.annotation.activeLineLightColor)) {
|
!Objects.areEquivalent(cfg.blame.annotation.activeLineLightColor, this._config && this._config.blame.annotation.activeLineLightColor)) {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._config = cfg;
|
this._config = cfg;
|
||||||
|
|
||||||
if (!changed) return;
|
if (!changed) return;
|
||||||
|
|
||||||
let trackActiveLine = cfg.statusBar.enabled || cfg.blame.annotation.activeLine !== 'off';
|
let trackActiveLine = cfg.statusBar.enabled || cfg.blame.annotation.activeLine !== 'off';
|
||||||
if (trackActiveLine && !this._activeEditorLineDisposable) {
|
if (trackActiveLine && !this._activeEditorLineDisposable) {
|
||||||
const subscriptions: Disposable[] = [];
|
const subscriptions: Disposable[] = [];
|
||||||
|
|
||||||
subscriptions.push(window.onDidChangeActiveTextEditor(this._onActiveTextEditorChanged, this));
|
subscriptions.push(window.onDidChangeActiveTextEditor(this._onActiveTextEditorChanged, this));
|
||||||
subscriptions.push(window.onDidChangeTextEditorSelection(this._onTextEditorSelectionChanged, this));
|
subscriptions.push(window.onDidChangeTextEditorSelection(this._onTextEditorSelectionChanged, this));
|
||||||
subscriptions.push(this.gitContextTracker.onDidBlameabilityChange(this._onBlameabilityChanged, this));
|
subscriptions.push(this.gitContextTracker.onDidBlameabilityChange(this._onBlameabilityChanged, this));
|
||||||
|
|
||||||
this._activeEditorLineDisposable = Disposable.from(...subscriptions);
|
this._activeEditorLineDisposable = Disposable.from(...subscriptions);
|
||||||
}
|
}
|
||||||
else if (!trackActiveLine && this._activeEditorLineDisposable) {
|
else if (!trackActiveLine && this._activeEditorLineDisposable) {
|
||||||
this._activeEditorLineDisposable.dispose();
|
this._activeEditorLineDisposable.dispose();
|
||||||
this._activeEditorLineDisposable = undefined;
|
this._activeEditorLineDisposable = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._onActiveTextEditorChanged(window.activeTextEditor);
|
this._onActiveTextEditorChanged(window.activeTextEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private isEditorBlameable(editor: TextEditor | undefined): boolean {
|
private isEditorBlameable(editor: TextEditor | undefined): boolean {
|
||||||
if (editor === undefined || editor.document === undefined) return false;
|
if (editor === undefined || editor.document === undefined) return false;
|
||||||
|
|
||||||
if (!this.git.isTrackable(editor.document.uri)) return false;
|
if (!this.git.isTrackable(editor.document.uri)) return false;
|
||||||
if (editor.document.isUntitled && editor.document.uri.scheme === DocumentSchemes.File) return false;
|
if (editor.document.isUntitled && editor.document.uri.scheme === DocumentSchemes.File) return false;
|
||||||
|
|
||||||
return this.git.isEditorBlameable(editor);
|
return this.git.isEditorBlameable(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _onActiveTextEditorChanged(editor: TextEditor | undefined) {
|
private async _onActiveTextEditorChanged(editor: TextEditor | undefined) {
|
||||||
this._currentLine = -1;
|
this._currentLine = -1;
|
||||||
|
|
||||||
const previousEditor = this._editor;
|
const previousEditor = this._editor;
|
||||||
previousEditor && previousEditor.setDecorations(activeLineDecoration, []);
|
previousEditor && previousEditor.setDecorations(activeLineDecoration, []);
|
||||||
|
|
||||||
if (editor === undefined || !this.isEditorBlameable(editor)) {
|
if (editor === undefined || !this.isEditorBlameable(editor)) {
|
||||||
this.clear(editor);
|
this.clear(editor);
|
||||||
|
|
||||||
this._editor = undefined;
|
this._editor = undefined;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._blameable = editor !== undefined && editor.document !== undefined && !editor.document.isDirty;
|
this._blameable = editor !== undefined && editor.document !== undefined && !editor.document.isDirty;
|
||||||
this._editor = editor;
|
this._editor = editor;
|
||||||
this._uri = await GitUri.fromUri(editor.document.uri, this.git);
|
this._uri = await GitUri.fromUri(editor.document.uri, this.git);
|
||||||
|
|
||||||
const maxLines = this._config.advanced.caching.statusBar.maxLines;
|
const maxLines = this._config.advanced.caching.statusBar.maxLines;
|
||||||
// If caching is on and the file is small enough -- kick off a blame for the whole file
|
// If caching is on and the file is small enough -- kick off a blame for the whole file
|
||||||
if (this._config.advanced.caching.enabled && (maxLines <= 0 || editor.document.lineCount <= maxLines)) {
|
if (this._config.advanced.caching.enabled && (maxLines <= 0 || editor.document.lineCount <= maxLines)) {
|
||||||
this.git.getBlameForFile(this._uri);
|
this.git.getBlameForFile(this._uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._updateBlame(editor.selection.active.line, editor);
|
this._updateBlame(editor.selection.active.line, editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onBlameabilityChanged(e: BlameabilityChangeEvent) {
|
private _onBlameabilityChanged(e: BlameabilityChangeEvent) {
|
||||||
this._blameable = e.blameable;
|
this._blameable = e.blameable;
|
||||||
if (!e.blameable || !this._editor) {
|
if (!e.blameable || !this._editor) {
|
||||||
this.clear(e.editor);
|
this.clear(e.editor);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure this is for the editor we are tracking
|
// Make sure this is for the editor we are tracking
|
||||||
if (!TextEditorComparer.equals(this._editor, e.editor)) return;
|
if (!TextEditorComparer.equals(this._editor, e.editor)) return;
|
||||||
|
|
||||||
this._updateBlame(this._editor.selection.active.line, this._editor);
|
this._updateBlame(this._editor.selection.active.line, this._editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onBlameAnnotationToggled() {
|
private _onBlameAnnotationToggled() {
|
||||||
this._onActiveTextEditorChanged(window.activeTextEditor);
|
this._onActiveTextEditorChanged(window.activeTextEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onGitCacheChanged() {
|
private _onGitCacheChanged() {
|
||||||
this._onActiveTextEditorChanged(window.activeTextEditor);
|
this._onActiveTextEditorChanged(window.activeTextEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _onTextEditorSelectionChanged(e: TextEditorSelectionChangeEvent): Promise<void> {
|
private async _onTextEditorSelectionChanged(e: TextEditorSelectionChangeEvent): Promise<void> {
|
||||||
// Make sure this is for the editor we are tracking
|
// Make sure this is for the editor we are tracking
|
||||||
if (!this._blameable || !TextEditorComparer.equals(this._editor, e.textEditor)) return;
|
if (!this._blameable || !TextEditorComparer.equals(this._editor, e.textEditor)) return;
|
||||||
|
|
||||||
const line = e.selections[0].active.line;
|
const line = e.selections[0].active.line;
|
||||||
if (line === this._currentLine) return;
|
if (line === this._currentLine) return;
|
||||||
this._currentLine = line;
|
this._currentLine = line;
|
||||||
|
|
||||||
if (!this._uri && e.textEditor) {
|
if (!this._uri && e.textEditor) {
|
||||||
this._uri = await GitUri.fromUri(e.textEditor.document.uri, this.git);
|
this._uri = await GitUri.fromUri(e.textEditor.document.uri, this.git);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._updateBlameDebounced(line, e.textEditor);
|
this._updateBlameDebounced(line, e.textEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _updateBlame(line: number, editor: TextEditor) {
|
private async _updateBlame(line: number, editor: TextEditor) {
|
||||||
line = line - this._uri.offset;
|
line = line - this._uri.offset;
|
||||||
|
|
||||||
let commit: GitCommit | undefined = undefined;
|
let commit: GitCommit | undefined = undefined;
|
||||||
let commitLine: IGitCommitLine | undefined = undefined;
|
let commitLine: IGitCommitLine | undefined = undefined;
|
||||||
// Since blame information isn't valid when there are unsaved changes -- don't show any status
|
// Since blame information isn't valid when there are unsaved changes -- don't show any status
|
||||||
if (this._blameable && line >= 0) {
|
if (this._blameable && line >= 0) {
|
||||||
const blameLine = await this.git.getBlameForLine(this._uri, line);
|
const blameLine = await this.git.getBlameForLine(this._uri, line);
|
||||||
commitLine = blameLine === undefined ? undefined : blameLine.line;
|
commitLine = blameLine === undefined ? undefined : blameLine.line;
|
||||||
commit = blameLine === undefined ? undefined : blameLine.commit;
|
commit = blameLine === undefined ? undefined : blameLine.commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commit !== undefined && commitLine !== undefined) {
|
if (commit !== undefined && commitLine !== undefined) {
|
||||||
this.show(commit, commitLine, editor);
|
this.show(commit, commitLine, editor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.clear(editor);
|
this.clear(editor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clear(editor: TextEditor | undefined, previousEditor?: TextEditor) {
|
clear(editor: TextEditor | undefined, previousEditor?: TextEditor) {
|
||||||
editor && editor.setDecorations(activeLineDecoration, []);
|
editor && editor.setDecorations(activeLineDecoration, []);
|
||||||
// I have no idea why the decorators sometimes don't get removed, but if they don't try again with a tiny delay
|
// I have no idea why the decorators sometimes don't get removed, but if they don't try again with a tiny delay
|
||||||
if (editor) {
|
if (editor) {
|
||||||
setTimeout(() => editor.setDecorations(activeLineDecoration, []), 1);
|
setTimeout(() => editor.setDecorations(activeLineDecoration, []), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._statusBarItem && this._statusBarItem.hide();
|
this._statusBarItem && this._statusBarItem.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
async show(commit: GitCommit, blameLine: IGitCommitLine, editor: TextEditor) {
|
async show(commit: GitCommit, blameLine: IGitCommitLine, editor: TextEditor) {
|
||||||
// I have no idea why I need this protection -- but it happens
|
// I have no idea why I need this protection -- but it happens
|
||||||
if (!editor.document) return;
|
if (!editor.document) return;
|
||||||
|
|
||||||
if (this._config.statusBar.enabled && this._statusBarItem !== undefined) {
|
if (this._config.statusBar.enabled && this._statusBarItem !== undefined) {
|
||||||
switch (this._config.statusBar.date) {
|
switch (this._config.statusBar.date) {
|
||||||
case 'off':
|
case 'off':
|
||||||
this._statusBarItem.text = `$(git-commit) ${commit.author}`;
|
this._statusBarItem.text = `$(git-commit) ${commit.author}`;
|
||||||
break;
|
break;
|
||||||
case 'absolute':
|
case 'absolute':
|
||||||
const dateFormat = this._config.statusBar.dateFormat || 'MMMM Do, YYYY h:MMa';
|
const dateFormat = this._config.statusBar.dateFormat || 'MMMM Do, YYYY h:MMa';
|
||||||
let date: string;
|
let date: string;
|
||||||
try {
|
try {
|
||||||
date = moment(commit.date).format(dateFormat);
|
date = moment(commit.date).format(dateFormat);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
date = moment(commit.date).format('MMMM Do, YYYY h:MMa');
|
date = moment(commit.date).format('MMMM Do, YYYY h:MMa');
|
||||||
}
|
}
|
||||||
this._statusBarItem.text = `$(git-commit) ${commit.author}, ${date}`;
|
this._statusBarItem.text = `$(git-commit) ${commit.author}, ${date}`;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this._statusBarItem.text = `$(git-commit) ${commit.author}, ${moment(commit.date).fromNow()}`;
|
this._statusBarItem.text = `$(git-commit) ${commit.author}, ${moment(commit.date).fromNow()}`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (this._config.statusBar.command) {
|
switch (this._config.statusBar.command) {
|
||||||
case StatusBarCommand.BlameAnnotate:
|
case StatusBarCommand.BlameAnnotate:
|
||||||
this._statusBarItem.tooltip = 'Toggle Blame Annotations';
|
this._statusBarItem.tooltip = 'Toggle Blame Annotations';
|
||||||
break;
|
break;
|
||||||
case StatusBarCommand.ShowBlameHistory:
|
case StatusBarCommand.ShowBlameHistory:
|
||||||
this._statusBarItem.tooltip = 'Open Blame History Explorer';
|
this._statusBarItem.tooltip = 'Open Blame History Explorer';
|
||||||
break;
|
break;
|
||||||
case StatusBarCommand.ShowFileHistory:
|
case StatusBarCommand.ShowFileHistory:
|
||||||
this._statusBarItem.tooltip = 'Open File History Explorer';
|
this._statusBarItem.tooltip = 'Open File History Explorer';
|
||||||
break;
|
break;
|
||||||
case StatusBarCommand.DiffWithPrevious:
|
case StatusBarCommand.DiffWithPrevious:
|
||||||
this._statusBarItem.tooltip = 'Compare with Previous Commit';
|
this._statusBarItem.tooltip = 'Compare with Previous Commit';
|
||||||
break;
|
break;
|
||||||
case StatusBarCommand.ToggleCodeLens:
|
case StatusBarCommand.ToggleCodeLens:
|
||||||
this._statusBarItem.tooltip = 'Toggle Git CodeLens';
|
this._statusBarItem.tooltip = 'Toggle Git CodeLens';
|
||||||
break;
|
break;
|
||||||
case StatusBarCommand.ShowQuickCommitDetails:
|
case StatusBarCommand.ShowQuickCommitDetails:
|
||||||
this._statusBarItem.tooltip = 'Show Commit Details';
|
this._statusBarItem.tooltip = 'Show Commit Details';
|
||||||
break;
|
break;
|
||||||
case StatusBarCommand.ShowQuickCommitFileDetails:
|
case StatusBarCommand.ShowQuickCommitFileDetails:
|
||||||
this._statusBarItem.tooltip = 'Show Line Commit Details';
|
this._statusBarItem.tooltip = 'Show Line Commit Details';
|
||||||
break;
|
break;
|
||||||
case StatusBarCommand.ShowQuickFileHistory:
|
case StatusBarCommand.ShowQuickFileHistory:
|
||||||
this._statusBarItem.tooltip = 'Show File History';
|
this._statusBarItem.tooltip = 'Show File History';
|
||||||
break;
|
break;
|
||||||
case StatusBarCommand.ShowQuickCurrentBranchHistory:
|
case StatusBarCommand.ShowQuickCurrentBranchHistory:
|
||||||
this._statusBarItem.tooltip = 'Show Branch History';
|
this._statusBarItem.tooltip = 'Show Branch History';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._statusBarItem.show();
|
this._statusBarItem.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._config.blame.annotation.activeLine !== 'off') {
|
if (this._config.blame.annotation.activeLine !== 'off') {
|
||||||
const activeLine = this._config.blame.annotation.activeLine;
|
const activeLine = this._config.blame.annotation.activeLine;
|
||||||
const offset = this._uri.offset;
|
const offset = this._uri.offset;
|
||||||
|
|
||||||
const cfg = {
|
const cfg = {
|
||||||
annotation: {
|
annotation: {
|
||||||
sha: true,
|
sha: true,
|
||||||
author: this._config.statusBar.enabled ? false : this._config.blame.annotation.author,
|
author: this._config.statusBar.enabled ? false : this._config.blame.annotation.author,
|
||||||
date: this._config.statusBar.enabled ? 'off' : this._config.blame.annotation.date,
|
date: this._config.statusBar.enabled ? 'off' : this._config.blame.annotation.date,
|
||||||
message: true
|
message: true
|
||||||
}
|
}
|
||||||
} as IBlameConfig;
|
} as IBlameConfig;
|
||||||
|
|
||||||
const annotation = BlameAnnotationFormatter.getAnnotation(cfg, commit, BlameAnnotationFormat.Unconstrained);
|
const annotation = BlameAnnotationFormatter.getAnnotation(cfg, commit, BlameAnnotationFormat.Unconstrained);
|
||||||
|
|
||||||
// Get the full commit message -- since blame only returns the summary
|
// Get the full commit message -- since blame only returns the summary
|
||||||
let logCommit: GitCommit | undefined = undefined;
|
let logCommit: GitCommit | undefined = undefined;
|
||||||
if (!commit.isUncommitted) {
|
if (!commit.isUncommitted) {
|
||||||
logCommit = await this.git.getLogCommit(this._uri.repoPath, this._uri.fsPath, commit.sha);
|
logCommit = await this.git.getLogCommit(this._uri.repoPath, this._uri.fsPath, commit.sha);
|
||||||
}
|
}
|
||||||
|
|
||||||
// I have no idea why I need this protection -- but it happens
|
// I have no idea why I need this protection -- but it happens
|
||||||
if (!editor.document) return;
|
if (!editor.document) return;
|
||||||
|
|
||||||
let hoverMessage: string | string[] | undefined = undefined;
|
let hoverMessage: string | string[] | undefined = undefined;
|
||||||
if (activeLine !== 'inline') {
|
if (activeLine !== 'inline') {
|
||||||
// If the messages match (or we couldn't find the log), then this is a possible duplicate annotation
|
// If the messages match (or we couldn't find the log), then this is a possible duplicate annotation
|
||||||
const possibleDuplicate = !logCommit || logCommit.message === commit.message;
|
const possibleDuplicate = !logCommit || logCommit.message === commit.message;
|
||||||
// If we don't have a possible dupe or we aren't showing annotations get the hover message
|
// If we don't have a possible dupe or we aren't showing annotations get the hover message
|
||||||
if (!commit.isUncommitted && (!possibleDuplicate || !this.annotationController.isAnnotating(editor))) {
|
if (!commit.isUncommitted && (!possibleDuplicate || !this.annotationController.isAnnotating(editor))) {
|
||||||
hoverMessage = BlameAnnotationFormatter.getAnnotationHover(cfg, blameLine, logCommit || commit);
|
hoverMessage = BlameAnnotationFormatter.getAnnotationHover(cfg, blameLine, logCommit || commit);
|
||||||
|
|
||||||
// if (commit.previousSha !== undefined) {
|
// if (commit.previousSha !== undefined) {
|
||||||
// const changes = await this.git.getDiffForLine(this._uri.repoPath, this._uri.fsPath, blameLine.line + offset, commit.previousSha);
|
// const changes = await this.git.getDiffForLine(this._uri.repoPath, this._uri.fsPath, blameLine.line + offset, commit.previousSha);
|
||||||
@@ -310,7 +310,7 @@ export class BlameActiveLineController extends Disposable {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
else if (commit.isUncommitted) {
|
else if (commit.isUncommitted) {
|
||||||
const changes = await this.git.getDiffForLine(this._uri.repoPath, this._uri.fsPath, blameLine.line + offset);
|
const changes = await this.git.getDiffForLine(this._uri.repoPath, this._uri.fsPath, blameLine.line + offset);
|
||||||
if (changes !== undefined) {
|
if (changes !== undefined) {
|
||||||
@@ -324,44 +324,62 @@ export class BlameActiveLineController extends Disposable {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let decorationOptions: DecorationOptions | undefined = undefined;
|
let decorationOptions: [DecorationOptions] | undefined = undefined;
|
||||||
switch (activeLine) {
|
switch (activeLine) {
|
||||||
case 'both':
|
case 'both':
|
||||||
case 'inline':
|
case 'inline':
|
||||||
decorationOptions = {
|
const range = editor.document.validateRange(new Range(blameLine.line + offset, 0, blameLine.line + offset, 1000000));
|
||||||
range: editor.document.validateRange(new Range(blameLine.line + offset, 0, blameLine.line + offset, 1000000)),
|
decorationOptions = [
|
||||||
hoverMessage: hoverMessage,
|
{
|
||||||
renderOptions: {
|
range: range.with({
|
||||||
after: {
|
start: range.start.with({
|
||||||
contentText: annotation
|
character: range.end.character
|
||||||
},
|
})
|
||||||
dark: {
|
}),
|
||||||
after: {
|
hoverMessage: hoverMessage,
|
||||||
color: this._config.blame.annotation.activeLineDarkColor || 'rgba(153, 153, 153, 0.35)'
|
renderOptions: {
|
||||||
}
|
after: {
|
||||||
},
|
contentText: annotation
|
||||||
light: {
|
},
|
||||||
after: {
|
dark: {
|
||||||
color: this._config.blame.annotation.activeLineLightColor || 'rgba(153, 153, 153, 0.35)'
|
after: {
|
||||||
}
|
color: this._config.blame.annotation.activeLineDarkColor || 'rgba(153, 153, 153, 0.35)'
|
||||||
}
|
}
|
||||||
} as DecorationInstanceRenderOptions
|
},
|
||||||
} as DecorationOptions;
|
light: {
|
||||||
break;
|
after: {
|
||||||
|
color: this._config.blame.annotation.activeLineLightColor || 'rgba(153, 153, 153, 0.35)'
|
||||||
case 'hover':
|
}
|
||||||
decorationOptions = {
|
}
|
||||||
range: editor.document.validateRange(new Range(blameLine.line + offset, 0, blameLine.line + offset, 1000000)),
|
} as DecorationInstanceRenderOptions
|
||||||
hoverMessage: hoverMessage
|
} as DecorationOptions,
|
||||||
} as DecorationOptions;
|
// Add a hover decoration to the area between the start of the line and the first non-whitespace character
|
||||||
break;
|
{
|
||||||
}
|
range: range.with({
|
||||||
|
end: range.end.with({
|
||||||
if (decorationOptions !== undefined) {
|
character: editor.document.lineAt(range.end.line).firstNonWhitespaceCharacterIndex
|
||||||
editor.setDecorations(activeLineDecoration, [decorationOptions]);
|
})
|
||||||
}
|
}),
|
||||||
}
|
hoverMessage: hoverMessage
|
||||||
}
|
} as DecorationOptions
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'hover':
|
||||||
|
decorationOptions = [
|
||||||
|
{
|
||||||
|
range: editor.document.validateRange(new Range(blameLine.line + offset, 0, blameLine.line + offset, 1000000)),
|
||||||
|
hoverMessage: hoverMessage
|
||||||
|
} as DecorationOptions
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (decorationOptions !== undefined) {
|
||||||
|
editor.setDecorations(activeLineDecoration, decorationOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user