Skip to content

Commit 78e484d

Browse files
committed
frontend/latex: trying another approach, more debugging, etc
1 parent d96f495 commit 78e484d

File tree

13 files changed

+253
-137
lines changed

13 files changed

+253
-137
lines changed

src/packages/frontend/client/project.ts

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export class ProjectClient {
199199
async_stats: undefined,
200200
async_await: undefined,
201201
post: false, // if true, uses the POST api through nextjs instead of the websocket api.
202+
timeout: 30,
202203
cb: undefined,
203204
});
204205
} else {

src/packages/frontend/frame-editors/_style.sass

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
> button.btn
1111
margin-bottom: 20px
1212

13-
1413
// latex editor, build panel
1514
.cocalc-latex-build-content
1615

1716
.ant-tabs-tab
18-
margin: 0 !important
19-
padding: 0 !important
17+
margin: 0 !important
18+
padding: 0 !important
2019
> div
2120
width: 100%
2221
padding: 5px 10px
@@ -26,6 +25,9 @@
2625
.ant-tabs-content-holder
2726
display: flex
2827

28+
.ant-tabs-content
29+
overflow-y: auto
30+
2931
.ant-tabs-tabpane
30-
display : flex
31-
flex-direction : column
32+
display: flex
33+
flex-direction: column

src/packages/frontend/frame-editors/latex-editor/actions.ts

+42-38
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import {
5555
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
5656

5757
import { ExecOutput } from "@cocalc/util/db-schema/projects";
58-
import { ExecuteCodeOutputAsync } from "@cocalc/util/types/execute-code";
58+
// import { ExecuteCodeOutputAsync } from "@cocalc/util/types/execute-code";
5959
import { bibtex } from "./bibtex";
6060
import { clean } from "./clean";
6161
import { KNITR_EXTS } from "./constants";
@@ -79,7 +79,7 @@ import {
7979
BuildLogs,
8080
BuildSpecName,
8181
IBuildSpecs,
82-
JobInfos,
82+
// JobInfos,
8383
ScrollIntoViewMap,
8484
ScrollIntoViewRecord,
8585
} from "./types";
@@ -99,7 +99,7 @@ interface LatexEditorState extends CodeEditorState {
9999
includeError?: string;
100100
build_command_hardcoded?: boolean; // if true, an % !TeX cocalc = ... directive sets the command via the document itself
101101
contents?: TableOfContentsEntryList; // table of contents data.
102-
job_infos: JobInfos;
102+
// job_infos: JobInfos;
103103
}
104104

105105
export class Actions extends BaseActions<LatexEditorState> {
@@ -675,7 +675,7 @@ export class Actions extends BaseActions<LatexEditorState> {
675675
await this.build(); // kicks off a save of all relevant files
676676
}
677677

678-
// used by generic framework.
678+
// used by generic framework – this is bound to the instance, otherwise "this" is undefined
679679
build = async (id?: string, force: boolean = false): Promise<void> => {
680680
this.set_error("");
681681
this.set_status("");
@@ -685,6 +685,7 @@ export class Actions extends BaseActions<LatexEditorState> {
685685
cm.focus();
686686
}
687687
}
688+
// initiating a build. if one is running & forced, we stop the build
688689
if (this.is_building) {
689690
if (force) {
690691
await this.stop_build();
@@ -723,29 +724,30 @@ export class Actions extends BaseActions<LatexEditorState> {
723724
// likely "No such process", we just ignore it
724725
// console.info("LatexEditor/actions/kill:", err);
725726
} finally {
726-
// even if there was an error, we clean it out
727-
this.set_job_infos({ [name]: null });
727+
// we keep the data for debugging, but set its state to completed
728+
job.status = "completed";
729+
this.set_build_logs({ [name]: job });
728730
}
729731
}
730732
}
731733

732734
// This stops all known jobs with a status "running" and resets the state.
733735
async stop_build(_id?: string) {
734-
const job_infos = this.store.get("job_infos");
736+
const job_infos = this.store.get("build_logs"); // ("job_infos");
735737
if (job_infos) {
736738
for (const [name, job] of job_infos) {
737739
await this.kill(name, job.toJS());
738740
}
739741
}
740742

741743
// this must run in any case, we want a clean empty map!
742-
this.setState({ job_infos: Map() });
744+
//this.setState({ job_infos: Map() });
743745
this.set_status("");
744746
this.is_building = false;
745747
}
746748

747749
private async run_build(time: number, force: boolean): Promise<void> {
748-
// reset state and build info
750+
// reset state of build_logs, since it is a fresh start
749751
this.setState({ build_logs: Map() });
750752

751753
if (this.bad_filename) {
@@ -809,7 +811,7 @@ export class Actions extends BaseActions<LatexEditorState> {
809811
private async run_knitr(time: number, force: boolean): Promise<void> {
810812
let output: BuildLog;
811813
const status = (s) => this.set_status(`Running Knitr... ${s}`);
812-
const set_job_info = (job) => this.set_job_infos({ knitr: job });
814+
const set_job_info = (job) => this.set_build_logs({ knitr: job });
813815
status("");
814816

815817
try {
@@ -900,14 +902,14 @@ export class Actions extends BaseActions<LatexEditorState> {
900902
}
901903
this.set_error("");
902904
this.set_build_logs({ latex: undefined });
903-
this.set_job_infos({ latex: undefined });
905+
// this.set_job_infos({ latex: undefined });
904906
if (typeof s == "string") {
905907
build_command = s;
906908
} else {
907909
build_command = s.toJS();
908910
}
909911
const status = (s) => this.set_status(`Running Latex... ${s}`);
910-
const set_job_info = (job) => this.set_job_infos({ latex: job });
912+
const set_job_info = (job) => this.set_build_logs({ latex: job });
911913

912914
status("");
913915
try {
@@ -936,6 +938,7 @@ export class Actions extends BaseActions<LatexEditorState> {
936938
this.parsed_output_log = output.parse = new LatexParser(output.stdout, {
937939
ignoreDuplicates: true,
938940
}).parse();
941+
console.log("set_build_logs after complete:", (output as any)?.status);
939942
this.set_build_logs({ latex: output });
940943
// TODO: knitr complicates multifile a lot, so we do
941944
// not support it yet.
@@ -1106,7 +1109,7 @@ export class Actions extends BaseActions<LatexEditorState> {
11061109

11071110
async run_sagetex(time: number, force: boolean): Promise<void> {
11081111
const status = (s) => this.set_status(`Running SageTeX... ${s}`);
1109-
const set_job_info = (job) => this.set_job_infos({ sagetex: job });
1112+
const set_job_info = (job) => this.set_build_logs({ sagetex: job });
11101113
status("");
11111114
// First compute hash of sagetex file.
11121115
let hash: string = "";
@@ -1176,7 +1179,7 @@ export class Actions extends BaseActions<LatexEditorState> {
11761179
async run_pythontex(time: number, force: boolean): Promise<void> {
11771180
let output: BuildLog;
11781181
const status = (s) => this.set_status(`Running PythonTeX... ${s}`);
1179-
const set_job_info = (job) => this.set_job_infos({ pythontex: job });
1182+
const set_job_info = (job) => this.set_build_logs({ pythontex: job });
11801183
status("");
11811184

11821185
try {
@@ -1341,36 +1344,37 @@ export class Actions extends BaseActions<LatexEditorState> {
13411344
});
13421345
}
13431346

1344-
set_job_infos(obj: {
1345-
[K in keyof IBuildSpecs]?: ExecuteCodeOutputAsync;
1346-
}): void {
1347-
let job_infos: JobInfos = this.store.get("job_infos") ?? Map();
1347+
// set_job_infos(obj: {
1348+
// [K in keyof IBuildSpecs]?: ExecuteCodeOutputAsync;
1349+
// }): void {
1350+
// let job_infos: JobInfos = this.store.get("job_infos") ?? Map();
1351+
// let k: BuildSpecName;
1352+
// for (k in obj) {
1353+
// const v: ExecuteCodeOutputAsync | undefined = obj[k];
1354+
// if (v) {
1355+
// job_infos = job_infos.set(
1356+
// k as any,
1357+
// fromJS(v) as any as TypedMap<ExecOutput>,
1358+
// );
1359+
// } else {
1360+
// job_infos = job_infos.delete(k);
1361+
// }
1362+
// }
1363+
// this.setState({ job_infos });
1364+
// }
1365+
1366+
private set_build_logs(obj: { [K in keyof IBuildSpecs]?: BuildLog }): void {
1367+
let build_logs: BuildLogs = this.store.get("build_logs") ?? Map();
13481368
let k: BuildSpecName;
13491369
for (k in obj) {
1350-
const v: ExecuteCodeOutputAsync | undefined = obj[k];
1370+
const v: BuildLog | undefined = obj[k];
13511371
if (v) {
1352-
job_infos = job_infos.set(
1353-
k as any,
1354-
fromJS(v) as any as TypedMap<ExecOutput>,
1355-
);
1372+
build_logs = build_logs.set(k, fromJS(v) as any as TypedMap<BuildLog>);
13561373
} else {
1357-
job_infos = job_infos.delete(k);
1374+
build_logs = build_logs.delete(k);
13581375
}
13591376
}
1360-
this.setState({ job_infos });
1361-
}
1362-
1363-
set_build_logs(obj: { [K in keyof IBuildSpecs]?: BuildLog }): void {
1364-
let build_logs: BuildLogs = this.store.get("build_logs");
1365-
if (!build_logs) {
1366-
// may have already been closed.
1367-
return;
1368-
}
1369-
let k: BuildSpecName;
1370-
for (k in obj) {
1371-
const v: BuildLog | undefined = obj[k];
1372-
build_logs = build_logs.set(k, fromJS(v) as any as TypedMap<BuildLog>);
1373-
}
1377+
console.log("set_job_info.latex", build_logs?.get("latex")?.get("status"));
13741378
this.setState({ build_logs });
13751379
}
13761380

0 commit comments

Comments
 (0)