fix(completions): instantiate Slugger per file
Move Slugger instantiation inside the file loops to prevent state leakage between files, as Slugger is stateful.
This commit is contained in:
parent
97148aa010
commit
9a312f76ad
|
|
@ -25,11 +25,14 @@ export const sparkTablesSource: CompletionSource = {
|
||||||
|
|
||||||
scan(index) {
|
scan(index) {
|
||||||
const items: SparkTableCompletion[] = [];
|
const items: SparkTableCompletion[] = [];
|
||||||
const slugger = new Slugger();
|
|
||||||
|
|
||||||
for (const [filePath, content] of Object.entries(index)) {
|
for (const [filePath, content] of Object.entries(index)) {
|
||||||
if (!filePath.endsWith(".md")) continue;
|
if (!filePath.endsWith(".md")) continue;
|
||||||
|
|
||||||
|
// Fresh slugger per file so duplicate headers across files don't
|
||||||
|
// pollute each other. (github-slugger is stateful.)
|
||||||
|
const slugger = new Slugger();
|
||||||
|
|
||||||
const lines = content.split(/\r?\n/);
|
const lines = content.split(/\r?\n/);
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
const headerCells = splitTableRow(lines[i]);
|
const headerCells = splitTableRow(lines[i]);
|
||||||
|
|
|
||||||
|
|
@ -81,12 +81,15 @@ async function scanClientSide(): Promise<JournalCompletions> {
|
||||||
const links: LinkCompletion[] = [];
|
const links: LinkCompletion[] = [];
|
||||||
const sparkTables: SparkTableCompletion[] = [];
|
const sparkTables: SparkTableCompletion[] = [];
|
||||||
const tagRegex = /<md-dice[^>]*>\s*([\s\S]*?)\s*<\/md-dice>/gi;
|
const tagRegex = /<md-dice[^>]*>\s*([\s\S]*?)\s*<\/md-dice>/gi;
|
||||||
const slugger = new Slugger();
|
|
||||||
|
|
||||||
for (const filePath of paths) {
|
for (const filePath of paths) {
|
||||||
const content = await getIndexedData(filePath);
|
const content = await getIndexedData(filePath);
|
||||||
if (!content) continue;
|
if (!content) continue;
|
||||||
|
|
||||||
|
// Fresh slugger per file so duplicate headers across files don't
|
||||||
|
// pollute each other.
|
||||||
|
const slugger = new Slugger();
|
||||||
|
|
||||||
// Dice scan
|
// Dice scan
|
||||||
let match: RegExpExecArray | null;
|
let match: RegExpExecArray | null;
|
||||||
tagRegex.lastIndex = 0;
|
tagRegex.lastIndex = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue