authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-04-13 17:38:52+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-04-13 17:38:52+02:00
log83d1f6b15a84864232eceafb24b95b8d16282a3f
tree5799e1dbed71b0e314aee9ddeb102dbc94507e9c
parent5c9906c231f65be759435fe0dc59acd8d9bc4d9c

autodoc: index in search usingnamespace decls


1 files changed, 63 insertions(+), 33 deletions(-)

lib/docs/main.js+63-33
......@@ -3242,42 +3242,33 @@ const NAV_MODES = {
32423242
32433243 let len = t.pubDecls ? t.pubDecls.length : 0;
32443244 for (let declI = 0; declI < len; declI += 1) {
3245 let mainDeclIndex = t.pubDecls[declI];
3246 if (list[mainDeclIndex] != null) continue;
3247
3248 let decl = getDecl(mainDeclIndex);
3249 let declVal = resolveValue(decl.value);
3250 let declNames = item.declNames.concat([decl.name]);
3251 list[mainDeclIndex] = {
3252 pkgNames: pkgNames,
3253 declNames: declNames,
3254 };
3255 if ("type" in declVal.expr) {
3256 let value = getType(declVal.expr.type);
3257 if (declCanRepresentTypeKind(value.kind)) {
3258 canonTypeDecls[declVal.type] = mainDeclIndex;
3259 }
3260
3261 if (isContainerType(value)) {
3262 stack.push({
3263 declNames: declNames,
3264 type: value,
3265 });
3266 }
3267
3268 // Generic function
3269 if (value.kind == typeKinds.Fn && value.generic_ret != null) {
3270 let resolvedVal = resolveValue({ expr: value.generic_ret });
3271 if ("type" in resolvedVal.expr) {
3272 let generic_type = getType(resolvedVal.expr.type);
3273 if (isContainerType(generic_type)) {
3274 stack.push({
3275 declNames: declNames,
3276 type: generic_type,
3277 });
3245 let declIndex = t.pubDecls[declI];
3246 if (list[declIndex] != null) continue;
3247
3248 let decl = getDecl(declIndex);
3249
3250 if (decl.is_uns) {
3251 let unsDeclList = [decl];
3252 while(unsDeclList.length != 0) {
3253 let unsDecl = unsDeclList.pop();
3254 let unsDeclVal = resolveValue(unsDecl.value);
3255 if (!("type" in unsDeclVal.expr)) continue;
3256 let unsType = getType(unsDeclVal.expr.type);
3257 if (!isContainerType(unsType)) continue;
3258 let unsPubDeclLen = unsType.pubDecls ? unsType.pubDecls.length : 0;
3259 for (let unsDeclI = 0; unsDeclI < unsPubDeclLen; unsDeclI += 1) {
3260 let childDeclIndex = unsType.pubDecls[unsDeclI];
3261 let childDecl = getDecl(childDeclIndex);
3262
3263 if (childDecl.is_uns) {
3264 unsDeclList.push(childDecl);
3265 } else {
3266 addDeclToSearchResults(childDecl, childDeclIndex, pkgNames, item, list, stack);
32783267 }
32793268 }
32803269 }
3270 } else {
3271 addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack);
32813272 }
32823273 }
32833274 }
......@@ -3286,6 +3277,45 @@ const NAV_MODES = {
32863277 return list;
32873278 }
32883279
3280function addDeclToSearchResults(decl, declIndex, pkgNames, item, list, stack) {
3281 let declVal = resolveValue(decl.value);
3282 let declNames = item.declNames.concat([decl.name]);
3283
3284 if (list[declIndex] != null) return;
3285 list[declIndex] = {
3286 pkgNames: pkgNames,
3287 declNames: declNames,
3288 };
3289
3290 if ("type" in declVal.expr) {
3291 let value = getType(declVal.expr.type);
3292 if (declCanRepresentTypeKind(value.kind)) {
3293 canonTypeDecls[declVal.type] = declIndex;
3294 }
3295
3296 if (isContainerType(value)) {
3297 stack.push({
3298 declNames: declNames,
3299 type: value,
3300 });
3301 }
3302
3303 // Generic function
3304 if (value.kind == typeKinds.Fn && value.generic_ret != null) {
3305 let resolvedVal = resolveValue({ expr: value.generic_ret });
3306 if ("type" in resolvedVal.expr) {
3307 let generic_type = getType(resolvedVal.expr.type);
3308 if (isContainerType(generic_type)) {
3309 stack.push({
3310 declNames: declNames,
3311 type: generic_type,
3312 });
3313 }
3314 }
3315 }
3316 }
3317}
3318
32893319 function getCanonDeclPath(index) {
32903320 if (canonDeclPaths == null) {
32913321 canonDeclPaths = computeCanonDeclPaths();