Skip to content

Commit

Permalink
Modularize outline
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Dec 12, 2023
1 parent e413247 commit 0c24947
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 176 deletions.
2 changes: 1 addition & 1 deletion src/completion/completer/citation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export class Citation implements IProvider {
})
this.bibEntries.set(fileName, newEntry)
logger.log(`Parsed ${newEntry.length} bib entries from ${fileName} .`)
void lw.structureViewer.reconstruct()
void lw.outline.reconstruct()
lw.event.fire(lw.event.FileParsed, fileName)
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ async function refreshCache(filePath: string, rootPath?: string): Promise<Promis
lw.event.fire(lw.event.FileParsed, filePath)

if (cachingFilesCount === 0) {
void lw.structureViewer.reconstruct()
void lw.outline.reconstruct()
}
})
)
Expand Down
4 changes: 2 additions & 2 deletions src/core/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function find(): Promise<undefined> {
}
if (rootFilePath === root.file.path) {
logger.log(`Keep using the same root file: ${root.file.path}`)
void lw.structureViewer.refresh()
void lw.outline.refresh()
} else {
root.file.path = rootFilePath
root.file.langId = lw.file.getLangId(rootFilePath)
Expand All @@ -80,7 +80,7 @@ async function find(): Promise<undefined> {
return
}
logger.log('No root file found.')
void lw.structureViewer.refresh()
void lw.outline.refresh()
lw.event.fire(lw.event.RootFileSearched)
return
}
Expand Down
8 changes: 4 additions & 4 deletions src/language/symbol-document.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as vscode from 'vscode'
import { TeXElement, TeXElementType } from '../outline/structurelib/types'
import { buildBibTeX } from '../outline/structurelib/bibtex'
import { construct as constructLaTeX } from '../outline/structurelib/latex'
import { construct } from '../outline/structurelib/doctex'
import { type TeXElement, TeXElementType } from '../types'
import { buildBibTeX } from '../outline/structure/bibtex'
import { construct as constructLaTeX } from '../outline/structure/latex'
import { construct } from '../outline/structure/doctex'

export class DocSymbolProvider implements vscode.DocumentSymbolProvider {

Expand Down
4 changes: 2 additions & 2 deletions src/language/symbol-project.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode'
import { lw } from '../lw'
import { construct } from '../outline/structurelib/latex'
import { TeXElement } from '../outline/structurelib/types'
import type { TeXElement } from '../types'
import { construct } from '../outline/structure/latex'

export class ProjectSymbolProvider implements vscode.WorkspaceSymbolProvider {

Expand Down
4 changes: 2 additions & 2 deletions src/lw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { compile } from './compile'
import type { server, viewer } from './preview'
import type { locate } from './locate'
import type { lint } from './lint'
import type { outline } from './outline'

import type { Cleaner } from './extras/cleaner'
import type { LaTeXCommanderTreeView } from './extras/activity-bar'
Expand All @@ -20,7 +21,6 @@ import type { TeXMagician } from './extras/texroot'
import type { AtSuggestionCompleter, Completer } from './completion/latex'
import type { GraphicsPreview } from './preview/graphics'
import type { MathPreview } from './preview/math/mathpreview'
import type { StructureView } from './outline/project'
import type { TeXDoc } from './extras/texdoc'
import type * as commands from './core/commands'

Expand All @@ -41,13 +41,13 @@ export const lw = {
completer: Object.create(null) as Completer,
atSuggestionCompleter: Object.create(null) as AtSuggestionCompleter,
lint: {} as typeof lint,
outline: {} as typeof outline,
cleaner: Object.create(null) as Cleaner,
counter: Object.create(null) as Counter,
texdoc: Object.create(null) as TeXDoc,
texMagician: Object.create(null) as TeXMagician,
section: Object.create(null) as Section,
latexCommanderTreeView: Object.create(null) as LaTeXCommanderTreeView,
structureViewer: Object.create(null) as StructureView,
snippetView: Object.create(null) as SnippetView,
graphicsPreview: Object.create(null) as GraphicsPreview,
mathPreview: Object.create(null) as MathPreview,
Expand Down
18 changes: 15 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { locate } from './locate'
lw.locate = locate
import { lint } from './lint'
lw.lint = lint
import { outline } from './outline'
lw.outline = outline

import { MathPreviewPanelSerializer } from './extras/math-preview-panel'
import { BibtexCompleter } from './completion/bibtex'
Expand All @@ -43,7 +45,6 @@ import { TeXMagician } from './extras/texroot'
import { AtSuggestionCompleter, Completer } from './completion/latex'
import { GraphicsPreview } from './preview/graphics'
import { MathPreview } from './preview/math/mathpreview'
import { StructureView } from './outline/project'
import { TeXDoc } from './extras/texdoc'
import { parser } from './parse/parser'
import { MathJaxPool } from './preview/math/mathjaxpool'
Expand All @@ -61,7 +62,6 @@ function initialize(extensionContext: vscode.ExtensionContext) {
lw.texMagician = new TeXMagician()
lw.section = new Section()
lw.latexCommanderTreeView = new LaTeXCommanderTreeView()
lw.structureViewer = new StructureView()
lw.snippetView = new SnippetView()
lw.graphicsPreview = new GraphicsPreview()
lw.mathPreview = new MathPreview()
Expand Down Expand Up @@ -116,6 +116,11 @@ export function activate(extensionContext: vscode.ExtensionContext) {
void lw.compile.autoBuild(e.fileName, 'onSave')
lw.counter.countOnSaveIfEnabled(e.fileName)
}
// We don't check LaTeX ID as the reconstruct is handled by the Cacher.
// We don't check BibTeX ID as the reconstruct is handled by the citation completer.
if (lw.file.hasDtxLangId(e.languageId)) {
void lw.outline.reconstruct()
}
}))

/** The previous active TeX document path. If this changed, root need to be re-searched */
Expand Down Expand Up @@ -143,6 +148,12 @@ export function activate(extensionContext: vscode.ExtensionContext) {
} else if (!e || !lw.file.hasBibLangId(e.document.languageId)) {
isLaTeXActive = false
}
if (e && (
lw.file.hasTexLangId(e.document.languageId)
|| lw.file.hasBibLangId(e.document.languageId)
|| lw.file.hasDtxLangId(e.document.languageId))) {
void lw.outline.refresh()
}
}))

extensionContext.subscriptions.push(vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => {
Expand All @@ -163,7 +174,7 @@ export function activate(extensionContext: vscode.ExtensionContext) {
if (lw.file.hasTexLangId(e.textEditor.document.languageId) ||
lw.file.hasBibLangId(e.textEditor.document.languageId) ||
lw.file.hasDtxLangId(e.textEditor.document.languageId)) {
return lw.structureViewer.showCursorItem(e)
return lw.outline.reveal(e)
}
return
}))
Expand Down Expand Up @@ -204,6 +215,7 @@ function registerLatexWorkshopCommands(extensionContext: vscode.ExtensionContext
vscode.commands.registerCommand('latex-workshop.compilerlog', () => lw.commands.showLog('compiler')),
vscode.commands.registerCommand('latex-workshop.code-action', (d: vscode.TextDocument, r: vscode.Range, c: number, m: string) => lw.lint.latex.action(d, r, c, m)),
vscode.commands.registerCommand('latex-workshop.goto-section', (filePath: string, lineNumber: number) => lw.commands.gotoSection(filePath, lineNumber)),
vscode.commands.registerCommand('latex-workshop.structure-toggle-follow-cursor', () => { lw.outline.follow = !lw.outline.follow }),
vscode.commands.registerCommand('latex-workshop.navigate-envpair', () => lw.commands.navigateToEnvPair()),
vscode.commands.registerCommand('latex-workshop.select-envcontent', () => lw.commands.selectEnvContent('content')),
vscode.commands.registerCommand('latex-workshop.select-env', () => lw.commands.selectEnvContent('whole')),
Expand Down
1 change: 1 addition & 0 deletions src/outline/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { outline } from './structure'
Loading

0 comments on commit 0c24947

Please sign in to comment.