Skip to content

Commit f13a5d2

Browse files
committed
API Client config
1 parent 4b18ef0 commit f13a5d2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/api.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import APIClient from '@hackmd/api';
2+
import { ExportType } from '@hackmd/api';
3+
import * as vscode from 'vscode';
4+
const config = {
5+
serverUrl: vscode.workspace.getConfiguration('Hackmd').get('serverURL') as string,
6+
enterprise: vscode.workspace.getConfiguration('Hackmd').get('enterprise') as boolean
7+
};
8+
const API = new APIClient(config);
9+
vscode.workspace.onDidChangeConfiguration(async e => {
10+
if (e.affectsConfiguration('Hackmd')) {
11+
const clicked = await vscode.window.showInformationMessage('Setting updated. Restart to apply this change.', ...['Restart']);
12+
if (clicked === 'Restart') {
13+
vscode.commands.executeCommand("workbench.action.reloadWindow");
14+
}
15+
}
16+
});
17+
export { API, ExportType };

src/commands/snippet.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from 'vscode';
2-
import * as apiClient from '@hackmd/api';
3-
const API = new apiClient.default();
2+
import { API } from './../api';
43

54
export function registerSnippetCommands(context: vscode.ExtensionContext) {
65
context.subscriptions.push(vscode.commands.registerCommand('HackMD.createCodeSnippet', async () => {
@@ -12,7 +11,7 @@ export function registerSnippetCommands(context: vscode.ExtensionContext) {
1211

1312
const textRange = new vscode.Range(editor.selection.start.line, editor.selection.start.character, editor.selection.end.line, editor.selection.end.character);
1413
const text = vscode.window.activeTextEditor.document.getText(textRange);
15-
const filePath = vscode.workspace.asRelativePath(editor.document.uri.fsPath)
14+
const filePath = vscode.workspace.asRelativePath(editor.document.uri.fsPath);
1615
const snippet = `---\ntitle: public/${filePath}\n---\n> \`${filePath}\`\n\n\`\`\`${editor.document.languageId}=${editor.selection.start.line + 1}\n${text}\n\`\`\``;
1716

1817
const noteUrl = await API.newNote(snippet);

0 commit comments

Comments
 (0)