Skip to content

Commit ed1915a

Browse files
committed
Fix structure + review changes
1 parent 1d79868 commit ed1915a

File tree

6 files changed

+105
-78
lines changed

6 files changed

+105
-78
lines changed

_overviews/scala3-scaladoc/inkuire.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
layout: multipage-overview
3+
title: Inkuire (Hoogle-like searches)
4+
partof: scala3-scaladoc
5+
num: 7
6+
previous-page: site-versioning
7+
next-page: settings
8+
---
9+
10+
Searching for functions by their symbolic names can be time-consuming.
11+
That is why the new scaladoc allows to search for functions and fields by their types.
12+
13+
14+
So, for a declatation:
15+
```
16+
extension [T](arr: IArray[T]) def span(p: T => Boolean): (IArray[T], IArray[T]) = ...
17+
```
18+
Instead of searching for `span` we can also search for `IArray[A] => (A => Boolean) => (IArray[A], IArray[A])`.
19+
20+
To use this feature simply type the signature of the function you are looking for in the scaladoc searchbar. This is how it works:
21+
22+
![]({{ site.baseurl }}/resources/images/scala3/scaladoc/inkuire-1.0.0-M2_js_flatMap.gif)
23+
24+
This feature is provided by the [Inkuire](https://github.com/VirtusLab/Inkuire) search engine, which works for Scala 3 and Kotlin. To be up-to-date with the development of this feature, follow the [Inkuire repository](https://github.com/VirtusLab/Inkuire).
25+
26+
## Example queries
27+
28+
Some examples of queries with intended results:
29+
- `List[Int] => (Int => Long) => List[Long]` -> `map`
30+
- `Seq[A] => (A => B) => Seq[B]` -> `map`
31+
- `(A, B) => A` -> `_1`
32+
- `Set[Long] => Long => Boolean` -> `contains`
33+
- `Int => Long => Int` -> `const`
34+
- `String => Int => Char` -> `apply`
35+
- `(Int & Float) => (String | Double)` -> `toDouble`, `toString`
36+
- `F[A] => Int` -> `length`
37+
38+
## Query syntax
39+
40+
In order for a scaladoc searchbar query to be searched using Inkuire instead of the default search engine, the query has to contain the `=>` character sequence.
41+
42+
Accepted input is similar to a curried function signature in Scala 3. With some differences:
43+
- AndTypes, OrTypes and Functions have to be enclosed in parentheses e.g. `(Int & Any) => String`
44+
- static fields and static functions that don't take parameters can be found by their type preceded with `=>` e.g. `=> Int`
45+
- A wildcard `_` can be used to indicate that we want to match any type in a given place e.g. `Long => Double => _`
46+
- Types in the form of single letter e.g. `A` or a letter with a digit `X1` are automatically assumed to be type variables
47+
- Other type variables can be declared just like in polymorphic functions e.g. `[AVariable, AlsoAVariable] => AVariable => AlsoAVariable => AVariable`
48+
49+
## How it works
50+
51+
Inkuire works as a JavaScript worker in the browser thanks to the power of [ScalaJS](https://www.scala-js.org/).
52+
53+
To enable Inkuire when running scaladoc, add the flag `-Ygenerate-inkuire`. By adding this flag two files are generated:
54+
- `inkuire-db.json` - this is the file containing all the searchable declarations from the currently documented project in a format readable to the Inkuire search engine.
55+
- `inkuire-config.json` - this file contains the locations of the database files that should be searchable from the documentation of the current project. By default, it will be generated with the location of the local db file as well as the default implied locations of database files in [External mappings](/scala3/guides/scaladoc/settings.html#-external-mappings).
56+
57+
## What to expect?
58+
59+
When it comes to how the code is mapped to InkuireDb entries, there are some transformations to make the engine more opinionated (though open to suggestions and changes). Firstly, the receiver (non-module owner) of a function can be treated as a first argument. Automatic currying is also applied, so that the results don't depend on argument lists. When finding matches, `val`s and `def`s are not distinguished.
60+
61+
So the following declarations should be found by query `Num => Int => Int => Int`:
62+
```
63+
class Num():
64+
def a(i: Int, j: Int): Int
65+
def b(i: Int)(j: Int): Int
66+
def c(i: Int): (Int => Int)
67+
val d: Int => Int => Int
68+
val e: Int => Int => Int
69+
val f: (Int, Int) => Int
70+
end Num
71+
72+
def g(i: Num, j: Int, k: Int): Int
73+
extension (i: Num) def h(j: Int, k: Int): Int
74+
def i(i: Num, j: Int)(k: Int): Int
75+
extension (i: Num) def j(j: Int)(k: Int): Int
76+
...
77+
```
78+
79+
When it comes to type aliases, they are desugared on both the declaration and the query signature. This means that for declarations:
80+
```
81+
type Name = String
82+
83+
def fromName(name: Name): String
84+
def fromString(str: String): Name
85+
```
86+
both methods, `fromName` and `fromString`, should be found for queries `Name => Name`, `String => String`, `Name => String` and `String => Name`.

_overviews/scala3-scaladoc/settings.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
layout: multipage-overview
33
title: Settings
44
partof: scala3-scaladoc
5-
num: 7
6-
previous-page: site-versioning
5+
num: 8
6+
previous-page: inkuire
77
---
88

99
This chapter lists the configuration options that can be used when calling scaladoc. Some of the information shown here can be found by calling scaladoc with the `-help` flag.

_overviews/scala3-scaladoc/site-versioning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Site versioning
44
partof: scala3-scaladoc
55
num: 6
66
previous-page: blog
7-
next-page: settings
7+
next-page: inkuire
88
---
99

1010
Scaladoc provides a convenient way to switch between different versions of the documentation. The feature is useful if we want to expose older docs for users that didn't migrate to the new version of our library.

scala3/guides.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ guides:
1919
url: "/scala3/guides/tasty-overview.html"
2020
description: "An overview over the TASTy format aimed at end-users of the Scala language."
2121
- title: Scaladoc
22-
by: Krzysztof Romanowski, Aleksander Boruch-Gruszecki, Andrzej Ratajczak
22+
by: Krzysztof Romanowski, Aleksander Boruch-Gruszecki, Andrzej Ratajczak, Kacper Korban
2323
icon: book
2424
url: "/scala3/guides/scaladoc"
2525
description: "Scala’s API documentation generation tool."

scala3/scaladoc.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,28 @@ For more information you can follow this [thread](https://contributors.scala-lan
5454
![](../resources/images/scala3/scaladoc/snippet-compiler2.gif)
5555
![](../resources/images/scala3/scaladoc/snippet-compiler1.gif)
5656

57-
### Inkuire (Hoogle-like searches)
57+
### Inkuire (Type-signature searches)
5858

59-
Haskell programmers are probably familiar with [Hoogle](https://hoogle.haskell.org/) - a documentation search engine that allows you to find functions by their signatures rather than their symbolic names. Since many Scala developers are also functional programming fans, we decided to add a similar functionality to Scaladoc.
59+
Searching for functions by their symbolic names can be time-consuming.
60+
That is why the new scaladoc allows to search for functions and fields by their types.
6061

61-
To use this feature simply type the signature of the function You are looking for in scaladoc searchbar. This is how it works:
62+
63+
So, for a declatation:
64+
```
65+
extension [T](arr: IArray[T]) def span(p: T => Boolean): (IArray[T], IArray[T]) = ...
66+
```
67+
Instead of searching for `span` we can also search for `IArray[A] => (A => Boolean) => (IArray[A], IArray[A])`.
68+
69+
To use this feature simply type the signature of the function you are looking for in the scaladoc searchbar. This is how it works:
6270

6371
![](../resources/images/scala3/scaladoc/inkuire-1.0.0-M2_js_flatMap.gif)
6472

65-
This feature is provided by [Inkuire](https://github.com/VirtusLab/Inkuire) search engine, which works for Scala 3 and Kotlin. To be up-to-date with development of this feature follow [Inkuire repository](https://github.com/VirtusLab/Inkuire) for new releases.
73+
This feature is provided by the [Inkuire](https://github.com/VirtusLab/Inkuire) search engine, which works for Scala 3 and Kotlin. To be up-to-date with the development of this feature, follow the [Inkuire repository](https://github.com/VirtusLab/Inkuire).
74+
75+
For more information see [Guides](/scala3/guides/scaladoc/inkuire.html)
6676

6777
Note that this feature is still in development, so it can be subject to considerable change.
68-
If You encounter a bug or have an idea for improvement don't hesitate to create an issue on [Inkuire](https://github.com/VirtusLab/Inkuire/issues/new) or [dotty](https://github.com/lampepfl/dotty/issues/new).
78+
If you encounter a bug or have an idea for improvement, don't hesitate to create an issue on [Inkuire](https://github.com/VirtusLab/Inkuire/issues/new) or [dotty](https://github.com/lampepfl/dotty/issues/new).
6979

7080
[scaladoc-docstrings]: https://dotty.epfl.ch/docs/usage/scaladoc/scaladocDocstrings.html
7181
[static-documentation]: https://dotty.epfl.ch/docs/usage/scaladoc/staticSite.html

scala3/scaladoc/inkuire.md

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

0 commit comments

Comments
 (0)