Skip to content

Commit

Permalink
fix: support loading from http URI
Browse files Browse the repository at this point in the history
  • Loading branch information
DCsunset committed Jul 27, 2022
1 parent 15bec9b commit c29dd47
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 2 deletions.
144 changes: 143 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,8 @@
"standard-version": "^9.3.2",
"ts-auto-guard": "^2.4.1",
"typescript": "^4.5.5"
},
"dependencies": {
"axios": "^0.27.2"
}
}
10 changes: 9 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from "vscode";
import * as os from "os";
import axios from "axios";
import { readConfig } from "./config";
import { isKeybindings } from "./keybindings.guard";
import { AppState, NORMAL, INSERT, SELECT, COMMAND, Command } from "./actions";
Expand All @@ -21,7 +22,14 @@ function commandId(command: ((_: any) => any) | string) {
async function loadKeybindings(uri: vscode.Uri) {
const fs = vscode.workspace.fs;
try {
let data = Buffer.from(await fs.readFile(uri)).toString("utf-8");
let data: string;
if (uri.scheme === "http" || uri.scheme === "https") {
const res = await axios.get(uri.toString());
data = res.data;
}
else {
data = Buffer.from(await fs.readFile(uri)).toString("utf-8");
}
if (uri.fsPath.match(/json[5c]?$/))
data = `(${data})`;

Expand Down

0 comments on commit c29dd47

Please sign in to comment.