Skip to content

Commit 2473feb

Browse files
committed
wip
1 parent 104dd9e commit 2473feb

File tree

5 files changed

+67
-16
lines changed

5 files changed

+67
-16
lines changed

packages/core/src/Bundle.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export type Bundle = {
1717
spaces: Map<Id, Space>
1818
traits: Map<Id, Trait<Id>>
1919
theorems: Map<Id, Theorem>
20+
lean?: {
21+
properties: { id: string; module: string }[]
22+
}
2023
version: Version
2124
}
2225

@@ -26,6 +29,16 @@ export const serializedSchema = z.object({
2629
theorems: z.array(theoremSchema),
2730
traits: z.array(traitSchema(z.string())),
2831
version: z.object({ ref: z.string(), sha: z.string() }),
32+
lean: z
33+
.object({
34+
properties: z.array(
35+
z.object({
36+
id: z.string(),
37+
module: z.string(),
38+
}),
39+
),
40+
})
41+
.optional(),
2942
})
3043

3144
export type Serialized = z.infer<typeof serializedSchema>
@@ -41,14 +54,16 @@ export function serialize(bundle: Bundle): Serialized {
4154
}
4255

4356
export function deserialize(data: unknown): Bundle {
44-
const serialized = serializedSchema.parse(data)
57+
const { properties, spaces, theorems, traits, version, lean } =
58+
serializedSchema.parse(data)
4559

4660
return {
47-
properties: indexBy(serialized.properties, p => p.uid),
48-
spaces: indexBy(serialized.spaces, s => s.uid),
49-
theorems: indexBy(serialized.theorems, t => t.uid),
50-
traits: indexBy(serialized.traits, traitId),
51-
version: serialized.version,
61+
properties: indexBy(properties, p => p.uid),
62+
spaces: indexBy(spaces, s => s.uid),
63+
theorems: indexBy(theorems, t => t.uid),
64+
traits: indexBy(traits, traitId),
65+
lean,
66+
version,
5267
}
5368
}
5469

packages/core/src/Property.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const propertySchema = z.intersection(
55
z.object({
66
name: z.string(),
77
aliases: z.array(z.string()),
8+
mathlib: z.string().optional(),
89
}),
910
recordSchema,
1011
)

packages/viewer/src/components/Properties/Show.svelte

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
export let rel: string | undefined = undefined
1010
1111
const tabs = ['spaces', 'theorems', 'references'] as const
12+
13+
function leanUrl({ id, module }: { id: string; module: string }) {
14+
const path = module.replaceAll('.', '/')
15+
return `https://leanprover-community.github.io/mathlib4_docs/${path}.html#${id}`
16+
}
1217
</script>
1318

1419
<Title title={property.name} />
@@ -24,6 +29,16 @@
2429
<Typeset body={property.description} />
2530
</section>
2631

32+
{#if property?.lean}
33+
<section>
34+
<a href={leanUrl(property.lean)} target="_blank">
35+
Formalized in Lean as <code>{property.lean.id}</code>
36+
in
37+
<code>{property.lean.module}</code>
38+
</a>
39+
</section>
40+
{/if}
41+
2742
<Tabs {tabs} {tab} {rel} />
2843

2944
{#if tab === 'spaces'}

packages/viewer/src/gateway.ts

+26-10
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ export function sync(
3131
trace({ event: 'remote_fetch_started', host, branch })
3232
const result = await pb.bundle.fetch({ host, branch, etag, fetch })
3333

34+
const propIdx: Record<string, string> = {}
35+
if (result?.bundle.lean?.properties) {
36+
for (const { id, module } of result.bundle.lean.properties) {
37+
propIdx[id] = module
38+
}
39+
}
40+
3441
if (result) {
3542
trace({ event: 'remote_fetch_complete', result })
3643
return {
3744
spaces: transform(space, result.bundle.spaces),
38-
properties: transform(property, result.bundle.properties),
45+
properties: transform(property(propIdx), result.bundle.properties),
3946
traits: transform(trait, result.bundle.traits),
4047
theorems: transform(theorem, result.bundle.theorems),
4148
etag: result.etag,
@@ -47,19 +54,28 @@ export function sync(
4754
}
4855
}
4956

50-
function property({
51-
uid,
52-
name,
53-
aliases,
54-
description,
55-
refs,
56-
}: pb.Property): Property {
57-
return {
58-
id: Id.toInt(uid),
57+
function property(propertyIdx: Record<string, string>) {
58+
return function ({
59+
uid,
5960
name,
6061
aliases,
6162
description,
6263
refs,
64+
mathlib,
65+
}: pb.Property): Property {
66+
return {
67+
id: Id.toInt(uid),
68+
name,
69+
aliases,
70+
description,
71+
refs,
72+
lean: mathlib
73+
? {
74+
id: mathlib,
75+
module: propertyIdx[mathlib],
76+
}
77+
: undefined,
78+
}
6379
}
6480
}
6581

packages/viewer/src/types/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export type Property = {
99
aliases: string[]
1010
description: string
1111
refs: Ref[]
12+
lean?: {
13+
id: string
14+
module: string
15+
}
1216
}
1317

1418
export type Space = {

0 commit comments

Comments
 (0)