From 4974dbaa9bf964681ca732919644eea4875e3e88 Mon Sep 17 00:00:00 2001 From: Jerome Lelong Date: Tue, 24 Dec 2019 10:53:32 +0100 Subject: [PATCH 1/3] Use cross-spawn to run latexindent Related to #1873 --- package-lock.json | 9 +++++++++ package.json | 4 +++- src/providers/latexformatter.ts | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) 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..b979c55ee 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' @@ -141,7 +142,7 @@ export class LaTexFormatter { 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[] = [] From 37e676dee95b22eef29d6d9e29c8ed64eb3c1ece Mon Sep 17 00:00:00 2001 From: Jerome Lelong Date: Thu, 26 Dec 2019 11:33:49 +0100 Subject: [PATCH 2/3] Fix placeholders for latexindent with docker --- src/providers/latexformatter.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/providers/latexformatter.ts b/src/providers/latexformatter.ts index b979c55ee..fd4122f8c 100644 --- a/src/providers/latexformatter.ts +++ b/src/providers/latexformatter.ts @@ -109,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 @@ -133,11 +134,11 @@ 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}`) From 62ec525d0b13a7fe913fd83bfba002382d03b0ca Mon Sep 17 00:00:00 2001 From: Jerome Lelong Date: Sat, 28 Dec 2019 21:58:49 +0100 Subject: [PATCH 3/3] Fix double / in latexindent -c when using docker --- src/providers/latexformatter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/latexformatter.ts b/src/providers/latexformatter.ts index fd4122f8c..243226a99 100644 --- a/src/providers/latexformatter.ts +++ b/src/providers/latexformatter.ts @@ -136,7 +136,7 @@ export class LaTexFormatter { // taken from ../components/builder.ts .replace(/%DOC%/g, useDocker ? docfile : doc) .replace(/%DOCFILE%/g, docfile) - .replace(/%DIR%/g, useDocker ? './' : 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, useDocker ? path.basename(temporaryFile) : temporaryFile.split(path.sep).join('/')) .replace(/%INDENT%/g, indent))