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:
@@ -25,11 +25,14 @@ export const sparkTablesSource: CompletionSource = {
|
||||
|
||||
scan(index) {
|
||||
const items: SparkTableCompletion[] = [];
|
||||
const slugger = new Slugger();
|
||||
|
||||
for (const [filePath, content] of Object.entries(index)) {
|
||||
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/);
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const headerCells = splitTableRow(lines[i]);
|
||||
|
||||
Reference in New Issue
Block a user