From 2cf6426910bd155b778b94b770daf67ded019d35 Mon Sep 17 00:00:00 2001 From: James Yu Date: Wed, 14 Feb 2024 13:11:45 +0000 Subject: [PATCH] Store ref math on parsing, partial #4156 --- src/completion/completer/reference.ts | 75 +++++++------ src/completion/latex.ts | 27 ++--- src/extras/math-preview-panel.ts | 2 +- src/preview/hover.ts | 6 +- src/preview/math.ts | 106 +++++++++++++----- .../math/mathpreviewlib/hoverpreviewonref.ts | 67 ----------- .../math/mathpreviewlib/texmathenvfinder.ts | 4 +- src/types.ts | 15 +-- 8 files changed, 137 insertions(+), 165 deletions(-) delete mode 100644 src/preview/math/mathpreviewlib/hoverpreviewonref.ts diff --git a/src/completion/completer/reference.ts b/src/completion/completer/reference.ts index 5899c6d74..ba5b10546 100644 --- a/src/completion/completer/reference.ts +++ b/src/completion/completer/reference.ts @@ -3,7 +3,7 @@ import * as fs from 'fs' import * as path from 'path' import type * as Ast from '@unified-latex/unified-latex-types' import { lw } from '../../lw' -import type { CompletionArgs, CompletionItem, CompletionProvider, FileCache, ReferenceDocType, ReferenceEntry } from '../../types' +import type { CompletionArgs, CompletionProvider, FileCache, ReferenceItem, TeXMathEnv } from '../../types' import { getLongestBalancedString, stripEnvironments } from '../../utils/utils' import { computeFilteringRange } from './completerutils' import { argContentToStr } from '../../utils/parser' @@ -16,7 +16,7 @@ export const reference = { } const data = { - suggestions: new Map(), + suggestions: new Map(), prevIndexObj: new Map() } @@ -31,29 +31,12 @@ function provide(line: string, position: vscode.Position): vscode.CompletionItem keys = Array.from(new Set(keys)) const items: vscode.CompletionItem[] = [] for (const key of keys) { - const suggestion = data.suggestions.get(key) - if (suggestion) { - const refDoc: ReferenceDocType = { - documentation: suggestion.documentation, - file: suggestion.file, - position: { - line: suggestion.position.line, - character: suggestion.position.character - }, - key, - label: suggestion.label, - prevIndex: suggestion.prevIndex - } - suggestion.documentation = JSON.stringify(refDoc) - items.push(suggestion) - } else { - items.push({label: key}) - } + items.push(data.suggestions.get(key) ?? {label: key}) } return items } -function getItem(token: string): ReferenceEntry | undefined { +function getItem(token: string): ReferenceItem | undefined { updateAll() return data.suggestions.get(token) } @@ -123,8 +106,6 @@ function updateAll(line?: string, position?: vscode.Position) { const label = (cachedFile in prefixes ? prefixes[cachedFile] : '') + ref.label data.suggestions.set(label, {...ref, label, - file: cachedFile, - position: 'inserting' in ref.range ? ref.range.inserting.start : ref.range.start, range, prevIndex: data.prevIndexObj.get(label) }) @@ -143,14 +124,14 @@ function parse(cache: FileCache) { if (cache.ast !== undefined) { const configuration = vscode.workspace.getConfiguration('latex-workshop') const labelMacros = configuration.get('intellisense.label.command') as string[] - cache.elements.reference = parseAst(cache.ast, cache.content.split('\n'), labelMacros) + cache.elements.reference = parseAst(cache.ast, [], cache.filePath, cache.content.split('\n'), labelMacros) } else { - cache.elements.reference = parseContent(cache.content) + cache.elements.reference = parseContent(cache.content, cache.filePath) } } -function parseAst(node: Ast.Node, lines: string[], labelMacros: string[]): CompletionItem[] { - let refs: CompletionItem[] = [] +function parseAst(node: Ast.Node, nodeStack: Ast.Node[], filePath: string, lines: string[], labelMacros: string[]): ReferenceItem[] { + let refs: ReferenceItem[] = [] if (node.type === 'macro' && ['renewcommand', 'newcommand', 'providecommand', 'DeclareMathOperator', 'renewenvironment', 'newenvironment'].includes(node.content)) { // Do not scan labels inside \newcommand, \newenvironment & co @@ -179,20 +160,24 @@ function parseAst(node: Ast.Node, lines: string[], labelMacros: string[]): Compl } if (label !== '' && node.position !== undefined) { - refs.push({ + const ref: ReferenceItem = { label, kind: vscode.CompletionItemKind.Reference, // One row before, four rows after documentation: lines.slice(node.position.start.line - 2, node.position.end.line + 4).join('\n'), // Here we abuse the definition of range to store the location of the reference definition range: new vscode.Range(node.position.start.line - 1, node.position.start.column - 1, - node.position.end.line - 1, node.position.end.column - 1) - }) + node.position.end.line - 1, node.position.end.column - 1), + file: filePath, + position: new vscode.Position(node.position.start.line - 1, node.position.start.column - 1), + math: findMath(nodeStack) + } + refs.push(ref) } const parseContentNodes = (content: Ast.Node[]) => { for (const subNode of content) { - refs = [...refs, ...parseAst(subNode, lines, labelMacros)] + refs = [...refs, ...parseAst(subNode, [...nodeStack, node], filePath, lines, labelMacros)] } } if (node.type === 'macro' && node.args) { @@ -206,9 +191,29 @@ function parseAst(node: Ast.Node, lines: string[], labelMacros: string[]): Compl return refs } -function parseContent(content: string): CompletionItem[] { +function findMath(nodeStack: Ast.Node[]): TeXMathEnv | undefined { + const node = nodeStack[nodeStack.length - 1] + if (node.type !== 'environment' && node.type !== 'mathenv') { + return + } + const env = (typeof node.env === 'string') ? node.env : (node.env as unknown as {content: string}).content + if (![ + 'align', 'align\\*', 'alignat', 'alignat\\*', 'aligned', 'alignedat', 'array', 'Bmatrix', 'bmatrix', 'cases', 'CD', 'eqnarray', 'eqnarray\\*', 'equation', 'equation\\*', 'flalign', 'flalign\\*', 'gather', 'gather\\*', 'gathered', 'matrix', 'multline', 'multline\\*', 'pmatrix', 'smallmatrix', 'split', 'subarray', 'Vmatrix', 'vmatrix' + ].includes(env)) { + return + } + const math = lw.parse.stringify(node) + return { + envname: env, + range: new vscode.Range((node.position?.start.line ?? 1) - 1, (node.position?.start.column ?? 1) - 1, + (node.position?.end.line ?? 1) - 1, (node.position?.end.column ?? 1) - 1), + texString: math + } +} + +function parseContent(content: string, filePath: string): ReferenceItem[] { const refReg = /(?:\\label(?:\[[^[\]{}]*\])?|(?:^|[,\s])label=){([^#\\}]*)}/gm - const refs: CompletionItem[] = [] + const refs: ReferenceItem[] = [] const refList: string[] = [] content = stripEnvironments(content, ['']) while (true) { @@ -230,7 +235,9 @@ function parseContent(content: string): CompletionItem[] { documentation: content.substring(prevContent.lastIndexOf('\n') + 1, result.index + followLength), // Here we abuse the definition of range to store the location of the reference definition range: new vscode.Range(positionContent.length - 1, positionContent[positionContent.length - 1].length, - positionContent.length - 1, positionContent[positionContent.length - 1].length) + positionContent.length - 1, positionContent[positionContent.length - 1].length), + file: filePath, + position: new vscode.Position(positionContent.length - 1, positionContent[positionContent.length - 1].length) }) refList.push(result[1]) } diff --git a/src/completion/latex.ts b/src/completion/latex.ts index a0fddb5aa..09f6ba24e 100644 --- a/src/completion/latex.ts +++ b/src/completion/latex.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode' import { lw } from '../lw' -import type { CompletionArgs, CompletionProvider, ReferenceDocType } from '../types' +import type { CompletionArgs, CompletionProvider, ReferenceItem } from '../types' import { citation, provider as citationProvider } from './completer/citation' import { provider as environmentProvider } from './completer/environment' import { provider as macroProvider } from './completer/macro' @@ -53,30 +53,19 @@ export class Provider implements vscode.CompletionItemProvider { return [] } - async resolveCompletionItem(item: vscode.CompletionItem, token: vscode.CancellationToken): Promise { + async resolveCompletionItem(item: vscode.CompletionItem, ctoken: vscode.CancellationToken): Promise { const configuration = vscode.workspace.getConfiguration('latex-workshop') if (item.kind === vscode.CompletionItemKind.Reference) { - if (typeof item.documentation !== 'string') { + if (!('file' in item) || !configuration.get('hover.ref.enabled')) { return item } - const data = JSON.parse(item.documentation) as ReferenceDocType - const sug = { - file: data.file, - position: new vscode.Position(data.position.line, data.position.character) - } - if (!configuration.get('hover.ref.enabled')) { - item.documentation = data.documentation - return item - } - const tex = lw.preview.math.findRef(sug, data.key) - if (tex) { - const svgDataUrl = await lw.preview.math.renderSvgOnRef(tex, data, token) - item.documentation = new vscode.MarkdownString(`![equation](${svgDataUrl})`) - return item - } else { - item.documentation = data.documentation + const refItem = item as ReferenceItem + if (!refItem.math) { return item } + const svgDataUrl = await lw.preview.math.ref2svg(refItem, ctoken) + item.documentation = new vscode.MarkdownString(`![equation](${svgDataUrl})`) + return item } else if (item.kind === vscode.CompletionItemKind.File) { const preview = configuration.get('intellisense.includegraphics.preview.enabled') as boolean if (!preview) { diff --git a/src/extras/math-preview-panel.ts b/src/extras/math-preview-panel.ts index e437adc07..864454071 100644 --- a/src/extras/math-preview-panel.ts +++ b/src/extras/math-preview-panel.ts @@ -54,7 +54,7 @@ function open() { } return } - lw.preview.math.getColor() + lw.preview.math.refreshMathColor() const panel = vscode.window.createWebviewPanel( 'latex-workshop-mathpreview', 'Math Preview', diff --git a/src/preview/hover.ts b/src/preview/hover.ts index effddf752..391a8badf 100644 --- a/src/preview/hover.ts +++ b/src/preview/hover.ts @@ -10,7 +10,7 @@ export { class HoverProvider implements vscode.HoverProvider { public async provideHover(document: vscode.TextDocument, position: vscode.Position, ctoken: vscode.CancellationToken): Promise { - lw.preview.math.getColor() + lw.preview.math.refreshMathColor() const configuration = vscode.workspace.getConfiguration('latex-workshop') const hov = configuration.get('hover.preview.enabled') as boolean const hovReference = configuration.get('hover.ref.enabled') as boolean @@ -18,10 +18,12 @@ class HoverProvider implements vscode.HoverProvider { const hovCommand = configuration.get('hover.command.enabled') as boolean if (hov) { const tex = lw.preview.math.findTeX(document, position) + // Hovered over equations if (tex) { const hover = await lw.preview.math.onTeX(document, tex, await findMacros(ctoken)) return hover } + // Hovered over graphics const graphicsHover = await lw.preview.hover(document, position) if (graphicsHover) { return graphicsHover @@ -49,7 +51,7 @@ class HoverProvider implements vscode.HoverProvider { } const refData = lw.completion.reference.getItem(token) if (hovReference && refData) { - const hover = await lw.preview.math.onRef(document, position, refData, token, ctoken) + const hover = await lw.preview.math.onRef(document, position, refData, ctoken) return hover } const cite = lw.completion.citation.getItem(token, document.uri) diff --git a/src/preview/math.ts b/src/preview/math.ts index 8efdd7ffe..9aa008227 100644 --- a/src/preview/math.ts +++ b/src/preview/math.ts @@ -4,27 +4,26 @@ import * as workerpool from 'workerpool' import type { SupportedExtension } from 'mathjax-full' import type { IMathJaxWorker } from './math/mathjax' import { lw } from '../lw' -import type { ReferenceEntry, TeXMathEnv } from '../types' +import type { ReferenceItem, TeXMathEnv } from '../types' import * as utils from '../utils/svg' import { getCurrentThemeLightness } from '../utils/theme' import { renderCursor as renderCursorWorker } from './math/mathpreviewlib/cursorrenderer' import { type ITextDocumentLike, TextDocumentLike } from './math/mathpreviewlib/textdocumentlike' import { findMacros } from './math/mathpreviewlib/newcommandfinder' import { TeXMathEnvFinder } from './math/mathpreviewlib/texmathenvfinder' -import { HoverPreviewOnRefProvider } from './math/mathpreviewlib/hoverpreviewonref' import { MathPreviewUtils } from './math/mathpreviewlib/mathpreviewutils' const logger = lw.log('Preview', 'Math') export const math = { - getColor, + refreshMathColor, onRef, onTeX, findRef, findTeX, findMath, generateSVG, - renderSvgOnRef, + ref2svg, renderCursor, typeset } @@ -35,7 +34,7 @@ const pool: workerpool.WorkerPool = workerpool.pool( ) const proxy = pool.proxy() -lw.onConfigChange('*', getColor) +lw.onConfigChange('*', refreshMathColor) lw.onConfigChange('hover.preview.mathjax.extensions', initialize) lw.onDispose({ dispose: async () => { await pool.terminate(true) } }) @@ -46,7 +45,7 @@ async function initialize() { void (await proxy).loadExtensions(extensionsToLoad) } -let color = '#000000' +let foreColor: '#000000' | '#ffffff' = '#000000' async function onTeX(document: vscode.TextDocument, tex: TeXMathEnv, macros: string): Promise { const configuration = vscode.workspace.getConfiguration('latex-workshop') @@ -54,7 +53,7 @@ async function onTeX(document: vscode.TextDocument, tex: TeXMathEnv, macros: str let s = await renderCursor(document, tex) s = MathPreviewUtils.mathjaxify(s, tex.envname) const typesetArg = macros + MathPreviewUtils.stripTeX(s, macros) - const typesetOpts = { scale, color } + const typesetOpts = { scale, color: foreColor } try { const xml = await typeset(typesetArg, typesetOpts) const md = utils.svgToDataUrl(xml) @@ -73,8 +72,7 @@ async function onTeX(document: vscode.TextDocument, tex: TeXMathEnv, macros: str async function onRef( document: vscode.TextDocument, position: vscode.Position, - refData: ReferenceEntry, - token: string, + refData: ReferenceItem, ctoken: vscode.CancellationToken ): Promise { const configuration = vscode.workspace.getConfiguration('latex-workshop') @@ -82,11 +80,8 @@ async function onRef( const link = vscode.Uri.parse('command:latex-workshop.synctexto').with({ query: JSON.stringify([line, refData.file]) }) const mdLink = new vscode.MarkdownString(`[View on pdf](${link})`) mdLink.isTrusted = true - if (configuration.get('hover.ref.enabled') as boolean) { - const tex = TeXMathEnvFinder.findHoverOnRef(document, position, refData, token) - if (tex) { - return HoverPreviewOnRefProvider.provideHoverPreviewOnRef(tex, await findMacros(ctoken), refData, color) - } + if (configuration.get('hover.ref.enabled') as boolean && refData.math) { + return onRefMathJax(refData, ctoken) } const md = '```latex\n' + refData.documentation + '\n```\n' const refRange = document.getWordRangeAtPosition(position, /\{.*?\}/) @@ -97,7 +92,69 @@ async function onRef( return new vscode.Hover([md, mdLink], refRange) } -function refNumberMessage(refData: Pick): string | undefined { +async function onRefMathJax(refData: ReferenceItem, ctoken?: vscode.CancellationToken): Promise { + const md = await ref2svg(refData, ctoken) + const line = refData.position.line + const link = vscode.Uri.parse('command:latex-workshop.synctexto').with({ query: JSON.stringify([line, refData.file]) }) + const mdLink = new vscode.MarkdownString(`[View on pdf](${link})`) + mdLink.isTrusted = true + return new vscode.Hover( [MathPreviewUtils.addDummyCodeBlock(`![equation](${md})`), mdLink], refData.math?.range ) +} + +async function ref2svg(refData: ReferenceItem, ctoken?: vscode.CancellationToken) { + if (refData.math === undefined) { + return '' + } + const configuration = vscode.workspace.getConfiguration('latex-workshop') + const scale = configuration.get('hover.preview.scale') as number + + const macros = await findMacros(ctoken) + + let newTeXString: string + if (refData.prevIndex !== undefined && configuration.get('hover.ref.number.enabled') as boolean) { + const tag = refData.prevIndex.refNumber + const texString = replaceLabelWithTag(refData.math.texString, refData.label, tag) + newTeXString = MathPreviewUtils.mathjaxify(texString, refData.math.envname, {stripLabel: false}) + } else { + newTeXString = MathPreviewUtils.mathjaxify(refData.math.texString, refData.math.envname) + } + const typesetArg = macros + MathPreviewUtils.stripTeX(newTeXString, macros) + try { + const xml = await lw.preview.math.typeset(typesetArg, { scale, color: foreColor }) + const svg = utils.svgToDataUrl(xml) + return svg + } catch(e) { + logger.logError(`Failed rendering MathJax ${typesetArg} .`, e) + throw e + } +} + +function replaceLabelWithTag(tex: string, refLabel?: string, tag?: string): string { + const texWithoutTag = tex.replace(/\\tag\{(\{[^{}]*?\}|.)*?\}/g, '') + let newTex = texWithoutTag.replace(/\\label\{(.*?)\}/g, (_matchString, matchLabel, _offset, _s) => { + if (refLabel) { + if (refLabel === matchLabel) { + if (tag) { + return `\\tag{${tag}}` + } else { + return `\\tag{${matchLabel}}` + } + } + return '\\notag' + } else { + return `\\tag{${matchLabel}}` + } + }) + // To work around a bug of \tag with multi-line environments, + // we have to put \tag after the environments. + // See https://github.com/mathjax/MathJax/issues/1020 + newTex = newTex.replace(/(\\tag\{.*?\})([\r\n\s]*)(\\begin\{(aligned|alignedat|gathered|split)\}[^]*?\\end\{\4\})/gm, '$3$2$1') + newTex = newTex.replace(/^\\begin\{(\w+?)\}/, '\\begin{$1*}') + newTex = newTex.replace(/\\end\{(\w+?)\}$/, '\\end{$1*}') + return newTex +} + +function refNumberMessage(refData: Pick): string | undefined { if (refData.prevIndex) { const refNum = refData.prevIndex.refNumber const refMessage = `numbered ${refNum} at last compilation` @@ -111,17 +168,12 @@ async function generateSVG(tex: TeXMathEnv, macros?: string) { const configuration = vscode.workspace.getConfiguration('latex-workshop') const scale = configuration.get('hover.preview.scale') as number const s = MathPreviewUtils.mathjaxify(tex.texString, tex.envname) - const xml = await typeset(macros + MathPreviewUtils.stripTeX(s, macros), {scale, color}) + const xml = await typeset(macros + MathPreviewUtils.stripTeX(s, macros), {scale, color: foreColor}) return { svgDataUrl: utils.svgToDataUrl(xml), macros } } -function getColor() { - const lightness = getCurrentThemeLightness() - if (lightness === 'light') { - color = '#000000' - } else { - color = '#ffffff' - } +function refreshMathColor() { + foreColor = getCurrentThemeLightness() === 'light' ? '#000000' : '#ffffff' } async function typeset(arg: string, opts: { scale: number, color: string }): Promise { @@ -129,7 +181,7 @@ async function typeset(arg: string, opts: { scale: number, color: string }): Pro } function renderCursor(document: vscode.TextDocument, texMath: TeXMathEnv): Promise { - return renderCursorWorker(document, texMath, color) + return renderCursorWorker(document, texMath, foreColor) } function findTeX(document: ITextDocumentLike, position: vscode.Position): TeXMathEnv | undefined { @@ -137,7 +189,7 @@ function findTeX(document: ITextDocumentLike, position: vscode.Position): TeXMat } function findRef( - refData: Pick, + refData: Pick, token: string ) { const document = TextDocumentLike.load(refData.file) @@ -145,10 +197,6 @@ function findRef( return TeXMathEnvFinder.findHoverOnRef(document, position, refData, token) } -async function renderSvgOnRef(tex: TeXMathEnv, refData: Pick, ctoken: vscode.CancellationToken) { - return HoverPreviewOnRefProvider.renderSvgOnRef(tex, await findMacros(ctoken), refData, color) -} - function findMath(document: ITextDocumentLike, position: vscode.Position): TeXMathEnv | undefined { return TeXMathEnvFinder.findMathEnvIncludingPosition(document, position) } diff --git a/src/preview/math/mathpreviewlib/hoverpreviewonref.ts b/src/preview/math/mathpreviewlib/hoverpreviewonref.ts deleted file mode 100644 index cd92dbe01..000000000 --- a/src/preview/math/mathpreviewlib/hoverpreviewonref.ts +++ /dev/null @@ -1,67 +0,0 @@ -import * as vscode from 'vscode' -import { lw } from '../../../lw' -import type { ReferenceEntry, TeXMathEnv } from '../../../types' -import * as utils from '../../../utils/svg' -import { MathPreviewUtils } from './mathpreviewutils' - -const logger = lw.log('Preview', 'Hover') - -export class HoverPreviewOnRefProvider { - static async provideHoverPreviewOnRef(tex: TeXMathEnv, macros: string, refData: ReferenceEntry, color: string): Promise { - const md = await HoverPreviewOnRefProvider.renderSvgOnRef(tex, macros, refData, color) - const line = refData.position.line - const link = vscode.Uri.parse('command:latex-workshop.synctexto').with({ query: JSON.stringify([line, refData.file]) }) - const mdLink = new vscode.MarkdownString(`[View on pdf](${link})`) - mdLink.isTrusted = true - return new vscode.Hover( [MathPreviewUtils.addDummyCodeBlock(`![equation](${md})`), mdLink], tex.range ) - } - - static async renderSvgOnRef(tex: TeXMathEnv, macros: string, refData: Pick, color: string) { - const configuration = vscode.workspace.getConfiguration('latex-workshop') - const scale = configuration.get('hover.preview.scale') as number - - let newTeXString: string - if (refData.prevIndex !== undefined && configuration.get('hover.ref.number.enabled') as boolean) { - const tag = refData.prevIndex.refNumber - const texString = HoverPreviewOnRefProvider.replaceLabelWithTag(tex.texString, refData.label, tag) - newTeXString = MathPreviewUtils.mathjaxify(texString, tex.envname, {stripLabel: false}) - } else { - newTeXString = MathPreviewUtils.mathjaxify(tex.texString, tex.envname) - } - const typesetArg = macros + MathPreviewUtils.stripTeX(newTeXString, macros) - const typesetOpts = { scale, color } - try { - const xml = await lw.preview.math.typeset(typesetArg, typesetOpts) - const svg = utils.svgToDataUrl(xml) - return svg - } catch(e) { - logger.logError(`Failed rendering MathJax ${typesetArg} .`, e) - throw e - } - } - - private static replaceLabelWithTag(tex: string, refLabel?: string, tag?: string): string { - const texWithoutTag = tex.replace(/\\tag\{(\{[^{}]*?\}|.)*?\}/g, '') - let newTex = texWithoutTag.replace(/\\label\{(.*?)\}/g, (_matchString, matchLabel, _offset, _s) => { - if (refLabel) { - if (refLabel === matchLabel) { - if (tag) { - return `\\tag{${tag}}` - } else { - return `\\tag{${matchLabel}}` - } - } - return '\\notag' - } else { - return `\\tag{${matchLabel}}` - } - }) - // To work around a bug of \tag with multi-line environments, - // we have to put \tag after the environments. - // See https://github.com/mathjax/MathJax/issues/1020 - newTex = newTex.replace(/(\\tag\{.*?\})([\r\n\s]*)(\\begin\{(aligned|alignedat|gathered|split)\}[^]*?\\end\{\4\})/gm, '$3$2$1') - newTex = newTex.replace(/^\\begin\{(\w+?)\}/, '\\begin{$1*}') - newTex = newTex.replace(/\\end\{(\w+?)\}$/, '\\end{$1*}') - return newTex - } -} diff --git a/src/preview/math/mathpreviewlib/texmathenvfinder.ts b/src/preview/math/mathpreviewlib/texmathenvfinder.ts index 6ae33c94a..8b21b387e 100644 --- a/src/preview/math/mathpreviewlib/texmathenvfinder.ts +++ b/src/preview/math/mathpreviewlib/texmathenvfinder.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode' -import type { ReferenceEntry, TeXMathEnv } from '../../../types' +import type { ReferenceItem, TeXMathEnv } from '../../../types' import * as utils from '../../../utils/utils' import { type ITextDocumentLike, TextDocumentLike } from './textdocumentlike' @@ -30,7 +30,7 @@ export class TeXMathEnvFinder { static findHoverOnRef( document: ITextDocumentLike, position: vscode.Position, - refData: Pick, + refData: Pick, token: string, ): TeXMathEnv | undefined { const limit = vscode.workspace.getConfiguration('latex-workshop').get('hover.preview.maxLines') as number diff --git a/src/types.ts b/src/types.ts index f9c0971ff..c3a11f890 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,7 +12,7 @@ export type FileCache = { /** Completion items */ elements: { /** \ref{} items */ - reference?: CompletionItem[], + reference?: ReferenceItem[], /** \gls items */ glossary?: GlossaryItem[], /** \begin{} items */ @@ -216,24 +216,17 @@ export type Macro = { postAction?: string } -export interface ReferenceEntry extends CompletionItem { +export interface ReferenceItem extends CompletionItem { /** The file that defines the ref. */ file: string, /** The position that defines the ref. */ position: vscode.Position, + /** Math macros */ + math?: TeXMathEnv, /** Stores the ref number. */ prevIndex?: {refNumber: string, pageNumber: string} } -export type ReferenceDocType = { - documentation: ReferenceEntry['documentation'], - file: ReferenceEntry['file'], - position: {line: number, character: number}, - key: string, - label: ReferenceEntry['label'], - prevIndex: ReferenceEntry['prevIndex'] -} - export enum GlossaryType { glossary, acronym