Skip to content

Commit

Permalink
Merge pull request #1883 from James-Yu/1873-space-spawn
Browse files Browse the repository at this point in the history
Fix #1873.
Use cross-spawn to run latexindent
Fix placeholders with docker
  • Loading branch information
jlelong authored Dec 28, 2019
2 parents 003efb4 + 62ec525 commit 5fe320e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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.71.0",
"webpack": "^4.20.2"
Expand Down
12 changes: 7 additions & 5 deletions src/providers/latexformatter.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -108,7 +109,8 @@ export class LaTexFormatter {

private format(document: vscode.TextDocument, range?: vscode.Range): Thenable<vscode.TextEdit[]> {
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
Expand All @@ -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[] = []
Expand Down

0 comments on commit 5fe320e

Please sign in to comment.