diff --git a/src/components/cacher.ts b/src/components/cacher.ts index bd43950e4..971b21db4 100644 --- a/src/components/cacher.ts +++ b/src/components/cacher.ts @@ -160,7 +160,6 @@ export class Cacher { } logger.log(`Updated inputs of ${filePath} .`) - lw.eventBus.fire(eventbus.FileParsed, filePath) } private async updateElements(filePath: string, content: string, contentTrimmed: string) { diff --git a/test/fixtures/armory/intellisense_base.tex b/test/fixtures/armory/intellisense/base.tex similarity index 100% rename from test/fixtures/armory/intellisense_base.tex rename to test/fixtures/armory/intellisense/base.tex diff --git a/test/fixtures/armory/intellisense/class_option_with_brace.tex b/test/fixtures/armory/intellisense/class_option_with_brace.tex new file mode 100644 index 000000000..2af31797f --- /dev/null +++ b/test/fixtures/armory/intellisense/class_option_with_brace.tex @@ -0,0 +1,7 @@ +\documentclass[aspectratio=169,t,fontset=none,xcolor={x11names},]{ctexbeamer} +\usepackage[savemem,formats]{listings} +\begin{document} +\begin{lstlisting}[style={bash},] +Exception in thread "main" java.lang.ArithmeticException: / by zero +\end{lstlisting} +\end{document} diff --git a/test/fixtures/armory/intellisense_glossary.tex b/test/fixtures/armory/intellisense/glossary.tex similarity index 100% rename from test/fixtures/armory/intellisense_glossary.tex rename to test/fixtures/armory/intellisense/glossary.tex diff --git a/test/fixtures/armory/intellisense_glossaryentries.tex b/test/fixtures/armory/intellisense/glossaryentries.tex similarity index 100% rename from test/fixtures/armory/intellisense_glossaryentries.tex rename to test/fixtures/armory/intellisense/glossaryentries.tex diff --git a/test/fixtures/armory/intellisense_sub.tex b/test/fixtures/armory/intellisense/sub.tex similarity index 100% rename from test/fixtures/armory/intellisense_sub.tex rename to test/fixtures/armory/intellisense/sub.tex diff --git a/test/suites/04_intellisense.test.ts b/test/suites/04_intellisense.test.ts index b4caa3464..a6d91a574 100644 --- a/test/suites/04_intellisense.test.ts +++ b/test/suites/04_intellisense.test.ts @@ -5,11 +5,12 @@ import * as assert from 'assert' import rimraf from 'rimraf' import glob from 'glob' import * as lw from '../../src/lw' -import { sleep, getIntellisense, runTest, openActive, writeTestFile, loadTestFile, waitFileParsed } from './utils' +import { sleep, getIntellisense, runTest, openActive, writeTestFile, loadTestFile, waitEvent } from './utils' import { EnvSnippetType, EnvType } from '../../src/providers/completer/environment' import { CmdType } from '../../src/providers/completer/command' import { PkgType } from '../../src/providers/completion' import { isTriggerSuggestNeeded } from '../../src/providers/completer/commandlib/commandfinder' +import { FileParsed } from '../../src/components/eventbus' function assertKeys(keys: string[], expected: string[] = [], message: string): void { assert.ok( @@ -122,8 +123,8 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'command intellisense', async () => { await loadTestFile(fixture, [ - {src: 'intellisense_base.tex', dst: 'main.tex'}, - {src: 'intellisense_sub.tex', dst: 'sub/s.tex'} + {src: 'intellisense/base.tex', dst: 'main.tex'}, + {src: 'intellisense/sub.tex', dst: 'sub/s.tex'} ]) const result = await openActive(fixture, 'main.tex') const items = getIntellisense(result.doc, new vscode.Position(0, 1)) @@ -134,7 +135,6 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'command intellisense with usepackage', async () => { await loadTestFile(fixture, [{src: 'intellisense/package_on_cmd_1.tex', dst: 'main.tex'}]) let result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) let items = getIntellisense(result.doc, new vscode.Position(0, 1)) assert.ok(items) assert.ok(items.length > 0) @@ -146,7 +146,6 @@ suite('Intellisense test suite', () => { await loadTestFile(fixture, [{src: 'intellisense/package_on_cmd_2.tex', dst: 'main.tex'}]) result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) items = getIntellisense(result.doc, new vscode.Position(2, 1)) assert.ok(items) assert.ok(items.length > 0) @@ -158,7 +157,6 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'command intellisense with usepackage and option', async () => { await loadTestFile(fixture, [{src: 'intellisense/package_option_on_cmd.tex', dst: 'main.tex'}]) let result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) let items = getIntellisense(result.doc, new vscode.Position(2, 1)) assert.ok(items) assert.ok(items.length > 0) @@ -170,7 +168,6 @@ suite('Intellisense test suite', () => { await loadTestFile(fixture, [{src: 'intellisense/package_on_cmd_2.tex', dst: 'main.tex'}]) result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) items = getIntellisense(result.doc, new vscode.Position(2, 1)) assert.ok(items) assert.ok(items.length > 0) @@ -182,11 +179,10 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'command intellisense with config `intellisense.argumentHint.enabled`', async () => { await vscode.workspace.getConfiguration('latex-workshop').update('intellisense.argumentHint.enabled', true) await loadTestFile(fixture, [ - {src: 'intellisense_base.tex', dst: 'main.tex'}, - {src: 'intellisense_sub.tex', dst: 'sub/s.tex'} + {src: 'intellisense/base.tex', dst: 'main.tex'}, + {src: 'intellisense/sub.tex', dst: 'sub/s.tex'} ]) const result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) let items = getIntellisense(result.doc, new vscode.Position(0, 1)) assert.ok(items) assert.ok(items.length > 0) @@ -199,7 +195,9 @@ suite('Intellisense test suite', () => { assert.ok(snippet.value.includes('${1:')) await vscode.workspace.getConfiguration('latex-workshop').update('intellisense.argumentHint.enabled', false) + const wait = waitEvent(FileParsed, path.resolve(fixture, 'main.tex')) await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) + await wait items = getIntellisense(result.doc, new vscode.Position(0, 1)) assert.ok(items) assert.ok(items.length > 0) @@ -215,8 +213,8 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'command intellisense with config `intellisense.commandsJSON.replace`', async () => { await vscode.workspace.getConfiguration('latex-workshop').update('intellisense.commandsJSON.replace', {'mathbb{}': ''}) await loadTestFile(fixture, [ - {src: 'intellisense_base.tex', dst: 'main.tex'}, - {src: 'intellisense_sub.tex', dst: 'sub/s.tex'} + {src: 'intellisense/base.tex', dst: 'main.tex'}, + {src: 'intellisense/sub.tex', dst: 'sub/s.tex'} ]) const result = await openActive(fixture, 'main.tex') let items = getIntellisense(result.doc, new vscode.Position(0, 1)) @@ -238,8 +236,8 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'reference intellisense and config intellisense.label.keyval', async () => { await vscode.workspace.getConfiguration('latex-workshop').update('intellisense.label.keyval', true) await loadTestFile(fixture, [ - {src: 'intellisense_base.tex', dst: 'main.tex'}, - {src: 'intellisense_sub.tex', dst: 'sub/s.tex'} + {src: 'intellisense/base.tex', dst: 'main.tex'}, + {src: 'intellisense/sub.tex', dst: 'sub/s.tex'} ]) const result = await openActive(fixture, 'main.tex') let items = getIntellisense(result.doc, new vscode.Position(8, 5)) @@ -251,7 +249,9 @@ suite('Intellisense test suite', () => { assert.ok(labels.includes('eq1')) await vscode.workspace.getConfiguration('latex-workshop').update('intellisense.label.keyval', false) + const wait = waitEvent(FileParsed, path.resolve(fixture, 'main.tex')) await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) + await wait items = getIntellisense(result.doc, new vscode.Position(8, 5)) assert.ok(items) assert.ok(items.length > 0) @@ -263,8 +263,8 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'environment intellisense', async () => { await loadTestFile(fixture, [ - {src: 'intellisense_base.tex', dst: 'main.tex'}, - {src: 'intellisense_sub.tex', dst: 'sub/s.tex'} + {src: 'intellisense/base.tex', dst: 'main.tex'}, + {src: 'intellisense/sub.tex', dst: 'sub/s.tex'} ]) const result = await openActive(fixture, 'main.tex') const items = getIntellisense(result.doc, new vscode.Position(9, 7)) @@ -275,7 +275,6 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'environment intellisense with usepackage', async () => { await loadTestFile(fixture, [{src: 'intellisense/package_on_env_1.tex', dst: 'main.tex'}]) let result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) let items = getIntellisense(result.doc, new vscode.Position(3, 7)) assert.ok(items) assert.ok(items.length > 0) @@ -287,7 +286,6 @@ suite('Intellisense test suite', () => { await loadTestFile(fixture, [{src: 'intellisense/package_on_env_2.tex', dst: 'main.tex'}]) result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) items = getIntellisense(result.doc, new vscode.Position(3, 7)) assert.ok(items) assert.ok(items.length > 0) @@ -299,7 +297,6 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'environment intellisense with usepackage and option', async () => { await loadTestFile(fixture, [{src: 'intellisense/package_option_on_env.tex', dst: 'main.tex'}]) let result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) let items = getIntellisense(result.doc, new vscode.Position(3, 7)) assert.ok(items) assert.ok(items.length > 0) @@ -311,7 +308,6 @@ suite('Intellisense test suite', () => { await loadTestFile(fixture, [{src: 'intellisense/package_on_env_2.tex', dst: 'main.tex'}]) result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) items = getIntellisense(result.doc, new vscode.Position(3, 7)) assert.ok(items) assert.ok(items.length > 0) @@ -323,7 +319,6 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'environment as command intellisense with usepackage and option', async () => { await loadTestFile(fixture, [{src: 'intellisense/package_option_on_env.tex', dst: 'main.tex'}]) let result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) let items = getIntellisense(result.doc, new vscode.Position(3, 1)) assert.ok(items) assert.ok(items.length > 0) @@ -335,7 +330,6 @@ suite('Intellisense test suite', () => { await loadTestFile(fixture, [{src: 'intellisense/package_on_env_2.tex', dst: 'main.tex'}]) result = await openActive(fixture, 'main.tex') - await lw.cacher.refreshContext(path.resolve(fixture, 'main.tex')) items = getIntellisense(result.doc, new vscode.Position(3, 1)) assert.ok(items) assert.ok(items.length > 0) @@ -346,8 +340,8 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'argument intellisense', async () => { await loadTestFile(fixture, [ - {src: 'intellisense_base.tex', dst: 'main.tex'}, - {src: 'intellisense_sub.tex', dst: 'sub/s.tex'} + {src: 'intellisense/base.tex', dst: 'main.tex'}, + {src: 'intellisense/sub.tex', dst: 'sub/s.tex'} ]) const result = await openActive(fixture, 'main.tex') let items = getIntellisense(result.doc, new vscode.Position(0, 15)) @@ -375,10 +369,26 @@ suite('Intellisense test suite', () => { assert.ok(labels.includes('showlines')) }) + runTest(suiteName, fixtureName, 'argument intellisense with braces', async () => { + await loadTestFile(fixture, [{src: 'intellisense/class_option_with_brace.tex', dst: 'main.tex'}]) + const wait = waitEvent(FileParsed, path.resolve(fixture, 'main.tex')) + const result = await openActive(fixture, 'main.tex') + await wait + let items = getIntellisense(result.doc, new vscode.Position(0, 64)) + assert.ok(items) + let labels = items.map(item => item.label.toString()) + assert.ok(labels.includes('10pt')) + + items = getIntellisense(result.doc, new vscode.Position(3, 32)) + assert.ok(items) + labels = items.map(item => item.label.toString()) + assert.ok(labels.includes('label=')) + }) + runTest(suiteName, fixtureName, 'package and documentclass intellisense', async () => { await loadTestFile(fixture, [ - {src: 'intellisense_base.tex', dst: 'main.tex'}, - {src: 'intellisense_sub.tex', dst: 'sub/s.tex'} + {src: 'intellisense/base.tex', dst: 'main.tex'}, + {src: 'intellisense/sub.tex', dst: 'sub/s.tex'} ]) const result = await openActive(fixture, 'main.tex') let items = getIntellisense(result.doc, new vscode.Position(2, 21)) @@ -398,9 +408,9 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'input/include/import/subimport intellisense', async () => { await loadTestFile(fixture, [ - {src: 'intellisense_base.tex', dst: 'main.tex'}, - {src: 'intellisense_sub.tex', dst: 'sub/s.tex'}, - {src: 'intellisense_sub.tex', dst: 'sub/plain.tex'} + {src: 'intellisense/base.tex', dst: 'main.tex'}, + {src: 'intellisense/sub.tex', dst: 'sub/s.tex'}, + {src: 'intellisense/sub.tex', dst: 'sub/plain.tex'} ]) const result = await openActive(fixture, 'main.tex') let items = getIntellisense(result.doc, new vscode.Position(7, 7)) @@ -444,7 +454,7 @@ suite('Intellisense test suite', () => { writeTestFile(fixture, 'main.tex', '\\documentclass{article}', '\\begin{document}', 'abc\\cite{}', '\\bibliography{main}', '\\end{document}') await loadTestFile(fixture, [{src: 'base.bib', dst: 'main.bib'}]) const result = await openActive(fixture, 'main.tex') - const wait = waitFileParsed(path.resolve(fixture, 'main.bib')) + const wait = waitEvent(FileParsed, path.resolve(fixture, 'main.bib')) await lw.completer.citation.parseBibFile(path.resolve(fixture, 'main.bib')) await wait @@ -479,8 +489,8 @@ suite('Intellisense test suite', () => { runTest(suiteName, fixtureName, 'glossary intellisense', async () => { await loadTestFile(fixture, [ - {src: 'intellisense_glossary.tex', dst: 'main.tex'}, - {src: 'intellisense_glossaryentries.tex', dst: 'sub/glossary.tex'} + {src: 'intellisense/glossary.tex', dst: 'main.tex'}, + {src: 'intellisense/glossaryentries.tex', dst: 'sub/glossary.tex'} ]) const result = await openActive(fixture, 'main.tex') await lw.cacher.refreshContext(path.resolve(fixture, 'sub/glossary.tex'), fs.readFileSync(path.resolve(fixture, 'sub/glossary.tex')).toString()) @@ -501,8 +511,8 @@ suite('Intellisense test suite', () => { const replaces = {'@+': '\\sum', '@8': '', '@M': '\\sum'} await vscode.workspace.getConfiguration('latex-workshop').update('intellisense.atSuggestionJSON.replace', replaces) await loadTestFile(fixture, [ - {src: 'intellisense_base.tex', dst: 'main.tex'}, - {src: 'intellisense_sub.tex', dst: 'sub/s.tex'} + {src: 'intellisense/base.tex', dst: 'main.tex'}, + {src: 'intellisense/sub.tex', dst: 'sub/s.tex'} ]) const result = await openActive(fixture, 'main.tex') let items = getIntellisense(result.doc, new vscode.Position(5, 1), true) diff --git a/test/suites/utils.ts b/test/suites/utils.ts index 6af651f13..c46a04cdf 100644 --- a/test/suites/utils.ts +++ b/test/suites/utils.ts @@ -5,7 +5,7 @@ import * as glob from 'glob' import * as os from 'os' import * as assert from 'assert' import * as lw from '../../src/lw' -import { BuildDone, FileParsed, FileWatched, ViewerPageLoaded, ViewerStatusChanged } from '../../src/components/eventbus' +import { BuildDone, FileParsed, FileWatched, RootFileSearched, ViewerPageLoaded, ViewerStatusChanged } from '../../src/components/eventbus' import type { EventName } from '../../src/components/eventbus' let testCounter = 0 @@ -94,19 +94,21 @@ export async function loadTestFile(fixture: string, files: {src: string, dst: st await sleep(250) } -export async function openActive(fixture: string, fileName: string, skipSleep: boolean = false) { +export async function openActive(fixture: string, fileName: string) { const texFilePath = vscode.Uri.file(path.join(fixture, fileName)) + let wait = waitEvent(FileParsed, path.resolve(fixture, fileName)) const doc = await vscode.workspace.openTextDocument(texFilePath) await vscode.window.showTextDocument(doc) - if (!skipSleep) { - await sleep(250) - } + await lw.cacher.refreshContext(path.resolve(fixture, fileName)) + await wait + wait = waitEvent(RootFileSearched) const root = await lw.manager.findRoot() + await wait return {root, doc} } export async function assertBuild(fixture: string, texName: string, pdfName: string, build?: () => unknown) { - await openActive(fixture, texName, true) + await openActive(fixture, texName) if (build) { await build() } else { @@ -133,7 +135,7 @@ export async function assertAutoBuild(fixture: string, texName: string, pdfName: await wait } - wait = waitBuild() + wait = waitEvent(BuildDone) if (mode?.includes('onSave')) { await vscode.commands.executeCommand('workbench.action.files.save') } else { @@ -163,10 +165,6 @@ export async function waitEvent(event: EventName, arg?: any) { }) } -export async function waitBuild() { - return waitEvent(BuildDone) -} - export async function assertRoot(fixture: string, openName: string, rootName: string) { await vscode.commands.executeCommand('latex-workshop.activate') const result = await openActive(fixture, openName) @@ -190,10 +188,6 @@ export async function assertViewer(fixture: string, pdfName: string, action?: () assert.strictEqual(status.pdfFileUri, vscode.Uri.file(path.resolve(fixture, pdfName)).toString(true)) } -export async function waitFileParsed(fileName: string) { - return waitEvent(FileParsed, fileName) -} - export function getIntellisense(doc: vscode.TextDocument, pos: vscode.Position, atSuggestion = false) { const completer = atSuggestion ? lw.atSuggestionCompleter : lw.completer return completer?.provideCompletionItems(