Skip to content

Commit

Permalink
Modularize viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Dec 7, 2023
1 parent fc5c958 commit 29ee757
Show file tree
Hide file tree
Showing 14 changed files with 494 additions and 492 deletions.
4 changes: 2 additions & 2 deletions src/compile/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ function handleUserTermination() {
async function afterSuccessfulBuilt(lastStep: Step, skipped: boolean) {
if (lastStep.rootFile === undefined) {
// This only happens when the step is an external command.
lw.viewer.refreshExistingViewer()
lw.viewer.refresh()
return
}
logger.log(`Successfully built ${lastStep.rootFile} .`)
Expand All @@ -414,7 +414,7 @@ async function afterSuccessfulBuilt(lastStep: Step, skipped: boolean) {
if (!lastStep.isExternal && skipped) {
return
}
lw.viewer.refreshExistingViewer(lw.file.getPdfPath(lastStep.rootFile))
lw.viewer.refresh(lw.file.getPdfPath(lastStep.rootFile))
lw.completer.reference.setNumbersFromAuxFile(lastStep.rootFile)
await lw.cache.loadFlsFile(lastStep.rootFile ?? '')
const configuration = vscode.workspace.getConfiguration('latex-workshop', vscode.Uri.file(lastStep.rootFile))
Expand Down
4 changes: 2 additions & 2 deletions src/core/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ export async function view(mode?: 'tab' | 'browser' | 'external' | vscode.Uri) {
if (!pickedRootFile) {
return
}
return lw.viewer.open(lw.file.getPdfPath(pickedRootFile), typeof mode === 'string' ? mode : undefined)
return lw.viewer.view(lw.file.getPdfPath(pickedRootFile), typeof mode === 'string' ? mode : undefined)
}

export function refresh() {
logger.log('REFRESH command invoked.')
lw.viewer.refreshExistingViewer()
lw.viewer.refresh()
}

export function kill() {
Expand Down
4 changes: 2 additions & 2 deletions src/locate/synctex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ export class Locator {
if (!record) {
return
}
void lw.viewer.syncTeX(pdfFile, record)
void lw.viewer.locate(pdfFile, record)
} catch (e) {
logger.logError('Forward SyncTeX failed.', e)
}
} else {
void this.invokeSyncTeXCommandForward(line, character, filePath, pdfFile).then( (record) => {
if (pdfFile) {
void lw.viewer.syncTeX(pdfFile, record)
void lw.viewer.locate(pdfFile, record)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/lw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { watcher } from './core/watcher'
import type { cache } from './core/cache'
import type { root } from './core/root'
import type { compile } from './compile'
import type { viewer } from './preview'

import type { Cleaner } from './extras/cleaner'
import type { LaTeXCommanderTreeView } from './extras/activity-bar'
Expand All @@ -20,7 +21,6 @@ import type { dupLabelDetector } from './lint/duplicate-label'
import type { Server } from './preview/server'
import type { SnippetView } from './extras/snippet-view'
import type { TeXMagician } from './extras/texroot'
import type { Viewer } from './preview/viewer'
import type { CodeActions } from './lint/latex-code-actions'
import type { AtSuggestionCompleter, Completer } from './completion/latex'
import type { GraphicsPreview } from './preview/graphics'
Expand All @@ -41,7 +41,7 @@ export const lw = {
root: {} as typeof root,
compile: {} as typeof compile,
lwfs: Object.create(null) as LwFileSystem,
viewer: Object.create(null) as Viewer,
viewer: {} as typeof viewer,
server: Object.create(null) as Server,
locator: Object.create(null) as Locator,
completer: Object.create(null) as Completer,
Expand Down
9 changes: 4 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import { root } from './core/root'
lw.root = root
import { compile } from './compile'
lw.compile = compile
import { viewer } from './preview'
lw.viewer = viewer

import { pdfViewerHookProvider, pdfViewerPanelSerializer } from './preview/viewer'
import { MathPreviewPanelSerializer } from './extras/math-preview-panel'
import { BibtexCompleter } from './completion/bibtex'
import { HoverProvider } from './preview/hover'
Expand All @@ -42,7 +43,6 @@ import { Section } from './extras/section'
import { Server } from './preview/server'
import { SnippetView } from './extras/snippet-view'
import { TeXMagician } from './extras/texroot'
import { Viewer } from './preview/viewer'
import { CodeActions } from './lint/latex-code-actions'
import { AtSuggestionCompleter, Completer } from './completion/latex'
import { GraphicsPreview } from './preview/graphics'
Expand All @@ -58,7 +58,6 @@ const logger = lw.log('Extension')
function initialize(extensionContext: vscode.ExtensionContext) {
lw.onConfigChange(undefined, undefined, undefined, extensionContext.subscriptions)
lw.lwfs = new LwFileSystem()
lw.viewer = new Viewer()
lw.server = new Server()
lw.locator = new Locator()
lw.completer = new Completer()
Expand Down Expand Up @@ -298,8 +297,8 @@ function registerProviders(extensionContext: vscode.ExtensionContext) {
)

extensionContext.subscriptions.push(
vscode.window.registerWebviewPanelSerializer('latex-workshop-pdf', pdfViewerPanelSerializer),
vscode.window.registerCustomEditorProvider('latex-workshop-pdf-hook', pdfViewerHookProvider, {supportsMultipleEditorsPerDocument: true, webviewOptions: {retainContextWhenHidden: true}}),
vscode.window.registerWebviewPanelSerializer('latex-workshop-pdf', lw.viewer.serializer),
vscode.window.registerCustomEditorProvider('latex-workshop-pdf-hook', lw.viewer.hook, {supportsMultipleEditorsPerDocument: true, webviewOptions: {retainContextWhenHidden: true}}),
vscode.window.registerWebviewPanelSerializer('latex-workshop-mathpreview', new MathPreviewPanelSerializer())
)

Expand Down
1 change: 1 addition & 0 deletions src/preview/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as viewer from './viewer'
6 changes: 2 additions & 4 deletions src/preview/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { lw } from '../lw'
import * as PdfFilePathEncoder from './serverlib/encodepath'
import { EventEmitter } from 'events'

import { viewerManager } from './viewerlib/pdfviewermanager'

const logger = lw.log('Server')

class WsServer extends ws.Server {
Expand Down Expand Up @@ -187,7 +185,7 @@ export class Server {
if (PdfFilePathEncoder.hasPrefix(request.url) && !request.url.includes('viewer.html')) {
const s = request.url.replace('/', '')
const fileUri = PdfFilePathEncoder.decodePathWithPrefix(s)
if (viewerManager.getClientSet(fileUri) === undefined) {
if (!lw.viewer.isViewing(fileUri)) {
logger.log(`Invalid PDF request: ${fileUri.toString(true)}`)
return
}
Expand All @@ -203,7 +201,7 @@ export class Server {
return
}
if (request.url.endsWith('/config.json')) {
const params = lw.viewer.viewerParams()
const params = lw.viewer.getParams()
const content = JSON.stringify(params)
this.sendOkResponse(response, Buffer.from(content), 'application/json')
return
Expand Down
Loading

0 comments on commit 29ee757

Please sign in to comment.