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

[Feature]: enable compiling different root file when opened #218

Merged
merged 1 commit into from
Jan 16, 2025
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
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
Loading