mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
adds process and make more proper help view
This commit is contained in:
parent
972539fff9
commit
ba9cb3d798
@ -1,11 +1,6 @@
|
||||
|
||||
## TODO: make options MENU also. and do for a command
|
||||
|
||||
## TODO: context.logPath and winston.js ! - log all commands, $ view
|
||||
log all commands, and all git errors
|
||||
and $ just opens the correct logfile, simple
|
||||
https://www.npmjs.com/package/winston-daily-rotate-file
|
||||
|
||||
## MINOR: NB! Thenables dont work with regular try/catch ?!
|
||||
|
||||
##
|
||||
|
13
package.json
13
package.json
@ -105,6 +105,10 @@
|
||||
{
|
||||
"command": "extension.magit-fetching",
|
||||
"title": "Magit Fetching"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-process-log",
|
||||
"title": "Magit Process Log"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
@ -180,6 +184,10 @@
|
||||
{
|
||||
"command": "extension.magit-fetching",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-process-log",
|
||||
"when": "editorLangId == magit"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -324,6 +332,11 @@
|
||||
"key": "shift+u",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-process-log",
|
||||
"key": "shift+4",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-save-and-close-commit-msg",
|
||||
"key": "ctrl+c ctrl+c",
|
||||
|
@ -1,52 +1,15 @@
|
||||
import { window, workspace } from 'vscode';
|
||||
import MagitUtils from '../utils/magitUtils';
|
||||
import { HelpView } from '../views/helpView';
|
||||
import { views } from '../extension';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
|
||||
export function magitHelp() {
|
||||
|
||||
return workspace.openTextDocument({
|
||||
content: `Popup and dwim commands
|
||||
A Cherry-picking b Branching B Bisecting c Committing
|
||||
d Diffing D Change diffs e Ediff dwimming E Ediffing
|
||||
f Fetching F Pulling l Logging L Change logs
|
||||
m Merging M Remoting o Submodules O Subtrees
|
||||
P Pushing r Rebasing t Tagging T Notes
|
||||
V Reverting w Apply patches W Format patches X Resetting
|
||||
y Show Refs z Stashing ! Running % Worktree
|
||||
|
||||
Applying changes
|
||||
a Apply s Stage u Unstage
|
||||
v Reverse S Stage all U Unstage all
|
||||
k Discard
|
||||
|
||||
Essential commands
|
||||
g refresh current buffer
|
||||
TAB toggle section at point
|
||||
RET visit thing at point
|
||||
C-h m show all key bindings`,
|
||||
language: 'magit'
|
||||
}).then(doc => window.showTextDocument(doc, { viewColumn: MagitUtils.oppositeActiveViewColumn(), preserveFocus: true, preview: true }));
|
||||
export async function magitHelp(repository: MagitRepository) {
|
||||
|
||||
// MINOR: everywhere; Combine encode and contructor
|
||||
// and just read helpView.uri when setting it in views
|
||||
const uri = HelpView.encodeLocation(repository);
|
||||
views.set(uri.toString(), new HelpView(uri));
|
||||
workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, MagitUtils.oppositeActiveViewColumn()));
|
||||
// commands.executeCommand('workbench.action.quickOpen', '>Magit ');
|
||||
|
||||
// window.showInformationMessage(`
|
||||
//Popup and dwim commands
|
||||
// A Cherry - picking b Branching B Bisecting c Committing
|
||||
// d Diffing D Change diffs e Ediff dwimming E Ediffing
|
||||
// f Fetching F Pulling l Logging L Change logs
|
||||
// m Merging M Remoting o Submodules O Subtrees
|
||||
// P Pushing r Rebasing t Tagging T Notes
|
||||
// V Reverting w Apply patches W Format patches X Resetting
|
||||
// y Show Refs z Stashing! Running % Worktree
|
||||
|
||||
// Applying changes
|
||||
// a Apply s Stage u Unstage
|
||||
// v Reverse S Stage all U Unstage all
|
||||
// k Discard
|
||||
|
||||
// Essential commands
|
||||
// g refresh current buffer
|
||||
// TAB toggle section at point
|
||||
// RET visit thing at point
|
||||
// C - h m show all key bindings
|
||||
//`);
|
||||
}
|
13
src/commands/processCommands.ts
Normal file
13
src/commands/processCommands.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import ProcessView from '../views/processView';
|
||||
import { views } from '../extension';
|
||||
import { workspace, window } from 'vscode';
|
||||
import MagitUtils from '../utils/magitUtils';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
|
||||
export async function processView(repository: MagitRepository) {
|
||||
const uri = ProcessView.encodeLocation(repository);
|
||||
|
||||
views.set(uri.toString(), new ProcessView(uri));
|
||||
|
||||
workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, MagitUtils.oppositeActiveViewColumn()));
|
||||
}
|
@ -31,13 +31,10 @@ export async function magitVisitAtPoint(repository: MagitRepository, currentView
|
||||
const commit: MagitCommit = (selectedView as CommitItemView).commit;
|
||||
|
||||
const result = await gitRun(repository, ['show', commit.hash]);
|
||||
|
||||
commit.diff = result.stdout;
|
||||
|
||||
const uri = CommitDetailView.encodeLocation(commit.hash);
|
||||
|
||||
views.set(uri.toString(), new CommitDetailView(uri, commit));
|
||||
|
||||
workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, MagitUtils.oppositeActiveViewColumn()));
|
||||
|
||||
} else if (selectedView instanceof StashItemView) {
|
||||
|
@ -26,9 +26,12 @@ import { DispatchView } from './views/dispatchView';
|
||||
import MagitUtils from './utils/magitUtils';
|
||||
import { remoting } from './commands/remotingCommands';
|
||||
import { logging } from './commands/loggingCommands';
|
||||
import { MagitProcessLogEntry } from './models/magitProcessLogEntry';
|
||||
import { processView } from './commands/processCommands';
|
||||
|
||||
export const magitRepositories: Map<string, MagitRepository> = new Map<string, MagitRepository>();
|
||||
export const views: Map<string, DocumentView> = new Map<string, DocumentView>();
|
||||
export const processLog: MagitProcessLogEntry[] = [];
|
||||
|
||||
export let gitApi: API;
|
||||
|
||||
@ -64,7 +67,7 @@ export function activate(context: ExtensionContext) {
|
||||
);
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit', (editor: TextEditor) => magitStatus(editor)));
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-help', magitHelp));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-help', Command.primeRepo(magitHelp, false)));
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-commit', Command.primeRepo(magitCommit)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-refresh', Command.primeRepo(magitRefresh)));
|
||||
@ -88,6 +91,8 @@ export function activate(context: ExtensionContext) {
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-file-popup', Command.primeFileCommand(filePopup)));
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-process-log', Command.primeRepo(processView, false)));
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-dispatch', Command.primeRepo(async (repository: MagitRepository) => {
|
||||
const uri = DispatchView.encodeLocation(repository);
|
||||
views.set(uri.toString(), new DispatchView(uri));
|
||||
|
6
src/models/magitProcessLogEntry.ts
Normal file
6
src/models/magitProcessLogEntry.ts
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
export interface MagitProcessLogEntry {
|
||||
index: number;
|
||||
command: string[];
|
||||
output?: string;
|
||||
}
|
@ -1,12 +1,21 @@
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { SpawnOptions } from '../common/gitApiExtensions';
|
||||
import MagitLogger from './logger';
|
||||
|
||||
export async function gitRun(repository: MagitRepository, args: string[], spawnOptions?: SpawnOptions) {
|
||||
|
||||
// Protects against projected change in internal api in vscode git extension
|
||||
if (repository._repository.repository.run) {
|
||||
return repository._repository.repository.run(args, spawnOptions);
|
||||
} else {
|
||||
return repository._repository.repository.exec!(args, spawnOptions);
|
||||
const logEntry = MagitLogger.logGitCommand(args);
|
||||
|
||||
try {
|
||||
|
||||
// Protects against projected change in internal api in vscode git extension
|
||||
if (repository._repository.repository.run) {
|
||||
return repository._repository.repository.run(args, spawnOptions);
|
||||
} else {
|
||||
return repository._repository.repository.exec!(args, spawnOptions);
|
||||
}
|
||||
} catch (error) {
|
||||
MagitLogger.logGitError(error, logEntry);
|
||||
throw error;
|
||||
}
|
||||
}
|
17
src/utils/logger.ts
Normal file
17
src/utils/logger.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import GitTextUtils from './gitTextUtils';
|
||||
import { processLog } from '../extension';
|
||||
import { MagitProcessLogEntry } from '../models/magitProcessLogEntry';
|
||||
|
||||
export default class MagitLogger {
|
||||
|
||||
public static logGitCommand(args: string[]): MagitProcessLogEntry {
|
||||
const logEntry = { command: ['git', ...args], index: processLog.length };
|
||||
processLog.push(logEntry);
|
||||
return logEntry;
|
||||
}
|
||||
|
||||
public static logGitError(error: any, entry: MagitProcessLogEntry) {
|
||||
const errorMsg = GitTextUtils.formatError(error);
|
||||
entry.output = errorMsg;
|
||||
}
|
||||
}
|
46
src/views/helpView.ts
Normal file
46
src/views/helpView.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { DocumentView } from './general/documentView';
|
||||
import { Uri } from 'vscode';
|
||||
import * as Constants from '../common/constants';
|
||||
import { TextView } from './general/textView';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
|
||||
export class HelpView extends DocumentView {
|
||||
|
||||
static UriPath: string = 'help.magit';
|
||||
isHighlightable = false;
|
||||
needsUpdate = false;
|
||||
|
||||
static HelpText: string = `Popup and dwim commands
|
||||
A Cherry-picking b Branching B Bisecting c Committing
|
||||
d Diffing D Change diffs e Ediff dwimming E Ediffing
|
||||
f Fetching F Pulling l Logging L Change logs
|
||||
m Merging M Remoting o Submodules O Subtrees
|
||||
P Pushing r Rebasing t Tagging T Notes
|
||||
V Reverting w Apply patches W Format patches X Resetting
|
||||
y Show Refs z Stashing ! Running % Worktree
|
||||
|
||||
Applying changes
|
||||
a Apply s Stage u Unstage
|
||||
v Reverse S Stage all U Unstage all
|
||||
k Discard
|
||||
|
||||
Essential commands
|
||||
g refresh current buffer
|
||||
TAB toggle section at point
|
||||
RET visit thing at point
|
||||
C-h m show all key bindings`;
|
||||
|
||||
constructor(uri: Uri) {
|
||||
super(uri);
|
||||
|
||||
const diffTextView = new TextView(HelpView.HelpText);
|
||||
diffTextView.isHighlightable = false;
|
||||
this.addSubview(diffTextView);
|
||||
}
|
||||
|
||||
public update(repository: MagitRepository): void { }
|
||||
|
||||
static encodeLocation(repository: MagitRepository): Uri {
|
||||
return Uri.parse(`${Constants.MagitUriScheme}:${HelpView.UriPath}?${repository.rootUri.path}#help`);
|
||||
}
|
||||
}
|
52
src/views/processView.ts
Normal file
52
src/views/processView.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import * as Constants from '../common/constants';
|
||||
import { DocumentView } from './general/documentView';
|
||||
import { Uri } from 'vscode';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { processLog } from '../extension';
|
||||
import { View } from './general/view';
|
||||
import { MagitProcessLogEntry } from '../models/magitProcessLogEntry';
|
||||
import { TextView } from './general/textView';
|
||||
|
||||
class ProcessLogEntryView extends View {
|
||||
isFoldable = true;
|
||||
|
||||
get id() { return '' + this.entry.index; }
|
||||
|
||||
constructor(private entry: MagitProcessLogEntry) {
|
||||
super();
|
||||
this.addSubview(
|
||||
new TextView(entry.command.reduce((msg, arg) => msg + arg + ' ', ''))
|
||||
);
|
||||
if (entry.output) {
|
||||
this.addSubview(new TextView(entry.output));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default class ProcessView extends DocumentView {
|
||||
|
||||
static UriPath: string = 'process.magit';
|
||||
|
||||
constructor(uri: Uri) {
|
||||
super(uri);
|
||||
this.provideContent();
|
||||
}
|
||||
|
||||
provideContent() {
|
||||
|
||||
if (processLog.length > 0) {
|
||||
this.subViews = processLog.map(entry => new ProcessLogEntryView(entry));
|
||||
} else {
|
||||
this.subViews = [new TextView('(No entries yet)')];
|
||||
}
|
||||
}
|
||||
|
||||
public update(repository: MagitRepository): void {
|
||||
this.provideContent();
|
||||
this.triggerUpdate();
|
||||
}
|
||||
|
||||
static encodeLocation(repository: MagitRepository): Uri {
|
||||
return Uri.parse(`${Constants.MagitUriScheme}:${ProcessView.UriPath}?${repository.rootUri.path}#process`);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user