|
@@ -1,4 +1,3 @@
|
|
|
-import { isMainFile } from './editor-files'
|
|
|
|
|
import getMeta from '../../../utils/meta'
|
|
import getMeta from '../../../utils/meta'
|
|
|
import { deleteJSON, postJSON } from '../../../infrastructure/fetch-json'
|
|
import { deleteJSON, postJSON } from '../../../infrastructure/fetch-json'
|
|
|
import { debounce, DebouncedFunc } from 'lodash'
|
|
import { debounce, DebouncedFunc } from 'lodash'
|
|
@@ -8,9 +7,9 @@ import { debugConsole } from '@/utils/debugging'
|
|
|
import { signalWithTimeout } from '@/utils/abort-signal'
|
|
import { signalWithTimeout } from '@/utils/abort-signal'
|
|
|
import { Dispatch, SetStateAction } from 'react'
|
|
import { Dispatch, SetStateAction } from 'react'
|
|
|
import { OpenDocuments } from '@/features/ide-react/editor/open-documents'
|
|
import { OpenDocuments } from '@/features/ide-react/editor/open-documents'
|
|
|
-import { DocumentContainer } from '@/features/ide-react/editor/document-container'
|
|
|
|
|
import { CompileOptions, CompileResponseData } from '@ol-types/compile'
|
|
import { CompileOptions, CompileResponseData } from '@ol-types/compile'
|
|
|
import { DeliveryLatencies } from './types'
|
|
import { DeliveryLatencies } from './types'
|
|
|
|
|
+import { RootDocInfo } from '@/shared/hooks/use-root-doc'
|
|
|
|
|
|
|
|
const AUTO_COMPILE_MAX_WAIT = 5000
|
|
const AUTO_COMPILE_MAX_WAIT = 5000
|
|
|
// We add a 2 second debounce to sending user changes to server if they aren't
|
|
// We add a 2 second debounce to sending user changes to server if they aren't
|
|
@@ -36,14 +35,12 @@ export default class DocumentCompiler {
|
|
|
cleanupCompileResult: () => void
|
|
cleanupCompileResult: () => void
|
|
|
signal: AbortSignal
|
|
signal: AbortSignal
|
|
|
openDocs: OpenDocuments
|
|
openDocs: OpenDocuments
|
|
|
- projectRootDocId: string | null
|
|
|
|
|
clsiServerId: string | null
|
|
clsiServerId: string | null
|
|
|
- currentDoc: DocumentContainer | null
|
|
|
|
|
error: Error | undefined
|
|
error: Error | undefined
|
|
|
timer: number
|
|
timer: number
|
|
|
defaultOptions: CompileOptions
|
|
defaultOptions: CompileOptions
|
|
|
debouncedAutoCompile: DebouncedFunc<() => void>
|
|
debouncedAutoCompile: DebouncedFunc<() => void>
|
|
|
- pathInFolder: (docId: string) => string | null
|
|
|
|
|
|
|
+ getRootDocInfo: () => RootDocInfo
|
|
|
|
|
|
|
|
constructor({
|
|
constructor({
|
|
|
compilingRef,
|
|
compilingRef,
|
|
@@ -57,6 +54,7 @@ export default class DocumentCompiler {
|
|
|
cleanupCompileResult,
|
|
cleanupCompileResult,
|
|
|
signal,
|
|
signal,
|
|
|
openDocs,
|
|
openDocs,
|
|
|
|
|
+ getRootDocInfo,
|
|
|
}: {
|
|
}: {
|
|
|
compilingRef: React.MutableRefObject<boolean>
|
|
compilingRef: React.MutableRefObject<boolean>
|
|
|
projectId: string
|
|
projectId: string
|
|
@@ -69,6 +67,7 @@ export default class DocumentCompiler {
|
|
|
cleanupCompileResult: () => void
|
|
cleanupCompileResult: () => void
|
|
|
signal: AbortSignal
|
|
signal: AbortSignal
|
|
|
openDocs: OpenDocuments
|
|
openDocs: OpenDocuments
|
|
|
|
|
+ getRootDocInfo: () => RootDocInfo
|
|
|
}) {
|
|
}) {
|
|
|
this.compilingRef = compilingRef
|
|
this.compilingRef = compilingRef
|
|
|
this.projectId = projectId
|
|
this.projectId = projectId
|
|
@@ -81,11 +80,9 @@ export default class DocumentCompiler {
|
|
|
this.cleanupCompileResult = cleanupCompileResult
|
|
this.cleanupCompileResult = cleanupCompileResult
|
|
|
this.signal = signal
|
|
this.signal = signal
|
|
|
this.openDocs = openDocs
|
|
this.openDocs = openDocs
|
|
|
- this.pathInFolder = () => null
|
|
|
|
|
|
|
+ this.getRootDocInfo = getRootDocInfo
|
|
|
|
|
|
|
|
- this.projectRootDocId = null
|
|
|
|
|
this.clsiServerId = null
|
|
this.clsiServerId = null
|
|
|
- this.currentDoc = null
|
|
|
|
|
this.error = undefined
|
|
this.error = undefined
|
|
|
this.timer = 0
|
|
this.timer = 0
|
|
|
this.defaultOptions = {
|
|
this.defaultOptions = {
|
|
@@ -136,9 +133,7 @@ export default class DocumentCompiler {
|
|
|
|
|
|
|
|
const t0 = performance.now()
|
|
const t0 = performance.now()
|
|
|
|
|
|
|
|
- const rootDocId = this.getRootDocOverrideId() || this.projectRootDocId
|
|
|
|
|
- const rootResourcePath =
|
|
|
|
|
- (rootDocId && this.pathInFolder(rootDocId)) || 'main.tex'
|
|
|
|
|
|
|
+ const { rootDocId, rootResourcePath } = this.getRootDocInfo()
|
|
|
|
|
|
|
|
const body = {
|
|
const body = {
|
|
|
rootDoc_id: rootDocId,
|
|
rootDoc_id: rootDocId,
|
|
@@ -184,21 +179,6 @@ export default class DocumentCompiler {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // parse the text of the current doc in the editor
|
|
|
|
|
- // if it contains "\documentclass" then use this as the root doc
|
|
|
|
|
- getRootDocOverrideId() {
|
|
|
|
|
- // only override when not in the root doc itself
|
|
|
|
|
- if (this.currentDoc && this.currentDoc.doc_id !== this.projectRootDocId) {
|
|
|
|
|
- const snapshot = this.currentDoc.getSnapshot()
|
|
|
|
|
-
|
|
|
|
|
- if (snapshot && isMainFile(snapshot)) {
|
|
|
|
|
- return this.currentDoc.doc_id
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return null
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// build the query parameters added to post-compile requests
|
|
// build the query parameters added to post-compile requests
|
|
|
buildPostCompileParams() {
|
|
buildPostCompileParams() {
|
|
|
const params = new URLSearchParams()
|
|
const params = new URLSearchParams()
|