Skip to content

Commit

Permalink
Modularize builder and cacher
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Nov 18, 2023
1 parent 96bcabe commit 62849a9
Show file tree
Hide file tree
Showing 41 changed files with 1,557 additions and 1,418 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@
"category": "LaTeX Workshop"
},
{
"command": "latex-workshop.kill",
"title": "Kill LaTeX compiler process",
"command": "latex-workshop.terminate",
"title": "Terminate LaTeX compiler process",
"category": "LaTeX Workshop",
"enablement": "!virtualWorkspace"
},
Expand Down
54 changes: 13 additions & 41 deletions src/core/commands.ts → src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
import * as vscode from 'vscode'
import * as path from 'path'
import * as lw from '../lw'
import { getSurroundingCommandRange, stripText } from '../utils/utils'
import { getLogger } from '../utils/logging/logger'
import { parser } from '../parse/parser'
import * as lw from './lw'
import { getSurroundingCommandRange, stripText } from './utils/utils'
import { getLogger } from './utils/logging/logger'
import { parser } from './parse/parser'
import { state as compile } from './compile'
import { build as buildWorker } from './compile/build'
import { terminate as terminateWorker } from './compile/terminate'

const logger = getLogger('Commander')

export async function build(skipSelection: boolean = false, rootFile: string | undefined = undefined, languageId: string | undefined = undefined, recipe: string | undefined = undefined) {
logger.log('BUILD command invoked.')
if (!vscode.window.activeTextEditor) {
logger.log('Cannot start to build because the active editor is undefined.')
return
}
logger.log(`The document of the active editor: ${vscode.window.activeTextEditor.document.uri.toString(true)}`)
logger.log(`The languageId of the document: ${vscode.window.activeTextEditor.document.languageId}`)
const workspace = rootFile ? vscode.Uri.file(rootFile) : vscode.window.activeTextEditor.document.uri
const configuration = vscode.workspace.getConfiguration('latex-workshop', workspace)
const externalBuildCommand = configuration.get('latex.external.build.command') as string
const externalBuildArgs = configuration.get('latex.external.build.args') as string[]
if (rootFile === undefined && lw.manager.hasTexId(vscode.window.activeTextEditor.document.languageId)) {
rootFile = await lw.manager.findRoot()
languageId = lw.manager.rootFileLanguageId
}
if (externalBuildCommand) {
const pwd = path.dirname(rootFile ? rootFile : vscode.window.activeTextEditor.document.fileName)
await lw.builder.buildExternal(externalBuildCommand, externalBuildArgs, pwd, rootFile)
return
}
if (rootFile === undefined || languageId === undefined) {
logger.log('Cannot find LaTeX root file. See https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#the-root-file')
return
}
let pickedRootFile: string | undefined = rootFile
if (!skipSelection && lw.manager.localRootFile) {
// We are using the subfile package
pickedRootFile = await quickPickRootFile(rootFile, lw.manager.localRootFile, 'build')
if (! pickedRootFile) {
return
}
}
logger.log(`Building root file: ${pickedRootFile}`)
await lw.builder.build(pickedRootFile, languageId, recipe)
await buildWorker(skipSelection, rootFile, languageId, recipe)
}

export async function revealOutputDir() {
Expand Down Expand Up @@ -114,9 +85,9 @@ export function refresh() {
lw.viewer.refreshExistingViewer()
}

export function kill() {
logger.log('KILL command invoked.')
lw.builder.kill()
export function terminate() {
logger.log('TERMINATE command invoked.')
terminateWorker()
}

export function synctex() {
Expand Down Expand Up @@ -478,7 +449,8 @@ export function texdocUsepackages() {
}

export async function saveActive() {
await lw.builder.saveActive()
compile.lastBuildTime = Date.now()
await vscode.window.activeTextEditor?.document.save()
}

export function openMathPreviewPanel() {
Expand Down
Loading

0 comments on commit 62849a9

Please sign in to comment.