Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Fix search data generation

author
Gears
committer
Louis Pilfold
date (Dec 5, 2025, 10:38 AM UTC) commit a2b22c1b parent 60e36fe1 change-id mrymkwmn
+63 -28
+4
CHANGELOG.md
··· 428 428 - The compiler now provides a clearer error message when a function's return type 429 429 is mistakenly declared using `:` instead of `->`. 430 430 ([Gurvir Singh](https://github.com/baraich)) 431 + 432 + - Fixed a bug where the data generated for searching documentation was in the 433 + wrong format, preventing it from being used by Hexdocs search. 434 + ([Surya Rose](https://github.com/GearsDatapacks))
+17 -11
compiler-core/src/docs.rs
··· 223 223 let arguments = constructor 224 224 .arguments 225 225 .iter() 226 - .map(|argument| format!("{}\n{}", argument.name, argument.doc)) 226 + .map(|argument| { 227 + format!("{}\n{}", argument.name, argument.text_documentation) 228 + }) 227 229 .join("\n"); 228 230 229 231 format!( 230 232 "{}\n{}\n{}", 231 - constructor.definition, constructor.text_documentation, arguments 233 + constructor.raw_definition, constructor.text_documentation, arguments 232 234 ) 233 235 }) 234 236 .join("\n"); ··· 239 241 title: type_.name.to_string(), 240 242 content: format!( 241 243 "{}\n{}\n{}\n{}", 242 - type_.definition, 244 + type_.raw_definition, 243 245 type_.text_documentation, 244 246 constructors, 245 247 import_synonyms(&module.name, type_.name) ··· 247 249 reference: format!("{}.html#{}", module.name, type_.name), 248 250 }) 249 251 }); 250 - values.iter().for_each(|constant| { 252 + values.iter().for_each(|value| { 251 253 search_items.push(SearchItem { 252 254 type_: SearchItemType::Value, 253 255 parent_title: module.name.to_string(), 254 - title: constant.name.to_string(), 256 + title: value.name.to_string(), 255 257 content: format!( 256 258 "{}\n{}\n{}", 257 - constant.definition, 258 - constant.text_documentation, 259 - import_synonyms(&module.name, constant.name) 259 + value.raw_definition, 260 + value.text_documentation, 261 + import_synonyms(&module.name, value.name) 260 262 ), 261 - reference: format!("{}.html#{}", module.name, constant.name), 263 + reference: format!("{}.html#{}", module.name, value.name), 262 264 }) 263 265 }); 264 266 ··· 368 370 ), 369 371 }); 370 372 371 - // lunr.min.js, search_data.json and index.js 373 + // lunr.min.js, search-data.json and index.js 372 374 373 375 files.push(OutputFile { 374 376 path: Utf8PathBuf::from("js/lunr.min.js"), ··· 382 384 .expect("search index serialization"); 383 385 384 386 files.push(OutputFile { 385 - path: Utf8PathBuf::from("search_data.json"), 387 + path: Utf8PathBuf::from("search-data.json"), 386 388 content: Content::Text(search_data_json.to_string()), 387 389 }); 388 390 ··· 599 601 #[derive(PartialEq, Eq, PartialOrd, Ord, Debug)] 600 602 struct TypeConstructor { 601 603 definition: String, 604 + raw_definition: String, 602 605 documentation: String, 603 606 text_documentation: String, 604 607 arguments: Vec<TypeConstructorArg>, ··· 608 611 struct TypeConstructorArg { 609 612 name: String, 610 613 doc: String, 614 + text_documentation: String, 611 615 } 612 616 613 617 #[derive(PartialEq, Eq, PartialOrd, Ord, Debug)] 614 618 struct TypeDefinition<'a> { 615 619 name: &'a str, 616 620 definition: String, 621 + raw_definition: String, 617 622 documentation: String, 618 623 constructors: Vec<TypeConstructor>, 619 624 text_documentation: String, ··· 626 631 struct DocsValues<'a> { 627 632 name: &'a str, 628 633 definition: String, 634 + raw_definition: String, 629 635 documentation: String, 630 636 text_documentation: String, 631 637 source_url: String,
+25
compiler-core/src/docs/printer.rs
··· 111 111 type_definitions.push(TypeDefinition { 112 112 name, 113 113 definition: print(self.custom_type(name, parameters, constructors, *opaque)), 114 + raw_definition: self 115 + .raw(|this| this.custom_type(name, parameters, constructors, *opaque)), 114 116 documentation: markdown_documentation(documentation), 115 117 text_documentation: text_documentation(documentation), 116 118 deprecation_message: match deprecation { ··· 124 126 .iter() 125 127 .map(|constructor| TypeConstructor { 126 128 definition: print(self.record_constructor(constructor)), 129 + raw_definition: self.raw(|this| this.record_constructor(constructor)), 127 130 documentation: markdown_documentation(&constructor.documentation), 128 131 text_documentation: text_documentation(&constructor.documentation), 129 132 arguments: constructor ··· 133 136 .map(|(argument, label)| TypeConstructorArg { 134 137 name: label.trim_end().to_string(), 135 138 doc: markdown_documentation(&argument.doc), 139 + text_documentation: text_documentation(&argument.doc), 136 140 }) 137 141 .filter(|arg| !arg.doc.is_empty()) 138 142 .collect(), ··· 161 165 type_definitions.push(TypeDefinition { 162 166 name, 163 167 definition: print(self.type_alias(name, type_, parameters).group()), 168 + raw_definition: self.raw(|this| this.type_alias(name, type_, parameters).group()), 164 169 documentation: markdown_documentation(documentation), 165 170 text_documentation: text_documentation(documentation), 166 171 constructors: vec![], ··· 177 182 type_definitions 178 183 } 179 184 185 + /// Print a definition without HTML highlighting, such as for search data 186 + fn raw<'a, F>(&mut self, definition: F) -> String 187 + where 188 + F: FnOnce(&mut Self) -> Document<'a>, 189 + { 190 + let options = self.options; 191 + // Turn off highlighting for this definition 192 + self.options = PrintOptions { 193 + print_highlighting: false, 194 + print_html: false, 195 + }; 196 + let result = print(definition(self)); 197 + // Restore previous options 198 + self.options = options; 199 + format!("```\n{result}\n```") 200 + } 201 + 180 202 pub fn value_definitions<'a>( 181 203 &mut self, 182 204 source_links: &SourceLinker, ··· 209 231 value_definitions.push(DocsValues { 210 232 name, 211 233 definition: print(self.function_signature(name, arguments, return_type)), 234 + raw_definition: self 235 + .raw(|this| this.function_signature(name, arguments, return_type)), 212 236 documentation: markdown_documentation(documentation), 213 237 text_documentation: text_documentation(documentation), 214 238 source_url: source_links.url(*location), ··· 236 260 value_definitions.push(DocsValues { 237 261 name, 238 262 definition: print(self.constant(name, type_)), 263 + raw_definition: self.raw(|this| this.constant(name, type_)), 239 264 documentation: markdown_documentation(documentation), 240 265 text_documentation: text_documentation(documentation), 241 266 source_url: source_links.url(*location),
+3 -3
compiler-core/src/docs/snapshots/gleam_core__docs__tests__canonical_link.snap
··· 320 320 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 321 321 <script src="./js/index.js?v=0"></script> 322 322 <script> 323 - fetch("./search_data.json?v=0") 323 + fetch("./search-data.json?v=0") 324 324 .then(response => response.json()) 325 325 .then(data => window.Gleam.initSearch(data)); 326 326 </script> ··· 687 687 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 688 688 <script src="./js/index.js?v=0"></script> 689 689 <script> 690 - fetch("./search_data.json?v=0") 690 + fetch("./search-data.json?v=0") 691 691 .then(response => response.json()) 692 692 .then(data => window.Gleam.initSearch(data)); 693 693 </script> ··· 1054 1054 <script src="../../js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 1055 1055 <script src="../../js/index.js?v=0"></script> 1056 1056 <script> 1057 - fetch("../../search_data.json?v=0") 1057 + fetch("../../search-data.json?v=0") 1058 1058 .then(response => response.json()) 1059 1059 .then(data => window.Gleam.initSearch(data)); 1060 1060 </script>
+1 -1
compiler-core/src/docs/snapshots/gleam_core__docs__tests__discarded_arguments_are_not_shown.snap
··· 352 352 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 353 353 <script src="./js/index.js?v=0"></script> 354 354 <script> 355 - fetch("./search_data.json?v=0") 355 + fetch("./search-data.json?v=0") 356 356 .then(response => response.json()) 357 357 .then(data => window.Gleam.initSearch(data)); 358 358 </script>
+1 -1
compiler-core/src/docs/snapshots/gleam_core__docs__tests__docs_of_a_type_constructor_are_not_used_by_the_following_function.snap
··· 423 423 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 424 424 <script src="./js/index.js?v=0"></script> 425 425 <script> 426 - fetch("./search_data.json?v=0") 426 + fetch("./search-data.json?v=0") 427 427 .then(response => response.json()) 428 428 .then(data => window.Gleam.initSearch(data)); 429 429 </script>
+1 -1
compiler-core/src/docs/snapshots/gleam_core__docs__tests__hello_docs.snap
··· 353 353 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 354 354 <script src="./js/index.js?v=0"></script> 355 355 <script> 356 - fetch("./search_data.json?v=0") 356 + fetch("./search-data.json?v=0") 357 357 .then(response => response.json()) 358 358 .then(data => window.Gleam.initSearch(data)); 359 359 </script>
+1 -1
compiler-core/src/docs/snapshots/gleam_core__docs__tests__ignored_argument_is_called_arg.snap
··· 352 352 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 353 353 <script src="./js/index.js?v=0"></script> 354 354 <script> 355 - fetch("./search_data.json?v=0") 355 + fetch("./search-data.json?v=0") 356 356 .then(response => response.json()) 357 357 .then(data => window.Gleam.initSearch(data)); 358 358 </script>
+1 -1
compiler-core/src/docs/snapshots/gleam_core__docs__tests__internal_definitions_are_not_included.snap
··· 322 322 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 323 323 <script src="./js/index.js?v=0"></script> 324 324 <script> 325 - fetch("./search_data.json?v=0") 325 + fetch("./search-data.json?v=0") 326 326 .then(response => response.json()) 327 327 .then(data => window.Gleam.initSearch(data)); 328 328 </script>
+1 -1
compiler-core/src/docs/snapshots/gleam_core__docs__tests__long_function_wrapping.snap
··· 426 426 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 427 427 <script src="./js/index.js?v=0"></script> 428 428 <script> 429 - fetch("./search_data.json?v=0") 429 + fetch("./search-data.json?v=0") 430 430 .then(response => response.json()) 431 431 .then(data => window.Gleam.initSearch(data)); 432 432 </script>
+1 -1
compiler-core/src/docs/snapshots/gleam_core__docs__tests__markdown_code_from_function_comment_is_trimmed.snap
··· 356 356 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 357 357 <script src="./js/index.js?v=0"></script> 358 358 <script> 359 - fetch("./search_data.json?v=0") 359 + fetch("./search-data.json?v=0") 360 360 .then(response => response.json()) 361 361 .then(data => window.Gleam.initSearch(data)); 362 362 </script>
+1 -1
compiler-core/src/docs/snapshots/gleam_core__docs__tests__markdown_code_from_module_comment_is_trimmed.snap
··· 326 326 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 327 327 <script src="./js/index.js?v=0"></script> 328 328 <script> 329 - fetch("./search_data.json?v=0") 329 + fetch("./search-data.json?v=0") 330 330 .then(response => response.json()) 331 331 .then(data => window.Gleam.initSearch(data)); 332 332 </script>
+1 -1
compiler-core/src/docs/snapshots/gleam_core__docs__tests__markdown_code_from_standalone_pages_is_not_trimmed.snap
··· 320 320 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 321 321 <script src="./js/index.js?v=0"></script> 322 322 <script> 323 - fetch("./search_data.json?v=0") 323 + fetch("./search-data.json?v=0") 324 324 .then(response => response.json()) 325 325 .then(data => window.Gleam.initSearch(data)); 326 326 </script>
+3 -3
compiler-core/src/docs/snapshots/gleam_core__docs__tests__no_hex_publish.snap
··· 313 313 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 314 314 <script src="./js/index.js?v=0"></script> 315 315 <script> 316 - fetch("./search_data.json?v=0") 316 + fetch("./search-data.json?v=0") 317 317 .then(response => response.json()) 318 318 .then(data => window.Gleam.initSearch(data)); 319 319 </script> ··· 673 673 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 674 674 <script src="./js/index.js?v=0"></script> 675 675 <script> 676 - fetch("./search_data.json?v=0") 676 + fetch("./search-data.json?v=0") 677 677 .then(response => response.json()) 678 678 .then(data => window.Gleam.initSearch(data)); 679 679 </script> ··· 1033 1033 <script src="../../js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 1034 1034 <script src="../../js/index.js?v=0"></script> 1035 1035 <script> 1036 - fetch("../../search_data.json?v=0") 1036 + fetch("../../search-data.json?v=0") 1037 1037 .then(response => response.json()) 1038 1038 .then(data => window.Gleam.initSearch(data)); 1039 1039 </script>
+1 -1
compiler-core/src/docs/snapshots/gleam_core__docs__tests__tables.snap
··· 356 356 <script src="./js/lunr.min.js?v=GLEAM_VERSION_HERE"></script> 357 357 <script src="./js/index.js?v=0"></script> 358 358 <script> 359 - fetch("./search_data.json?v=0") 359 + fetch("./search-data.json?v=0") 360 360 .then(response => response.json()) 361 361 .then(data => window.Gleam.initSearch(data)); 362 362 </script>
+1 -1
compiler-core/templates/documentation_layout.html
··· 309 309 <script src="{{ unnest }}/js/lunr.min.js?v={{ gleam_version }}"></script> 310 310 <script src="{{ unnest }}/js/index.js?v={{ rendering_timestamp }}"></script> 311 311 <script> 312 - fetch("{{ unnest }}/search_data.json?v={{ rendering_timestamp }}") 312 + fetch("{{ unnest }}/search-data.json?v={{ rendering_timestamp }}") 313 313 .then(response => response.json()) 314 314 .then(data => window.Gleam.initSearch(data)); 315 315 </script>