* Use VS Code 1.46.0 for tests.

* Get the state of the PDF viewer through WebView API instead of Websocket.
* Remove `request_state` protocol.
This commit is contained in:
Takashi Tamura 2020-06-14 10:15:18 +09:00
parent cfd3af362c
commit 6bb95c2058
6 changed files with 15 additions and 50 deletions

View File

@ -4,7 +4,7 @@ import * as os from 'os'
import ws from 'ws'
import * as path from 'path'
import * as cs from 'cross-spawn'
import {escapeHtml, sleep} from '../utils/utils'
import {escapeHtml} from '../utils/utils'
import {Extension} from '../main'
import {SyncTeXRecordForward} from './locator'
@ -26,11 +26,6 @@ class Client {
}
}
export type ViewerState = {
path: string,
scrollTop: number
}
class PdfViewerPanel {
readonly webviewPanel: vscode.WebviewPanel
readonly pdfFilePath: string
@ -91,7 +86,6 @@ export class Viewer {
extension: Extension
clients: {[key: string]: Set<Client>} = {}
webviewPanels: Map<string, Set<PdfViewerPanel>> = new Map()
stateMessageQueue: Map<string, ViewerState[]> = new Map()
pdfViewerPanelSerializer: PdfViewerPanelSerializer
constructor(extension: Extension) {
@ -413,14 +407,6 @@ export class Viewer {
// nothing to do
break
}
case 'state': {
const results = this.stateMessageQueue.get(data.path)
if (!results) {
break
}
results.push({ path: data.path, scrollTop: data.scrollTop })
break
}
default: {
this.extension.logger.addLogMessage(`Unknown websocket message: ${msg}`)
break
@ -466,24 +452,12 @@ export class Viewer {
return
}
async getViewerState(pdfFilePath: string): Promise<ViewerState[]> {
const clients = this.getClients(pdfFilePath)
if (clients === undefined || clients.size === 0) {
getViewerState(pdfFilePath: string): (PdfViewerState | undefined)[] {
const panelSet = this.getPanelSet(pdfFilePath)
if (!panelSet) {
return []
}
this.stateMessageQueue.set(pdfFilePath, [])
for (const client of clients) {
client.send({type: 'request_state'})
}
for (let i = 0; i < 30; i++) {
const results = this.stateMessageQueue.get(pdfFilePath)
if (results && results.length > 0) {
this.stateMessageQueue.delete(pdfFilePath)
return results
}
await sleep(100)
}
throw new Error('Cannot get viewer state.')
return Array.from(panelSet).map( e => e.state )
}
}

View File

@ -44,7 +44,7 @@ async function runTestsOnEachFixture(targetName: 'build' | 'viewer' | 'completio
for (const testWorkspace of testBuildWorkspaces) {
const nodejsTimeout = setTimeout(() => process.exit(1), firstTime ? 3*60000 : 60000)
await runTests({
version: '1.42.1',
version: '1.46.0',
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [

View File

@ -130,8 +130,13 @@ export async function getViewerStatus(pdfFilePath: string) {
const extension = await waitLatexWorkshopActivated()
return await waitUntil(async () => {
try {
const rs = await extension.exports.viewer.getViewerStatus?.(pdfFilePath)
return rs && rs.length > 0 ? rs : undefined
const rs = extension.exports.viewer.getViewerStatus?.(pdfFilePath)
const ret = rs && rs.find(st => st)
if (ret && ret.path !== undefined && ret.scrollTop !== undefined) {
return [{ path: ret.path, scrollTop: ret.scrollTop }]
} else {
return undefined
}
} catch (e) {
return
}

View File

@ -182,7 +182,7 @@ suite('PDF Viewer test suite', () => {
for (const result of secondResults) {
assert.ok( Math.abs(result.scrollTop) > 10 )
}
}, () => os.platform() !== 'linux')
}, () => os.platform() === 'win32')
runTestWithFixture('fixture021', 'basic build, view, and synctex with synctex.afterBuild.enabled', async () => {
const fixtureDir = getFixtureDir()
@ -217,5 +217,5 @@ suite('PDF Viewer test suite', () => {
for (const result of secondResults) {
assert.ok( Math.abs(result.scrollTop) > 10 )
}
}, () => os.platform() !== 'linux')
}, () => os.platform() === 'win32')
})

View File

@ -1,7 +1,5 @@
export type ServerResponse = {
type: 'refresh'
} | {
type: 'request_state'
} | {
type: 'params',
scale: string,
@ -44,10 +42,6 @@ export type ClientRequest = {
url: string
} | {
type: 'ping'
} | {
type: 'state',
path: string,
scrollTop: number
} | {
type: 'reverse_synctex',
path: string,

View File

@ -243,14 +243,6 @@ class LateXWorkshopPdfViewer implements ILatexWorkshopPdfViewer {
}
break
}
case 'request_state': {
this.send( {
type: 'state',
path: this.pdfFilePath,
scrollTop: (document.getElementById('viewerContainer') as HTMLElement).scrollTop
})
break
}
default: {
break
}