Fix preview error on large files

Signed-off-by: trivernis <trivernis@protonmail.com>
main
trivernis 4 years ago
parent 46aa2c2ed5
commit 15df4b90f4
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

9
package-lock.json generated

@ -1,6 +1,6 @@
{
"name": "snekdown-preview",
"version": "0.0.1",
"name": "snekdown",
"version": "0.9.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -75,11 +75,6 @@
}
}
},
"@microsoft/vscode-file-downloader-api": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@microsoft/vscode-file-downloader-api/-/vscode-file-downloader-api-1.0.1.tgz",
"integrity": "sha512-cO9n/IpTMbXizz5YcEkiuRyX5r66SBY/3LnrlroyXbQXrgDdaKecfV3n4viTcvp9O//QF2AxcBfDZex2d4VSTg=="
},
"@nodelib/fs.scandir": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.4.tgz",

@ -13,7 +13,7 @@
"url": "https://github.com/Trivernis/snekdown-vscode-extension.git"
},
"description": "Preview and commands for the snekdown markdown flavour",
"version": "0.9.0",
"version": "0.9.1",
"engines": {
"vscode": "^1.52.0"
},
@ -76,16 +76,20 @@
}
]
},
"languages": [{
"id": "snekdown",
"aliases": ["Snekdown"],
"extensions": [
".sd.md",
".snekdown",
".sd",
".sdown"
]
}],
"languages": [
{
"id": "snekdown",
"aliases": [
"Snekdown"
],
"extensions": [
".sd.md",
".snekdown",
".sd",
".sdown"
]
}
],
"grammars": [
{
"language": "snekdown",
@ -113,6 +117,7 @@
"eslint": "^7.15.0",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"@types/node-fetch": "^2.5.8",
"glob": "^7.1.6",
"mocha": "^8.1.3",
"typescript": "^4.1.2",
@ -122,11 +127,6 @@
"webpack-cli": "^4.2.0"
},
"dependencies": {
"@microsoft/vscode-file-downloader-api": "^1.0.1",
"@types/node-fetch": "^2.5.8",
"node-fetch": "^2.6.1"
},
"extensionDependencies": [
"mindaro-dev.file-downloader"
]
}
}

@ -1,5 +1,4 @@
import {getApi, FileDownloader} from "@microsoft/vscode-file-downloader-api";
import { exec, execFile } from "child_process";
import { exec, execFile, spawn } from "child_process";
import { chmodSync } from "fs";
import * as os from "os";
import * as path from "path";
@ -70,7 +69,6 @@ export class SnekdownWrapper {
* Detects or downloads the snekdown executable
*/
public async download () {
const fileDownloader: FileDownloader = await getApi();
let execPath: string;
@ -117,15 +115,20 @@ export class SnekdownWrapper {
cwd = vscode.workspace.workspaceFolders[0].uri.fsPath;
}
return new Promise((res, rej) => {
let process = execFile(this.executable, [command, ...args], {cwd}, (err, stdout, stderr) => {
if (err) {
rej(err);
}
if (process.exitCode !== 0) {
rej(stderr);
let child = spawn(this.executable, [command, ...args], {cwd});
let stdout = "";
child.stdout.on("data", data => {
stdout += data as string;
});
child.stderr.on("data", data => {
console.log("Snekdown: ", "" + data as string);
});
child.on("exit", code => {
if (code != 0) {
rej(new Error("Failed to execute command. Open the developer console for more information."))
} else {
res(stdout)
}
console.log(stderr);
res(stdout);
});
});
}

Loading…
Cancel
Save