mirror of
https://github.com/James-Yu/LaTeX-Workshop.git
synced 2024-10-04 15:17:59 +03:00
Show doc outline on vscode start, wait for cache
This commit is contained in:
parent
443b80bb63
commit
bf7499669a
@ -60,6 +60,7 @@ export class Cacher {
|
||||
private readonly pdfWatcher: PdfWatcher = new PdfWatcher()
|
||||
private readonly bibWatcher: BibWatcher = new BibWatcher()
|
||||
private caching = 0
|
||||
private promises: {[filePath: string]: Promise<void>} = {}
|
||||
|
||||
add(filePath: string) {
|
||||
if (CacherUtils.isExcluded(filePath)) {
|
||||
@ -88,6 +89,10 @@ export class Cacher {
|
||||
return this.caches[filePath]
|
||||
}
|
||||
|
||||
promise(filePath: string): Promise<void> | undefined {
|
||||
return this.promises[filePath]
|
||||
}
|
||||
|
||||
get allPaths() {
|
||||
return Object.keys(this.caches)
|
||||
}
|
||||
@ -126,16 +131,21 @@ export class Cacher {
|
||||
rootPath = rootPath || lw.manager.rootFile
|
||||
this.updateChildren(filePath, rootPath, contentTrimmed)
|
||||
|
||||
await this.updateAST(filePath, content)
|
||||
this.updateElements(filePath, content, contentTrimmed)
|
||||
this.updateBibfiles(filePath, contentTrimmed)
|
||||
logger.log(`Cached ${filePath} .`)
|
||||
this.caching--
|
||||
lw.eventBus.fire(eventbus.FileParsed, filePath)
|
||||
this.promises[filePath] = this.updateAST(filePath, content).then(() => {
|
||||
this.updateElements(filePath, content, contentTrimmed)
|
||||
this.updateBibfiles(filePath, contentTrimmed)
|
||||
}).finally(() => {
|
||||
logger.log(`Cached ${filePath} .`)
|
||||
this.caching--
|
||||
delete this.promises[filePath]
|
||||
lw.eventBus.fire(eventbus.FileParsed, filePath)
|
||||
|
||||
if (this.caching === 0) {
|
||||
void lw.structureViewer.computeTreeStructure()
|
||||
}
|
||||
if (this.caching === 0) {
|
||||
void lw.structureViewer.computeTreeStructure()
|
||||
}
|
||||
})
|
||||
|
||||
return this.promises[filePath]
|
||||
}
|
||||
|
||||
private async updateAST(filePath: string, content: string) {
|
||||
|
@ -149,9 +149,22 @@ export class SectionNodeProvider implements vscode.TreeDataProvider<Section> {
|
||||
}
|
||||
filesBuilt.add(file)
|
||||
|
||||
let waited = 0
|
||||
while (!lw.cacher.promise(file) && !lw.cacher.get(file)?.content) {
|
||||
// Just open vscode, has not cached, wait for a bit?
|
||||
await new Promise(resolve => setTimeout(resolve, 100))
|
||||
waited++
|
||||
if (waited > 10) {
|
||||
// Waited for five seconds before starting cache. Really?
|
||||
logger.log(`Error loading Cache during structuring: ${file} .`)
|
||||
return []
|
||||
}
|
||||
}
|
||||
await lw.cacher.promise(file)
|
||||
|
||||
const content = lw.cacher.get(file)?.content
|
||||
if (!content) {
|
||||
logger.log(`Error loading LaTeX during structuring: ${file} .`)
|
||||
logger.log(`Error loading content during structuring: ${file} .`)
|
||||
return []
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user