mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-14 12:08:33 -05:00
Fixes (read: hacks) blame with visible whitespace
Adds diff menu commands always Attempts to move the diff file to the correct line number Fixes code action provider -- works again Deletes deprecated code
This commit is contained in:
142
src/commands.ts
142
src/commands.ts
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
import {commands, DecorationOptions, Disposable, OverviewRulerLane, Position, Range, TextEditor, TextEditorEdit, TextEditorDecorationType, Uri, window} from 'vscode';
|
||||
import {Commands, VsCodeCommands} from './constants';
|
||||
import {BuiltInCommands, Commands} from './constants';
|
||||
import GitProvider from './gitProvider';
|
||||
import GitBlameController from './gitBlameController';
|
||||
import {basename} from 'path';
|
||||
@@ -36,6 +36,56 @@ abstract class EditorCommand extends Disposable {
|
||||
abstract execute(editor: TextEditor, edit: TextEditorEdit, ...args): any;
|
||||
}
|
||||
|
||||
export class DiffWithPreviousCommand extends EditorCommand {
|
||||
constructor(private git: GitProvider) {
|
||||
super(Commands.DiffWithPrevious);
|
||||
}
|
||||
|
||||
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string, compareWithSha?: string, line?: number) {
|
||||
line = line || editor.selection.active.line;
|
||||
if (!sha) {
|
||||
return this.git.getBlameForLine(uri.path, line)
|
||||
.then(blame => commands.executeCommand(Commands.DiffWithPrevious, uri, blame.commit.sha, blame.commit.previousSha));
|
||||
}
|
||||
|
||||
if (!compareWithSha) {
|
||||
return window.showInformationMessage(`Commit ${sha} has no previous commit`);
|
||||
}
|
||||
|
||||
return Promise.all([this.git.getVersionedFile(uri.path, sha), this.git.getVersionedFile(uri.path, compareWithSha)])
|
||||
.then(values => {
|
||||
const [source, compare] = values;
|
||||
const fileName = basename(uri.path);
|
||||
return commands.executeCommand(BuiltInCommands.Diff, Uri.file(compare), Uri.file(source), `${fileName} (${compareWithSha}) ↔ ${fileName} (${sha})`)
|
||||
// TODO: Moving doesn't always seem to work -- or more accurately it seems like it moves down that number of lines from the current line
|
||||
// which for a diff could be the first difference
|
||||
.then(() => commands.executeCommand(BuiltInCommands.CursorMove, { to: 'down', value: line }));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class DiffWithWorkingCommand extends EditorCommand {
|
||||
constructor(private git: GitProvider) {
|
||||
super(Commands.DiffWithWorking);
|
||||
}
|
||||
|
||||
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string, line?: number) {
|
||||
line = line || editor.selection.active.line;
|
||||
if (!sha) {
|
||||
return this.git.getBlameForLine(uri.path, line)
|
||||
.then(blame => commands.executeCommand(Commands.DiffWithWorking, uri, blame.commit.sha));
|
||||
};
|
||||
|
||||
return this.git.getVersionedFile(uri.path, sha).then(compare => {
|
||||
const fileName = basename(uri.path);
|
||||
return commands.executeCommand(BuiltInCommands.Diff, Uri.file(compare), uri, `${fileName} (${sha}) ↔ ${fileName} (index)`)
|
||||
// TODO: Moving doesn't always seem to work -- or more accurately it seems like it moves down that number of lines from the current line
|
||||
// which for a diff could be the first difference
|
||||
.then(() => commands.executeCommand(BuiltInCommands.CursorMove, { to: 'down', value: line }));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class ShowBlameCommand extends EditorCommand {
|
||||
constructor(private git: GitProvider, private blameController: GitBlameController) {
|
||||
super(Commands.ShowBlame);
|
||||
@@ -52,6 +102,30 @@ export class ShowBlameCommand extends EditorCommand {
|
||||
}
|
||||
}
|
||||
|
||||
export class ShowBlameHistoryCommand extends EditorCommand {
|
||||
constructor(private git: GitProvider) {
|
||||
super(Commands.ShowBlameHistory);
|
||||
}
|
||||
|
||||
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, range?: Range, position?: Position) {
|
||||
// If the command is executed manually -- treat it as a click on the root lens (i.e. show blame for the whole file)
|
||||
if (!uri) {
|
||||
const doc = editor.document;
|
||||
if (doc) {
|
||||
uri = doc.uri;
|
||||
range = doc.validateRange(new Range(0, 0, 1000000, 1000000));
|
||||
position = doc.validateRange(new Range(0, 0, 0, 1000000)).start;
|
||||
}
|
||||
|
||||
if (!uri) return;
|
||||
}
|
||||
|
||||
return this.git.getBlameLocations(uri.path, range).then(locations => {
|
||||
return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class ToggleBlameCommand extends EditorCommand {
|
||||
constructor(private git: GitProvider, private blameController: GitBlameController) {
|
||||
super(Commands.ToggleBlame);
|
||||
@@ -66,70 +140,4 @@ export class ToggleBlameCommand extends EditorCommand {
|
||||
return this.git.getBlameForLine(editor.document.fileName, activeLine)
|
||||
.then(blame => this.blameController.toggleBlame(editor, blame.commit.sha));
|
||||
}
|
||||
}
|
||||
|
||||
export class ShowHistoryCommand extends EditorCommand {
|
||||
constructor(private git: GitProvider) {
|
||||
super(Commands.ShowHistory);
|
||||
}
|
||||
|
||||
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, range?: Range, position?: Position) {
|
||||
// If the command is executed manually -- treat it as a click on the root lens (i.e. show blame for the whole file)
|
||||
if (!uri) {
|
||||
const doc = editor.document;
|
||||
if (doc) {
|
||||
uri = doc.uri;
|
||||
range = doc.validateRange(new Range(0, 0, 1000000, 1000000));
|
||||
position = doc.validateRange(new Range(0, 0, 0, 1000000)).start;
|
||||
}
|
||||
|
||||
if (!uri) return;
|
||||
}
|
||||
|
||||
return this.git.getBlameLocations(uri.path, range).then(locations => {
|
||||
return commands.executeCommand(VsCodeCommands.ShowReferences, uri, position, locations);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class DiffWithPreviousCommand extends EditorCommand {
|
||||
constructor(private git: GitProvider) {
|
||||
super(Commands.DiffWithPrevious);
|
||||
}
|
||||
|
||||
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string, compareWithSha?: string) {
|
||||
if (!sha) {
|
||||
return this.git.getBlameForLine(uri.path, editor.selection.active.line)
|
||||
.then(blame => commands.executeCommand(Commands.DiffWithPrevious, uri, blame.commit.sha, blame.commit.previousSha));
|
||||
}
|
||||
|
||||
if (!compareWithSha) {
|
||||
return window.showInformationMessage(`Commit ${sha} has no previous commit`);
|
||||
}
|
||||
|
||||
return Promise.all([this.git.getVersionedFile(uri.path, sha), this.git.getVersionedFile(uri.path, compareWithSha)])
|
||||
.then(values => {
|
||||
const [source, compare] = values;
|
||||
const fileName = basename(uri.path);
|
||||
return commands.executeCommand(VsCodeCommands.Diff, Uri.file(compare), Uri.file(source), `${fileName} (${compareWithSha}) ↔ ${fileName} (${sha})`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class DiffWithWorkingCommand extends EditorCommand {
|
||||
constructor(private git: GitProvider) {
|
||||
super(Commands.DiffWithWorking);
|
||||
}
|
||||
|
||||
execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, sha?: string) {
|
||||
if (!sha) {
|
||||
return this.git.getBlameForLine(uri.path, editor.selection.active.line)
|
||||
.then(blame => commands.executeCommand(Commands.DiffWithWorking, uri, blame.commit.sha));
|
||||
};
|
||||
|
||||
return this.git.getVersionedFile(uri.path, sha).then(compare => {
|
||||
const fileName = basename(uri.path);
|
||||
return commands.executeCommand(VsCodeCommands.Diff, Uri.file(compare), uri, `${fileName} (${sha}) ↔ ${fileName} (index)`);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user