Skip to content
Snippets Groups Projects
Commit 93709390 authored by James-Yu's avatar James-Yu
Browse files

Add clean and auto-clean features

parent 7e2a8938
No related branches found
No related tags found
No related merge requests found
......@@ -138,6 +138,10 @@
{
"command": "latex-workshop.synctex",
"title": "SyncTeX from LaTeX to PDF"
},
{
"command": "latex-workshop.clean",
"title": "Clean up auxillary files of LaTeX project"
}
],
"configuration": {
......@@ -154,6 +158,16 @@
"default": true,
"description": "Build LaTeX after saving LaTeX source file.\nThis property defines whether LaTeX Workshop will execute the LaTeX toolchain command(s) to build the project after new LaTeX contents are saved."
},
"latex-workshop.clean_after_build": {
"type": "boolean",
"default": false,
"description": "Delete LaTeX auxillary files after building project.\nThis property defines whether LaTeX Workshop will clean up all unnecessary files after building the project."
},
"latex-workshop.files_to_clean": {
"type": "array",
"default": ["*.aux", "*.bbl", "*.blg", "*.idx", "*.ind", "*.lof", "*.lot", "*.out", "*.toc", "*.acn", "*.acr", "*.alg", "*.glg", "*.glo", "*.gls", "*.ist", "*.fls", "*.log", "*.fdb_latexmk"],
"description": "Files to clean.\nThis property must be an array of strings. File globs such as *.removeme, something?.aux can be used."
},
"latex-workshop.linter": {
"type": "boolean",
"default": false,
......@@ -202,6 +216,11 @@
"when": "resourceLangId == latex",
"command": "latex-workshop.synctex",
"group": "navigation@103"
},
{
"when": "resourceLangId == latex",
"command": "latex-workshop.clean",
"group": "navigation@104"
}
]
}
......
......@@ -51,6 +51,11 @@ export class Builder {
this.extension.logger.addLogMessage(`Successfully built ${rootFile}`)
this.extension.logger.displayStatus('check', 'white', `LaTeX toolchain succeeded.`)
this.extension.viewer.refreshExistingViewer(rootFile)
let configuration = vscode.workspace.getConfiguration('latex-workshop')
let clean = configuration.get('clean_after_build') as boolean
if (clean) {
this.extension.cleaner.clean()
}
}
processWrapper(command: string, options: any, callback: (error: Error, stdout: string, stderr: string) => void) : cp.ChildProcess {
......
'use strict'
import * as vscode from 'vscode'
import * as path from 'path'
import * as fs from 'fs'
import * as glob from 'glob'
import {Extension} from './main'
export class Cleaner {
extension: Extension
constructor(extension: Extension) {
this.extension = extension
}
clean() {
if (this.extension.manager.rootFile !== undefined) {
this.extension.manager.findRoot()
}
let configuration = vscode.workspace.getConfiguration('latex-workshop')
let globs = configuration.get('files_to_clean') as Array<string>
for (let globType of globs) {
glob(globType, {cwd: this.extension.manager.rootDir}, (err, files) => {
if (err) {
this.extension.logger.addLogMessage(`Error identifying files with glob ${globType}: ${files}.`)
return
}
for (let file of files) {
let fullPath = path.resolve(this.extension.manager.rootDir, file)
fs.unlinkSync(fullPath)
}
})
}
}
}
......@@ -55,4 +55,10 @@ export class Commander {
return
this.extension.locator.syncTeX()
}
}
\ No newline at end of file
clean() {
this.extension.logger.addLogMessage(`CLEAN command invoked.`)
this.extension.manager.findRoot()
this.extension.cleaner.clean()
}
}
......@@ -12,6 +12,7 @@ import {Locator} from './locator'
import {Parser} from './parser'
import {Completer} from './completer'
import {Linter} from './linter'
import {Cleaner} from './cleaner'
export async function activate(context: vscode.ExtensionContext) {
let extension = new Extension()
......@@ -21,6 +22,7 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('latex-workshop.view', () => extension.commander.view())
vscode.commands.registerCommand('latex-workshop.tab', () => extension.commander.tab())
vscode.commands.registerCommand('latex-workshop.synctex', () => extension.commander.synctex())
vscode.commands.registerCommand('latex-workshop.clean', () => extension.commander.clean())
context.subscriptions.push(vscode.workspace.onDidSaveTextDocument((e: vscode.TextDocument) => {
let configuration = vscode.workspace.getConfiguration('latex-workshop')
......@@ -84,6 +86,7 @@ export class Extension {
parser: Parser
completer: Completer
linter: Linter
cleaner: Cleaner
constructor() {
this.logger = new Logger(this)
......@@ -96,6 +99,7 @@ export class Extension {
this.parser = new Parser(this)
this.completer = new Completer(this)
this.linter = new Linter(this)
this.cleaner = new Cleaner(this)
this.logger.addLogMessage(`LaTeX Workshop initialized.`)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment