Skip to content

Commit

Permalink
feat: enable compiling different root file when opened
Browse files Browse the repository at this point in the history
  • Loading branch information
QianrenLi authored and iamhyc committed Jan 16, 2025
1 parent 9635545 commit 97501e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/compile/compileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const severityMap: Record<string, vscode.DiagnosticSeverity> = {
information: vscode.DiagnosticSeverity.Information,
};

// Match the document class in the tex file
const documentClassRegex = new RegExp(/\\documentclass(?:\[[^\[\]\{\}]*\])?\{([^\[\]\{\}]+)\}/);

const pdfViewRecord: {
[key: string]: {
[key: string]: { doc: PdfDocument, webviewPanel: vscode.WebviewPanel }
Expand Down Expand Up @@ -198,7 +201,13 @@ export class CompileManager {
const uri = await this.update('compiling');
if (uri) {
this.vfsm.prefetch(uri)
.then(async (vfs) => await vfs.compile(force, this.compileAsDraft, this.compileStopOnFirstError))
.then(async (vfs) => {
const content = new TextDecoder().decode( await vfs?.openFile(uri) );
const match = RegExp(documentClassRegex).exec(content);
const fileId = (await vfs._resolveUri(uri)).fileId;
const rootDocId = match ? fileId : undefined;
return await vfs.compile(force, this.compileAsDraft, this.compileStopOnFirstError, rootDocId);
})
.then(async (res) => {
switch (res) {
case undefined:
Expand Down
4 changes: 2 additions & 2 deletions src/core/remoteFileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ export class VirtualFileSystem extends vscode.Disposable {
}
}

async compile(force:boolean=false, draft:boolean=false, stopOnFirstError:boolean=false) {
async compile(force:boolean=false, draft:boolean=false, stopOnFirstError:boolean=false, rootDocId?:string) {
if (force || (this.root && this.isDirty)) {
this.isDirty = false;
let needCacheClearFirst = false;
Expand All @@ -883,7 +883,7 @@ export class VirtualFileSystem extends vscode.Disposable {
await this.api.deleteAuxFiles(identity, this.projectId);
}
// compile project
const res = await this.api.compile(identity, this.projectId, this.root?.rootDoc_id??null, draft, stopOnFirstError);
const res = await this.api.compile(identity, this.projectId, rootDocId??this.root?.rootDoc_id??null, draft, stopOnFirstError);
if (res.type==='success' && res.compile?.status==='success') {
this.updateOutputs(res.compile.outputFiles);
return true;
Expand Down

0 comments on commit 97501e0

Please sign in to comment.