Skip to content

Commit 8feb1c0

Browse files
committed
Split out HSL from /hack/ to /hsl/
As well as correctness, this gets us another APIProduct, which will be useful for improving search result rendering.
1 parent 1dc03bb commit 8feb1c0

36 files changed

+302
-289
lines changed

LocalConfig.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
namespace HHVM\UserDocumentation;
44

5+
use namespace HH\Lib\Str;
6+
57
abstract final class LocalConfig {
68
const string ROOT = __DIR__;
9+
10+
<<__Memoize>>
11+
public static function getBuildID(): string {
12+
invariant(
13+
\file_exists(BuildPaths::BUILD_ID_FILE),
14+
"Build ID does not exist",
15+
);
16+
return Str\trim(\file_get_contents(BuildPaths::BUILD_ID_FILE));
17+
}
718
}

bin/build.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
namespace HHVM\UserDocumentation;
1212

1313
require(__DIR__.'/../vendor/hh_autoload.php');
14+
15+
use namespace HH\Lib\Vec;
16+
1417
function build_site(?Traversable<string> $filters = null): void {
1518
if (!is_dir(BuildPaths::BUILD_DIR)) {
1619
mkdir(BuildPaths::BUILD_DIR);
@@ -50,7 +53,7 @@ function build_site(?Traversable<string> $filters = null): void {
5053
StaticResourceMapBuildStep::class,
5154

5255
// Needs the static resources
53-
MergedMarkdownBuildStep::class,
56+
APIMarkdownBuildStep::class,
5457

5558
// Needs the Markdown
5659
GuidesHTMLBuildStep::class,
@@ -70,7 +73,7 @@ function (classname<BuildStep> $step): bool use ($filters) {
7073
);
7174
}
7275

73-
$steps[] = BuildIDBuildStep::class;
76+
$steps = Vec\concat(vec[BuildIDBuildStep::class], $steps);
7477

7578
foreach ($steps as $step) {
7679
(new $step())->buildAll();

bin/class-reference-skeletons.php

Lines changed: 0 additions & 132 deletions
This file was deleted.

src/APIIndex.php

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,43 @@
1414
use namespace HH\Lib\{C, Math, Str, Vec};
1515

1616
final class APIIndex {
17+
private function __construct(
18+
private ProductAPIIndexShape $index,
19+
) {
20+
}
21+
1722
<<__Memoize>>
18-
public static function getIndex(
23+
public static function get(APIProduct $product): APIIndex {
24+
$idx = self::getRawIndex();
25+
switch ($product) {
26+
case APIProduct::HACK:
27+
return new self($idx[APIProduct::HACK]);
28+
case APIProduct::HSL:
29+
return new self($idx[APIProduct::HSL]);
30+
case APIProduct::PHP:
31+
invariant_violation("Can't handle PHP index");
32+
}
33+
}
34+
35+
public function getIndex(): ProductAPIIndexShape {
36+
return $this->index;
37+
}
38+
39+
public static function searchAllProducts(string $term): vec<SearchResult> {
40+
return Vec\concat(
41+
self::get(APIProduct::HACK)->search($term),
42+
self::get(APIProduct::HSL)->search($term),
43+
);
44+
}
45+
46+
<<__Memoize>>
47+
private static function getRawIndex(
1948
): APIIndexShape {
20-
$key = __CLASS__.'!'.BuildPaths::BUILD_ID;
49+
$key = __CLASS__.'!'.LocalConfig::getBuildID();
2150

2251
$success = false;
2352
$data = apc_fetch($key, $success);
53+
$success = false;
2454
if ($success) {
2555
return $data;
2656
}
@@ -33,44 +63,47 @@ public static function getIndex(
3363
return $data;
3464
}
3565

36-
public static function getIndexForType(
66+
public function getIndexForType(
3767
APIDefinitionType $type,
3868
): array<string, APIIndexEntry> {
39-
$index = Shapes::toArray(self::getIndex());
69+
$index = Shapes::toArray($this->index);
4070
invariant(
4171
array_key_exists($type, $index),
4272
'invalid type: %s',
4373
(string) $type,
4474
);
45-
// UNSAFE
4675
return $index[$type];
4776
}
4877

49-
public static function getFunctionIndex(
78+
public function getFunctionIndex(
5079
): array<string, APIFunctionIndexEntry> {
51-
return self::getIndex()['function'];
80+
return $this->index['function'];
5281
}
5382

54-
public static function getClassIndex(
83+
public function getClassIndex(
5584
APIDefinitionType $type,
5685
): array<string, APIClassIndexEntry> {
57-
invariant(
58-
$type !== APIDefinitionType::FUNCTION_DEF,
59-
'functions are not classes',
60-
);
61-
// UNSAFE
62-
return self::getIndex()[$type];
86+
switch($type) {
87+
case APIDefinitionType::FUNCTION_DEF:
88+
invariant_violation('functions are not classes');
89+
case APIDefinitionType::CLASS_DEF:
90+
return $this->index['class'];
91+
case APIDefinitionType::INTERFACE_DEF:
92+
return $this->index['interface'];
93+
case APIDefinitionType::TRAIT_DEF:
94+
return $this->index['trait'];
95+
}
6396
}
6497

65-
public static function search(
98+
public function search(
6699
string $term,
67100
): vec<SearchResult> {
68101
return APIDefinitionType::getValues()
69-
|> Vec\map($$, $type ==> self::searchEntries($term, $type))
102+
|> Vec\map($$, $type ==> $this->searchEntries($term, $type))
70103
|> Vec\flatten($$);
71104
}
72105

73-
private static function getMethods(
106+
private function getMethods(
74107
APIIndexEntry $entry,
75108
): ?vec<APIMethodIndexEntry> {
76109
$arr = Shapes::toArray($entry);
@@ -87,14 +120,14 @@ private static function getMethods(
87120
return null;
88121
}
89122

90-
private static function searchEntries (
123+
private function searchEntries (
91124
string $term,
92125
APIDefinitionType $type,
93126
): vec<SearchResult> {
94127
$terms = Str\split($term, ' ');
95128
$results = vec[];
96129

97-
$entries = self::getIndexForType($type);
130+
$entries = $this->getIndexForType($type);
98131
foreach ($entries as $_ => $entry) {
99132
$name = $entry['name'];
100133
$type = Str\contains($name, "HH\\Lib\\")
@@ -106,7 +139,7 @@ private static function searchEntries (
106139
$results[] = new SearchResult($type, $score, $name, $entry['urlPath']);
107140
}
108141

109-
$methods = self::getMethods($entry);
142+
$methods = $this->getMethods($entry);
110143
if ($methods === null) {
111144
continue;
112145
}
@@ -122,10 +155,10 @@ private static function searchEntries (
122155
return $results;
123156
}
124157

125-
public static function getDataForFunction(
158+
public function getDataForFunction(
126159
string $name,
127160
): APIFunctionIndexEntry {
128-
$index = self::getIndex();
161+
$index = $this->index;
129162
invariant(
130163
array_key_exists($name, $index['function']),
131164
'function %s does not exist',
@@ -134,11 +167,11 @@ public static function getDataForFunction(
134167
return $index['function'][$name];
135168
}
136169

137-
public static function getDataForClass(
170+
public function getDataForClass(
138171
APIDefinitionType $class_type,
139172
string $class_name,
140173
): APIClassIndexEntry {
141-
$index = self::getClassIndex($class_type);
174+
$index = $this->getClassIndex($class_type);
142175
invariant(
143176
array_key_exists($class_name, $index),
144177
'class %s does not exist',
@@ -147,12 +180,12 @@ public static function getDataForClass(
147180
return $index[$class_name];
148181
}
149182

150-
public static function getDataForMethod(
183+
public function getDataForMethod(
151184
APIDefinitionType $class_type,
152185
string $class_name,
153186
string $method_name,
154187
): APIMethodIndexEntry {
155-
$index = self::getClassIndex($class_type);
188+
$index = $this->getClassIndex($class_type);
156189
invariant(
157190
array_key_exists($class_name, $index),
158191
'class %s does not exist',

0 commit comments

Comments
 (0)