Skip to content

Commit b11e1b2

Browse files
committed
Improve modules
1 parent 01c8678 commit b11e1b2

File tree

14 files changed

+63
-46
lines changed

14 files changed

+63
-46
lines changed

src/main/dumpers/schemas/schemas.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,10 @@ json SerializeType(CSchemaType* type)
327327
j["category"] = "declared_class";
328328
auto* classType = static_cast<CSchemaType_DeclaredClass*>(type);
329329
if (classType->m_pClassInfo && classType->m_pClassInfo->m_pszName)
330+
{
330331
j["name"] = classType->m_pClassInfo->m_pszName;
332+
j["module"] = classType->m_pClassInfo->m_pszProjectName;
333+
}
331334
else
332335
j["name"] = type->m_sTypeName.String();
333336
break;
@@ -337,7 +340,10 @@ json SerializeType(CSchemaType* type)
337340
j["category"] = "declared_enum";
338341
auto* enumType = static_cast<CSchemaType_DeclaredEnum*>(type);
339342
if (enumType->m_pEnumInfo && enumType->m_pEnumInfo->m_pszName)
343+
{
340344
j["name"] = enumType->m_pEnumInfo->m_pszName;
345+
j["module"] = enumType->m_pEnumInfo->m_pszProjectName;
346+
}
341347
else
342348
j["name"] = type->m_sTypeName.String();
343349
break;
@@ -463,12 +469,14 @@ void CollectClassesJson(CSchemaSystemTypeScope* typeScope, json& classesArray)
463469
{
464470
const auto* baseClass = classInfo->m_pBaseClasses[baseIndex].m_pClass;
465471
if (baseClass)
466-
parents.push_back(baseClass->m_pszName);
472+
{
473+
json parent;
474+
parent["name"] = baseClass->m_pszName;
475+
parent["module"] = baseClass->m_pszProjectName;
476+
parents.push_back(parent);
477+
}
467478
}
468479

469-
if (!parents.empty())
470-
classObj["parent"] = parents[0];
471-
472480
classObj["parents"] = parents;
473481

474482
// Fields
@@ -479,6 +487,7 @@ void CollectClassesJson(CSchemaSystemTypeScope* typeScope, json& classesArray)
479487

480488
json fieldObj;
481489
fieldObj["name"] = field.m_pszName;
490+
fieldObj["offset"] = field.m_nSingleInheritanceOffset;
482491
fieldObj["type"] = SerializeType(field.m_pType);
483492
fieldObj["metadata"] = SerializeMetadataArray(field.m_pStaticMetadata, field.m_nStaticMetadataCount, classInfo->m_pszName);
484493
fields.push_back(fieldObj);

web/src/components/Docs/ContentList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function renderItem(declaration: Declaration) {
1919
}
2020

2121
return (
22-
<ListItem key={declaration.name}>
22+
<ListItem key={`${declaration.module}/${declaration.name}`}>
2323
{children}
2424
</ListItem>
2525
);

web/src/components/Docs/DeclarationsContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Declaration } from "~components/Docs/api";
33

44
export type ReferenceEntry = {
55
declarationName: string;
6+
declarationModule: string;
67
declarationKind: "class" | "enum";
78
fieldName?: string;
89
relation: "field" | "parent";

web/src/components/Docs/ReferencedBy.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ const ToggleButton = styled.button`
6565
}
6666
`;
6767

68-
export function ReferencedBy({ name }: { name: string }) {
68+
export function ReferencedBy({ name, module }: { name: string; module: string }) {
6969
const { root, references } = useContext(DeclarationsContext);
7070
const [expanded, setExpanded] = useState(false);
7171

72-
const refs = references.get(name);
72+
const refs = references.get(`${module}/${name}`);
7373
if (!refs || refs.length === 0) return null;
7474

7575
const collapsible = refs.length > COLLAPSE_THRESHOLD;
@@ -80,7 +80,7 @@ export function ReferencedBy({ name }: { name: string }) {
8080
<Title>Referenced by ({refs.length})</Title>
8181
<RefList>
8282
{visible.map((ref, i) => (
83-
<RefLink key={`${ref.declarationName}-${ref.fieldName ?? ""}-${i}`} to={`${root}/${ref.declarationName}`}>
83+
<RefLink key={`${ref.declarationModule}/${ref.declarationName}-${ref.fieldName ?? ""}-${i}`} to={`${root}/${ref.declarationModule}/${ref.declarationName}`}>
8484
<KindIcon kind={ref.declarationKind} size="small" />
8585
<span>{ref.declarationName}{ref.fieldName && <RefField>{ref.fieldName}</RefField>}</span>
8686
</RefLink>

web/src/components/Docs/SchemaClass.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ export const SchemaClassView: React.FC<{
100100
<DeclarationHeader>
101101
<CommonGroupSignature>
102102
<KindIcon kind="class" size="big" />
103-
<DeclarationNameLink to={`${root}/${declaration.name}`}>{declaration.name}</DeclarationNameLink>
103+
<DeclarationNameLink to={`${root}/${declaration.module}/${declaration.name}`}>{declaration.name}</DeclarationNameLink>
104104
&nbsp;
105105
{declaration.parents.length > 0 && (
106106
<ClassExtendsWrapper>
107107
extends{" "}
108108
{declaration.parents.map((p, i) => (
109-
<React.Fragment key={p}>
109+
<React.Fragment key={`${p.module}/${p.name}`}>
110110
{i > 0 && ", "}
111-
<SchemaTypeView type={{ category: "declared_class", name: p }} />
111+
<SchemaTypeView type={{ category: "declared_class", name: p.name, module: p.module }} />
112112
</React.Fragment>
113113
))}
114114
</ClassExtendsWrapper>
@@ -123,13 +123,13 @@ export const SchemaClassView: React.FC<{
123123
<SchemaFieldView key={field.name} field={field} highlighted={searchWords.length > 0 && matchesWords(field.name, searchWords)} />
124124
))}
125125
{hiddenCount > 0 && (
126-
<CollapsedFieldsLink to={`${root}/${declaration.name}`}>
126+
<CollapsedFieldsLink to={`${root}/${declaration.module}/${declaration.name}`}>
127127
{hiddenCount} more field{hiddenCount !== 1 ? "s" : ""}
128128
</CollapsedFieldsLink>
129129
)}
130130
</ClassMembers>
131131
)}
132-
{!collapseNonMatching && <ReferencedBy name={declaration.name} />}
132+
{!collapseNonMatching && <ReferencedBy name={declaration.name} module={declaration.module} />}
133133
</CommonGroupWrapper>
134134
);
135135
};

web/src/components/Docs/SchemaEnum.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const SchemaEnumView: React.FC<{
8484
<DeclarationHeader>
8585
<CommonGroupSignature>
8686
<KindIcon kind="enum" size="big" />
87-
<DeclarationNameLink to={`${root}/${declaration.name}`}>{declaration.name}</DeclarationNameLink>
87+
<DeclarationNameLink to={`${root}/${declaration.module}/${declaration.name}`}>{declaration.name}</DeclarationNameLink>
8888
<EnumTypeWrapper>: {alignmentToType[declaration.alignment] ?? `unknown(${declaration.alignment})`}</EnumTypeWrapper>
8989
<ModuleBadge module={declaration.module} />
9090
</CommonGroupSignature>
@@ -96,13 +96,13 @@ export const SchemaEnumView: React.FC<{
9696
<EnumMemberView key={member.name} member={member} highlighted={searchWords.length > 0 && matchesWords(member.name, searchWords)} />
9797
))}
9898
{hiddenCount > 0 && (
99-
<CollapsedMembersLink to={`${root}/${declaration.name}`}>
99+
<CollapsedMembersLink to={`${root}/${declaration.module}/${declaration.name}`}>
100100
{hiddenCount} more member{hiddenCount !== 1 ? "s" : ""}
101101
</CollapsedMembersLink>
102102
)}
103103
</EnumMembers>
104104
)}
105-
{!collapseNonMatching && <ReferencedBy name={declaration.name} />}
105+
{!collapseNonMatching && <ReferencedBy name={declaration.name} module={declaration.module} />}
106106
</CommonGroupWrapper>
107107
);
108108
};

web/src/components/Docs/SchemaType.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function SchemaTypeView({ type }: { type: SchemaFieldType }) {
1919
return <ColoredSyntax kind="literal">{type.name}</ColoredSyntax>;
2020
case "declared_class":
2121
case "declared_enum":
22-
return <DeclarationLink name={type.name} />;
22+
return <DeclarationLink name={type.name} module={type.module} />;
2323
case "ptr":
2424
return (
2525
<>
@@ -54,13 +54,14 @@ export function SchemaTypeView({ type }: { type: SchemaFieldType }) {
5454
}
5555
}
5656

57-
function DeclarationLink({ name }: { name: string }) {
57+
function DeclarationLink({ name, module }: { name: string; module: string }) {
5858
const { root } = useContext(DeclarationsContext);
5959
const theme = useTheme();
6060
const style: React.CSSProperties = { textDecorationColor: getSyntaxColorFor(theme, "interface") };
61+
const to = `${root}/${module}/${name}`;
6162

6263
return (
63-
<TypeLink to={`${root}/${name}`} style={style}>
64+
<TypeLink to={to} style={style}>
6465
<ColoredSyntax kind="interface">{name}</ColoredSyntax>
6566
</TypeLink>
6667
);

web/src/components/Docs/api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export type SchemaFieldType =
44
| { category: "ptr"; inner: SchemaFieldType }
55
| { category: "fixed_array"; inner: SchemaFieldType; count: number }
66
| { category: "atomic"; name: string; inner?: SchemaFieldType; inner2?: SchemaFieldType }
7-
| { category: "declared_class"; name: string }
8-
| { category: "declared_enum"; name: string }
7+
| { category: "declared_class"; name: string; module: string }
8+
| { category: "declared_enum"; name: string; module: string }
99
| { category: "bitfield"; count: number };
1010

1111
export interface SchemaMetadataEntry {
@@ -15,6 +15,7 @@ export interface SchemaMetadataEntry {
1515

1616
export interface SchemaField {
1717
name: string;
18+
offset: number;
1819
type: SchemaFieldType;
1920
metadata: SchemaMetadataEntry[];
2021
}
@@ -23,8 +24,7 @@ export interface SchemaClass {
2324
kind: "class";
2425
name: string;
2526
module: string;
26-
parent?: string;
27-
parents: string[];
27+
parents: { name: string; module: string }[];
2828
fields: SchemaField[];
2929
metadata: SchemaMetadataEntry[];
3030
}

web/src/components/Docs/utils/filtering.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import * as api from "~components/Docs/api";
55

66
export function useFilteredData(declarations: api.Declaration[]) {
77
const { search } = useContext(SearchContext);
8-
const { scope = "" } = useParams();
8+
const { module = "", scope = "" } = useParams();
99

1010
return useMemo(() => {
1111
if (search) {
1212
return { data: doSearch(declarations, search.toLowerCase().split(" ")), isSearching: true };
1313
}
1414

15-
if (scope) {
16-
return { data: declarations.filter((x) => x.name === scope), isSearching: false };
15+
if (module && scope) {
16+
return { data: declarations.filter((x) => x.module === module && x.name === scope), isSearching: false };
1717
}
1818

1919
return { data: [] as api.Declaration[], isSearching: false };
20-
}, [declarations, search, scope]);
20+
}, [declarations, search, module, scope]);
2121
}
2222

2323
export function useSearchWords(): string[] {

web/src/components/layout/Sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const DeclarationSidebarElement: React.FC<{ declaration: Declaration }> =
5151
const { root } = useContext(DeclarationsContext);
5252
return (
5353
<SidebarElement
54-
to={`${root}/${declaration.name}`}
54+
to={`${root}/${declaration.module}/${declaration.name}`}
5555
icon={declaration.kind}
5656
text={declaration.name}
5757
/>

0 commit comments

Comments
 (0)