Skip to content

Commit

Permalink
#4247 Fix racing build-on-save when multiple files are edited
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Apr 24, 2024
1 parent 12c3ff6 commit b58bc13
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/compile/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function autoBuild(file: string, type: 'onFileChange' | 'onSave', bibChanged: bo
logger.log('Autobuild temporarily disabled.')
return
}
lw.compile.lastAutoBuildTime = Date.now()
if (!bibChanged && lw.root.subfiles.path && configuration.get('latex.rootFile.useSubFile')) {
return build(true, lw.root.subfiles.path, lw.root.subfiles.langId)
} else {
Expand All @@ -57,7 +58,7 @@ function autoBuild(file: string, type: 'onFileChange' | 'onSave', bibChanged: bo
*/
function canAutoBuild(): boolean {
const configuration = vscode.workspace.getConfiguration('latex-workshop', lw.root.file.path ? vscode.Uri.file(lw.root.file.path) : undefined)
return Date.now() - lw.compile.lastBuildTime >= (configuration.get('latex.autoBuild.interval', 1000) as number)
return Date.now() - lw.compile.lastAutoBuildTime >= (configuration.get('latex.autoBuild.interval', 1000) as number)
}

let isBuilding = false
Expand Down Expand Up @@ -147,7 +148,6 @@ async function buildLoop() {

isBuilding = true
lw.compile.compiledPDFWriting++
lw.compile.lastBuildTime = Date.now()
// Stop watching the PDF file to avoid reloading the PDF viewer twice.
// The builder will be responsible for refreshing the viewer.
let skipped = true
Expand Down
2 changes: 1 addition & 1 deletion src/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const compile = {
autoBuild,
terminate,
lastSteps: [] as Step[],
lastBuildTime: 0,
lastAutoBuildTime: 0,
compiledPDFPath: '',
compiledPDFWriting: 0,
process: undefined as ChildProcessWithoutNullStreams | undefined
Expand Down
2 changes: 1 addition & 1 deletion src/core/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export function texdocUsepackages() {
}

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

Expand Down
2 changes: 1 addition & 1 deletion test/suites/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function reset() {
await vscode.commands.executeCommand('workbench.action.closeAllEditors')
await Promise.all(Object.values(lw.cache.promises))
lw.compile.lastSteps = []
lw.compile.lastBuildTime = 0
lw.compile.lastAutoBuildTime = 0
lw.compile.compiledPDFPath = ''
lw.compile.compiledPDFWriting = 0
lw.root.file.path = undefined
Expand Down

0 comments on commit b58bc13

Please sign in to comment.