Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! feat: modify BracketReplacer to display b…
Browse files Browse the repository at this point in the history
…racket sizes using MathJax rendering.
  • Loading branch information
tamuratak committed Jan 30, 2025
1 parent 9414924 commit 3fa1bf2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/providers/completionlib/bracketreplacer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getPrevChar } from './utils/position.js'
import { ContextAwareKind } from './completionkind.js'
import type { MathPreview } from '../../components/mathpreview.js'
import { ExternalPromise } from '../../utils/externalpromise.js'
import { Logger } from '../../components/logger.js'


export class BracketReplacer implements IContexAwareProvider {
Expand Down Expand Up @@ -85,22 +86,28 @@ export class BracketReplacer implements IContexAwareProvider {
private readonly bracketDocumentMapPromise = new ExternalPromise<Map<string, vscode.MarkdownString>>()

constructor(private readonly extension: {
readonly logger: Logger,
readonly mathPreview: MathPreview
}) {
setTimeout(() => this.initializeBracketDocumentMap(), 0)
}

async initializeBracketDocumentMap() {
const bracketDocumentMap = new Map<string, vscode.MarkdownString>()
for (const [_, pairs] of this.bracketPairs) {
for (const [key, pairs] of this.bracketPairs) {
if (key === '04') {
continue
}
for (const [left, right] of pairs) {
try {
const {svgDataUrl} = await this.extension.mathPreview.generateSVG({
texString: `\\begin{align*}${left}x${right} + ${left} \\sum a_i ${right}\\end{align*}`,
envname: 'align*'
}, '')
bracketDocumentMap.set(left, new vscode.MarkdownString(`![${left}${right}](${svgDataUrl})`))
} catch { }
} catch {
this.extension.logger.debug(`Failed to generate preview for ${left}${right}`)
}
}
}
this.bracketDocumentMapPromise.resolve(bracketDocumentMap)
Expand Down

0 comments on commit 3fa1bf2

Please sign in to comment.