-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
helpCommands.ts
29 lines (24 loc) · 1.08 KB
/
helpCommands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { workspace } from 'vscode';
import { HelpView } from '../views/helpView';
import { MagitRepository } from '../models/magitRepository';
import * as path from 'path';
import * as JSONC from 'jsonc-parser';
import ViewUtils from '../utils/viewUtils';
import { logPath } from '../extension';
export async function magitHelp(repository: MagitRepository) {
return openHelpView(repository);
}
export async function magitDispatch(repository: MagitRepository) {
return openHelpView(repository);
}
async function openHelpView(repository: MagitRepository) {
let keybindingsPath = path.join(logPath, '..', '..', '..', '..', '..', 'User', 'keybindings.json');
let userKeyBindings = [];
try {
const userKeyBindingsDoc = await workspace.openTextDocument(keybindingsPath);
const userKeyBindingsText = userKeyBindingsDoc.getText().replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
userKeyBindings = JSONC.parse(userKeyBindingsText);
} catch (e) { console.error(e); }
const uri = HelpView.encodeLocation(repository);
return ViewUtils.showView(uri, new HelpView(uri, userKeyBindings));
}