Update autocomplete name to be the label and update ref to use main name as a synonym

This commit is contained in:
Aria
2025-09-02 16:29:01 -05:00
parent 8d2a368da9
commit c199b51645
3 changed files with 11 additions and 6 deletions
+1 -1
View File
@@ -86,7 +86,7 @@ const jsdocCompletions = (() => {
seen.add(label);
completions.push({
label,
info: () => Autocomplete({ doc }),
info: () => Autocomplete({ doc, label }),
type: 'function', // https://codemirror.net/docs/ref/#autocomplete.Completion.type
});
}
@@ -3,22 +3,27 @@ import { useMemo, useState } from 'react';
import jsdocJson from '../../../../../doc.json';
import { Textbox } from '../textbox/Textbox';
const isValid = ({ name, description }) =>
name && !name.startsWith('_') && !!description;
const isValid = ({ name, description }) => name && !name.startsWith('_') && !!description;
const availableFunctions = (() => {
const seen = new Set(); // avoid repetition
const functions = [];
for (const doc of jsdocJson.docs) {
if (!isValid(doc)) continue;
let docAndSynonyms = [doc.name, ...(doc.synonyms || [])];
for (const s of docAndSynonyms) {
functions.push(doc);
const synonyms = doc.synonyms || [];
for (const s of synonyms) {
if (!s || seen.has(s)) continue;
seen.add(s);
// Swap `doc.name` in for `s` in the list of synonyms
const notS = synonyms.filter((x) => x && x !== s);
const synonymsWithDoc = Array.from(new Set([doc.name, ...notS]));
functions.push({
...doc,
name: s, // update names for the synonym
longname: s,
synonyms: synonymsWithDoc,
synonyms_text: synonymsWithDoc.join(', '),
});
}
}
@@ -312,7 +312,7 @@ export function SettingsTab({ started }) {
confirmDialog('Sure?').then((r) => {
if (r) {
const { userPatterns } = settingsMap.get(); // keep current patterns
settingsMap.set({...defaultSettings, userPatterns});
settingsMap.set({ ...defaultSettings, userPatterns });
}
});
}}