Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cross-spawn to run latexindent #1883

Merged
merged 3 commits into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.69.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