reference: show synonyms in the same row, grayed out, instead of adding a row for each synonym

This commit is contained in:
Felix Roos 2026-01-24 02:01:36 +01:00
parent 4051fd5241
commit a9975a2b41
No known key found for this signature in database

View file

@ -21,23 +21,18 @@ const availableFunctions = (() => {
// @something is. We only want data from comments like `@tags superdough` here. // @something is. We only want data from comments like `@tags superdough` here.
// If nothing is specified, we default to "untagged" for debugging // If nothing is specified, we default to "untagged" for debugging
doc.tags = doc.tags?.filter((t) => t && typeof t === 'string') || ['untagged']; doc.tags = doc.tags?.filter((t) => t && typeof t === 'string') || ['untagged'];
functions.push(doc);
const synonyms = doc.synonyms || []; const synonyms = doc.synonyms || [];
let names = [doc.name];
seen.add(doc.name); seen.add(doc.name);
for (const s of synonyms) { for (const s of synonyms) {
if (!s || seen.has(s)) continue; if (!s || seen.has(s)) continue;
names.push(s);
seen.add(s); seen.add(s);
// Swap `doc.name` in for `s` in the list of synonyms
const synonymsWithDoc = [doc.name, ...synonyms].filter((x) => x && x !== s);
functions.push({
...doc,
name: s, // update names for the synonym
longname: s,
synonyms: synonymsWithDoc,
synonyms_text: synonymsWithDoc.join(', '),
});
} }
doc.allNames = names.join(' ');
doc.synonyms = names.slice(1);
functions.push(doc);
} }
return functions.sort((a, b) => /* a.meta.filename.localeCompare(b.meta.filename) + */ a.name.localeCompare(b.name)); return functions.sort((a, b) => /* a.meta.filename.localeCompare(b.meta.filename) + */ a.name.localeCompare(b.name));
})(); })();
@ -87,7 +82,7 @@ export const Reference = memo(function Reference() {
} }
const lowerCaseSearch = search.toLowerCase(); const lowerCaseSearch = search.toLowerCase();
return ( return (
entry.name.toLowerCase().includes(lowerCaseSearch) || (entry.allNames || entry.name).toLowerCase().includes(lowerCaseSearch) ||
(entry.synonyms?.some((s) => s.toLowerCase().includes(lowerCaseSearch)) ?? false) (entry.synonyms?.some((s) => s.toLowerCase().includes(lowerCaseSearch)) ?? false)
); );
}); });
@ -156,7 +151,7 @@ export const Reference = memo(function Reference() {
<Fragment key={`entry-${entry.name}`}> <Fragment key={`entry-${entry.name}`}>
<a <a
className={ className={
'cursor-pointer hover:opacity-50 text-ellipsis block' + 'whitespace-nowrap cursor-pointer hover:opacity-50 text-ellipsis block' +
(entry.name === selectedFunction ? 'bg-lineHighlight font-bold' : '') (entry.name === selectedFunction ? 'bg-lineHighlight font-bold' : '')
} }
onClick={() => { onClick={() => {
@ -167,7 +162,7 @@ export const Reference = memo(function Reference() {
} }
}} }}
> >
{entry.name} {entry.name} {entry.synonyms && <small className="opacity-50">{entry.synonyms?.join(', ')}</small>}
</a>{' '} </a>{' '}
</Fragment> </Fragment>
))} ))}