diff --git a/package-lock.json b/package-lock.json index 22061cde4..2067caef6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -334,6 +334,15 @@ "@types/node": "*" } }, + "@types/cross-spawn": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@types/cross-spawn/-/cross-spawn-6.0.1.tgz", + "integrity": "sha512-MtN1pDYdI6D6QFDzy39Q+6c9rl2o/xN7aWGe6oZuzqq5N6+YuwFsWiEAv3dNzvzN9YzU+itpN8lBzFpphQKLAw==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", diff --git a/package.json b/package.json index 0089b5948..7e73fc9e2 100644 --- a/package.json +++ b/package.json @@ -1644,6 +1644,7 @@ "dependencies": { "@tamuratak/domstubs": "^0.1.1", "chokidar": "^3.2.3", + "cross-spawn": "^7.0.1", "fs-extra": "^5.0.0", "glob": "^7.1.1", "iconv-lite": "^0.4.24", @@ -1659,6 +1660,7 @@ "ws": "^5.1.1" }, "devDependencies": { + "@types/cross-spawn": "^6.0.1", "@types/fs-extra": "^5.0.0", "@types/glob": "^7.1.1", "@types/micromatch": "^3.0.0", @@ -1674,8 +1676,8 @@ "eslint-plugin-import": "^2.19.1", "husky": "^3.0.2", "npm-run-all": "^4.1.5", - "textmate-bailout": "^1.1.0", "rimraf": "^3.0.0", + "textmate-bailout": "^1.1.0", "typescript": "~3.7.3", "vsce": "^1.69.0", "webpack": "^4.20.2" diff --git a/src/providers/latexformatter.ts b/src/providers/latexformatter.ts index ef1ce56ee..243226a99 100644 --- a/src/providers/latexformatter.ts +++ b/src/providers/latexformatter.ts @@ -1,5 +1,6 @@ import * as vscode from 'vscode' import * as cp from 'child_process' +import * as cs from 'cross-spawn' import * as path from 'path' import * as fs from 'fs' import * as os from 'os' @@ -108,7 +109,8 @@ export class LaTexFormatter { private format(document: vscode.TextDocument, range?: vscode.Range): Thenable { return new Promise((resolve, _reject) => { - const configuration = vscode.workspace.getConfiguration('editor', document.uri) + const configuration = vscode.workspace.getConfiguration('latex-workshop') + const useDocker = configuration.get('docker.enabled') as boolean if (!vscode.window.activeTextEditor) { return @@ -132,16 +134,16 @@ export class LaTexFormatter { // generate command line arguments const args = this.formatterArgs.map(arg => arg // taken from ../components/builder.ts - .replace(/%DOC%/g, configuration.get('docker.enabled') ? docfile : doc) + .replace(/%DOC%/g, useDocker ? docfile : doc) .replace(/%DOCFILE%/g, docfile) - .replace(/%DIR%/g, path.dirname(document.fileName).split(path.sep).join('/')) + .replace(/%DIR%/g, useDocker ? '.' : path.dirname(document.fileName).split(path.sep).join('/')) // latexformatter.ts specific tokens - .replace(/%TMPFILE%/g, temporaryFile.split(path.sep).join('/')) + .replace(/%TMPFILE%/g, useDocker ? path.basename(temporaryFile) : temporaryFile.split(path.sep).join('/')) .replace(/%INDENT%/g, indent)) this.extension.logger.addLogMessage(`Formatting with command ${this.formatter} ${args}`) this.extension.manager.setEnvVar() - const worker = cp.spawn(this.formatter, args, { stdio: 'pipe', cwd: path.dirname(document.fileName) }) + const worker = cs.spawn(this.formatter, args, { stdio: 'pipe', cwd: path.dirname(document.fileName) }) // handle stdout/stderr const stdoutBuffer: string[] = [] const stderrBuffer: string[] = []