Skip to content

Inkuire docs #2125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions _overviews/scala3-scaladoc/search-engine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
layout: multipage-overview
title: Type-based search
partof: scala3-scaladoc
num: 7
previous-page: site-versioning
next-page: settings
---

Searching for functions by their symbolic names can be time-consuming.
That is why the new scaladoc allows searching for methods and fields by their types.


Consider the following extension method definition:
```
extension [T](arr: IArray[T]) def span(p: T => Boolean): (IArray[T], IArray[T]) = ...
```
Instead of searching for `span` we can also search for `IArray[A] => (A => Boolean) => (IArray[A], IArray[A])`.

To use this feature, type the signature of the member you are looking for in the scaladoc searchbar. This is how it works:

![]({{ site.baseurl }}/resources/images/scala3/scaladoc/inkuire-1.0.0-M2_js_flatMap.gif)

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).

## Examples of queries

Some examples of queries with intended results:
- `List[Int] => (Int => Long) => List[Long]` -> `map`
- `Seq[A] => (A => B) => Seq[B]` -> `map`
- `(A, B) => A` -> `_1`
- `Set[Long] => Long => Boolean` -> `contains`
- `Int => Long => Int` -> `const`
- `String => Int => Char` -> `apply`
- `(Int & Float) => (String | Double)` -> `toDouble`, `toString`
- `F[A] => Int` -> `length`

## Query syntax

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.

Accepted input is similar to a curried function signature in Scala 3. With some differences:
- AndTypes, OrTypes and Functions have to be enclosed in parentheses e.g. `(Int & Any) => String`
- fields and parameterless methods can be found by preceding their type with `=>`, e.g., `=> Int`
- A wildcard `_` can be used to indicate that we want to match any type in a given place e.g. `Long => Double => _`
- Types in the form of single letter e.g. `A` or a letter with a digit `X1` are automatically assumed to be type variables
- Other type variables can be declared just like in polymorphic functions e.g. `[AVariable, AlsoAVariable] => AVariable => AlsoAVariable => AVariable`

### Working with type aliases and method receivers

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.

So the following declarations should be found by query `Num => Int => Int => Int`:
```
class Num():
def a(i: Int, j: Int): Int
def b(i: Int)(j: Int): Int
def c(i: Int): (Int => Int)
val d: Int => Int => Int
val e: Int => Int => Int
val f: (Int, Int) => Int
end Num

def g(i: Num, j: Int, k: Int): Int
extension (i: Num) def h(j: Int, k: Int): Int
def i(i: Num, j: Int)(k: Int): Int
extension (i: Num) def j(j: Int)(k: Int): Int
...
```

When it comes to type aliases, they are desugared on both the declaration and the query signature. This means that for declarations:
```
type Name = String

def fromName(name: Name): String
def fromString(str: String): Name
```
both methods, `fromName` and `fromString`, should be found for queries `Name => Name`, `String => String`, `Name => String` and `String => Name`.

## How it works

Inkuire works as a JavaScript worker in the browser thanks to the power of [ScalaJS](https://www.scala-js.org/).

To enable Inkuire when running scaladoc, add the flag `-Ygenerate-inkuire`. By adding this flag two files are generated:
- `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.
- `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).
4 changes: 2 additions & 2 deletions _overviews/scala3-scaladoc/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
layout: multipage-overview
title: Settings
partof: scala3-scaladoc
num: 7
previous-page: site-versioning
num: 8
previous-page: search-engine
---

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.
Expand Down
2 changes: 1 addition & 1 deletion _overviews/scala3-scaladoc/site-versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Site versioning
partof: scala3-scaladoc
num: 6
previous-page: blog
next-page: settings
next-page: search-engine
---

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.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resources/images/scala3/scaladoc/inkuire.gif
Binary file not shown.
2 changes: 1 addition & 1 deletion scala3/guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ guides:
url: "/scala3/guides/tasty-overview.html"
description: "An overview over the TASTy format aimed at end-users of the Scala language."
- title: Scaladoc
by: Krzysztof Romanowski, Aleksander Boruch-Gruszecki, Andrzej Ratajczak
by: Krzysztof Romanowski, Aleksander Boruch-Gruszecki, Andrzej Ratajczak, Kacper Korban
icon: book
url: "/scala3/guides/scaladoc"
description: "Scala’s API documentation generation tool."
Expand Down
22 changes: 17 additions & 5 deletions scala3/scaladoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,28 @@ For more information you can follow this [thread](https://contributors.scala-lan
![](../resources/images/scala3/scaladoc/snippet-compiler2.gif)
![](../resources/images/scala3/scaladoc/snippet-compiler1.gif)

### Type-signature browsing
### Type-based search

Haskell programmers are probably familiar with Hoogle - a documentation search engine that allows you browse the docs by signatures rather than symbolic names. Since many Scala developers are also functional programming fans, we decided to add a similar functionality to Scaladoc. The whole tool is based on [Inkuire](https://github.com/VirtusLab/Inkuire), which works with Kotlin and is being currently adapted to Scala 3.
Searching for functions by their symbolic names can be time-consuming.
That is why the new scaladoc allows you to search for methods and fields by their types.

![](../resources/images/scala3/scaladoc/inkuire.gif)

To be up-to-date with this feature you can follow this [thread](https://contributors.scala-lang.org/t/pre-sip-scaladoc-search-by-type-signature/1604/15).
Note that this feature is in an early stage of development. We still don't support type lambdas, higher-kinded types, and some other Scala features.
So, for a declatation:
```
extension [T](arr: IArray[T]) def span(p: T => Boolean): (IArray[T], IArray[T]) = ...
```
Instead of searching for `span` we can also search for `IArray[A] => (A => Boolean) => (IArray[A], IArray[A])`.

To use this feature simply type the signature of the function you are looking for in the scaladoc searchbar. This is how it works:

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

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).

For more information see [Guides](/scala3/guides/scaladoc/search-engine.html)

Note that this feature is still in development, so it can be subject to considerable change.
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).

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