-
Notifications
You must be signed in to change notification settings - Fork 94
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
Vendor sherlodoc #1259
Closed
Closed
Vendor sherlodoc #1259
Changes from all commits
Commits
Show all changes
294 commits
Select commit
Hold shift + click to select a range
b5f1aa9
reduce js database size
art-w 601520a
specialize trie for string keys
art-w c1a2dda
small size optim to js file
art-w dd8de37
unstash
EmileTrotignon b04e882
search of types
EmileTrotignon 38dc4b1
now supports search for module
EmileTrotignon 669ce1c
Search for exceptions and module types
EmileTrotignon 55aabde
Compatible with latest odoc version
EmileTrotignon 14b1146
Use odoc index
EmileTrotignon 857994e
odoc with search integration
EmileTrotignon 61c298e
package is now optionnal
EmileTrotignon 567724c
format
EmileTrotignon eae585d
odoc compat : links work
EmileTrotignon a3bb78b
reogranization
EmileTrotignon 2cdd2b5
char_list_map separated
EmileTrotignon d3bb61b
Adds type based search of constructors and fields
EmileTrotignon fa59ab8
Print types
EmileTrotignon 27faf9b
REfactoring + new sorting system
EmileTrotignon 0820ee8
Take name length into account to sort results
EmileTrotignon 88e8e7a
add support to print typedecl (with a hack)
EmileTrotignon e71ce73
Remove useless html from search results
EmileTrotignon a52a337
add tests
EmileTrotignon a58f0d6
Index now binds to odoc instead of having to call it first.
EmileTrotignon d665c8b
Compatibilty with odoc 89175b19aeae7e181fd46ce6f74b643367713cfb
EmileTrotignon 3fafe4a
add size options and size tests
EmileTrotignon bf1befa
payloads completely empty (broken)
EmileTrotignon 8e48c8a
index uses arrays instead of sets
EmileTrotignon bae317b
Shares submaps for a big size reduction
EmileTrotignon 19ce128
Uses the browser's decompress api
EmileTrotignon 4d02477
Query uses arrays.
EmileTrotignon 61c2b83
Query arrays directly
EmileTrotignon e4c6138
Restore static order
EmileTrotignon dcaa254
Cleanup
EmileTrotignon 05e4211
flat directory hierarchy
art-w 6e1bfc9
restore website
art-w c73f771
precompute static score
art-w a5c29f3
add missing dune files
art-w d5e88e0
Better performance for cache
EmileTrotignon 0a955ff
Remove json_display
EmileTrotignon f2eb565
sorting ajustments
EmileTrotignon eca30d9
Sherldoc now has a cli interface
EmileTrotignon 9c15dea
ignore perf data
EmileTrotignon 9f58218
Tests order
EmileTrotignon d204bf4
CLI : database can be provided as an environment variable
EmileTrotignon cf3be18
UI update
EmileTrotignon 5fd47a4
sort improvement
EmileTrotignon 15443cb
format
EmileTrotignon caaf3d2
Trie.find is allowed not to find anything
EmileTrotignon ad8445e
Tests update
EmileTrotignon 1983d35
remove unwanted printing
EmileTrotignon 9a49ebe
Returns results before type name is complete
EmileTrotignon d0a258e
Add support for typed search of extension constructors
EmileTrotignon c842e03
add new suffix tree algorithm
art-w d4f6c26
Remove Hocc to fix bug regarding occurence higher than 1
EmileTrotignon b039c45
WIP integrate suffix_tree
EmileTrotignon 66d6107
Bugfix
EmileTrotignon d6a5912
cleanup
art-w 2cda1ab
tokenize docstring
art-w 7fe9635
db without storage functor
art-w 0e55336
remove index_lib
art-w 56355c0
fix suffix_tree elt equality
art-w 528fea6
add weird sorting test
art-w 1adf050
Does not stackoverflow on the browser
EmileTrotignon c3367e5
Add deleted tests back
EmileTrotignon 9eadd69
Use rev_map instead of trmc
EmileTrotignon 5efb48d
Occ is abstract
EmileTrotignon 2d8546c
format
EmileTrotignon 58c09c1
format
EmileTrotignon a9465dc
Bugfix in Succ and make it polymorphic
EmileTrotignon 8728bd4
Adds new test : cli and Succ
EmileTrotignon f9370af
Make length more important for static cost
EmileTrotignon e7ceb43
Typo in comment
EmileTrotignon 45c97c8
Add options for testing the static order
EmileTrotignon 4487ea3
Format
EmileTrotignon 6d3608a
temp commit
EmileTrotignon 1dfb39f
Fix prefixname
EmileTrotignon 5321a8e
Type search of exceptions
EmileTrotignon b74c748
Succ bugfix and better testing
EmileTrotignon 571a01f
format
EmileTrotignon e83d176
Succ cleanup
EmileTrotignon 1a31504
Cleanup query api
EmileTrotignon 9fe953d
Pass id to entries_of_item
trefis 3fb1411
pretty: fix build, does this module make sense?
trefis ad04241
WIP compatibility with odoc PR
EmileTrotignon 1e1d1d0
no titles for doc comments
EmileTrotignon 0377e15
Fixes the name of the generated js object of an entry
EmileTrotignon d9cfda1
New odocls for the base test
EmileTrotignon 4fea97b
Compatibility with odoc cleanup
EmileTrotignon 8b720de
typedecl params are now printed in search results
EmileTrotignon 953cd1f
compatibility with last odoc renaming
EmileTrotignon 6871b21
compatibility with odoc refactoring
EmileTrotignon 8affd98
newlines in cli output
EmileTrotignon 45ef0de
comments and format
EmileTrotignon ca3eac8
odoc compatibility
EmileTrotignon cc414ae
fix compilation with tyxml.4.6.0
Khady 5c2c082
removes syntax error
EmileTrotignon 9df6bad
add limit
EmileTrotignon af73e4a
Just to compile still needs to fix
EmileTrotignon 71429f5
Better error message
EmileTrotignon ca33a60
install sherlodoc.js
EmileTrotignon a533e23
I am not sure about this one
EmileTrotignon ac8556d
wip fix opam dependencies
art-w 23520a8
update tyxml
EmileTrotignon ae7b10f
remove print and whitespaces
EmileTrotignon 3150a5c
fix tests
EmileTrotignon 5d50cda
add dependencies to opam file
EmileTrotignon c8aeb6b
add dependency bounds to opam file
EmileTrotignon 6c6dda7
fix extensiondecl case in pretty
EmileTrotignon 4ad17fa
fmt
EmileTrotignon 762cd32
test on switch
EmileTrotignon b6849e8
update readme
EmileTrotignon cafb613
whole switch test fix
EmileTrotignon 366ea17
readme improvement
EmileTrotignon d742a1e
module type entrie have less priority
EmileTrotignon 8939f75
functor
EmileTrotignon 112d32d
readme update
EmileTrotignon 72d7955
readme update
EmileTrotignon 8602308
readme update
EmileTrotignon 4c86eed
better output flag
EmileTrotignon 34e1964
sort test
EmileTrotignon 8c17c81
typedecl params in cli
EmileTrotignon 74c2ed6
simpler interface for succ
EmileTrotignon 4841740
reafctoring and comments
EmileTrotignon 1bec9c5
document dune files
EmileTrotignon 7d318c1
better readme
EmileTrotignon 2945002
add temporary review file
EmileTrotignon 919ad33
better index cli
EmileTrotignon 69b8636
review update
EmileTrotignon f1cc332
ancient support !
EmileTrotignon 5bbe1fb
Remove Succ.all
EmileTrotignon 4ed6dee
catch all is at jsoo level
EmileTrotignon abdf7f1
suffix_trie collapse gives a tree
EmileTrotignon 427bb54
fix succ.all removal
EmileTrotignon 4392107
tree leafs for types
EmileTrotignon 863e517
parser/lexer are documented
EmileTrotignon 4777e8c
update review.md
EmileTrotignon 094ac1d
wip refactoring of type paths
EmileTrotignon fed7a85
review discussions
EmileTrotignon 7fc9556
exceptions bugfix typepath refactoring wip again
EmileTrotignon 1f7e057
cache typeexprs
EmileTrotignon 76554df
cleanup in pretty
EmileTrotignon 4c58e55
refactoring and documentation
EmileTrotignon 7344ec7
score to cost refactoring
EmileTrotignon 5d1af00
opam deps : search odoc
EmileTrotignon 9398d01
installation instruction in readme
EmileTrotignon 30e1fe7
bugfixes, and changes
EmileTrotignon bc5ff03
remove pretty from api
EmileTrotignon 270a266
update review to be constitant with previous commit
EmileTrotignon 0ed3599
new recursive descent parser
EmileTrotignon 24879e3
fix tests
EmileTrotignon 1d03b3e
new parser works on partial queries
EmileTrotignon 1dce474
better type parser tests
EmileTrotignon fd308b8
better tests
EmileTrotignon 37e7ebf
bigger size tests
EmileTrotignon 97e2eb1
delete useless files from jsoo
EmileTrotignon 98d1e91
separate tests on base
EmileTrotignon fa17340
restore menhir parser and handle _ -> int
EmileTrotignon a06ecb5
improve tests
EmileTrotignon bfd9a22
review update
EmileTrotignon abf85e8
review : moving todo to top
EmileTrotignon d223d60
update readme and resotr compat with last dune rules commit
EmileTrotignon 514a67f
remove unused dependencies
art-w b9bb6a2
upgrade ocamlformat
art-w 96f325b
refactor db storage with/without ancient dependency
art-w 412a1d7
simplify Db.Entry
art-w cdfb34d
simplify index typename
art-w 194a4f5
fix ancient segfaults on empty strings / arrays
art-w a4f0173
remove db_typedef
art-w b38af8a
fix menhir conflicts
art-w 53c96b1
fix candidate sorting
art-w 12b0296
simplify indexing
art-w 11102a3
single command
art-w a93155f
optional dependency to dream
art-w 0115e95
fix cmdliner db argument
art-w abfbdbe
guess db_format from filename extension
art-w d16f726
interactive cli with colors
art-w ad6b9d7
allow search with incomplete type names
art-w 3698993
simplify type occurrences
art-w 91c2b04
sort suffix trie children
art-w 62e529a
remove functor from suffix tree and split construction/usage
art-w b51e61d
optimize search for short queries
art-w 0182637
simplify succ
art-w ec04144
refactor parts of query
art-w 515b469
fetch more results to improve sort quality
art-w 694c7b0
remove dependency to re,tyxml for smaller sherlodoc.js
art-w e9f6151
remove dependency to storage_js for smaller sherlodoc.js
art-w 7263e77
move indexing specific code away from db
art-w 8a3018b
remove dependency to printf for smaller sherlodoc.js
art-w fe52752
fix missing www static files
art-w 496d16b
add cli command to produce sherlodoc.js for dune/odoc integration
art-w 99aec73
lower ocaml version requirement to 4.08
art-w a0f215c
fix memory leaks
art-w ff9e9d2
improve fuzzy type search
art-w 819ca4d
index types in lowercase
art-w 26c6ba1
avoid indexing doc paragraphs and functor parameters
art-w a868412
optimize succ
art-w 2a73215
fix sorting heuristics
art-w 6850f59
prefer names that match query words in order
art-w c14665a
remove unused array_succ
art-w beb8c3d
fix jsoo odoc_html_frontend leading dot
art-w b7a87cf
Update type_polarity.mli comment
EmileTrotignon 4200c91
remove fullfilled todo
EmileTrotignon ce7a0de
fixes and test empty project bug
EmileTrotignon 421ab5e
delete odocls and use odig instead
EmileTrotignon fc53742
delete review.md
EmileTrotignon df8b04d
update readme
EmileTrotignon bb6d459
updates polarity mli comment
EmileTrotignon 106f8e7
performances and bugs fix thanks to voodoo testing
art-w a1f640d
Merge pull request #5 from Khady/louis/tyxml460
art-w a4ee03d
Merge branch 'master' into jsoo
art-w 8b91535
fix missing sort on suffix tree terminals
art-w cba8ade
fix ancient segfault on empty suffix tree
art-w 1b39bd2
test ancient on empty databases
EmileTrotignon 5193f8a
test dont fail when ancient is absent
EmileTrotignon 20c479f
attempt at testing sherlodoc.js size in ci compatible way
EmileTrotignon 3a35e1a
tighten static test enabling
EmileTrotignon 957f20d
remove unreliable test
EmileTrotignon 65d3761
fix jsoo version in static size test
EmileTrotignon 3570369
base web test is now static
EmileTrotignon 46b2ab0
sort ls output in cram test
EmileTrotignon 17fb107
remove odocl size from cli tests
EmileTrotignon aef5b5c
Fast tests on base (#7)
EmileTrotignon 38b494b
remove deps from odig docs build
EmileTrotignon 757ad2b
fix CI for various architectures (#10)
art-w 088cede
Merge pull request #4 from art-w/jsoo
art-w 51db06c
add --version to sherlodoc (0.2)
EmileTrotignon d71cbf2
Merge pull request #18 from EmileTrotignon/version-flag
art-w 032c613
add option to chose a list of favored prefixes
EmileTrotignon db629c5
add file level favouritism
EmileTrotignon b14094e
Merge pull request #15 from EmileTrotignon/stdlib_favouritism
art-w 9b06e29
fix result version, thanks to opam CI lower bounds check
art-w 67dd91f
prepare for release
art-w 648c756
tests link in docstrings (#22)
EmileTrotignon 80ded5e
remove weird warnings
EmileTrotignon d222c61
update readme with dune trick
EmileTrotignon 77ecc82
Merge pull request #25 from art-w/remove_weird_warnings
art-w 184fc92
Fix unvendorable [%blob] path
Julow 555a4f5
Compatibility with ocaml/odoc#1177
panglesd 271f3b9
Compatibility with ocaml/odoc#1081
panglesd 5c2e7db
Compatibility with ocaml/odoc#1242
panglesd 358dc49
Add pretty-printer for entries
panglesd 8f903c7
Compatibility with Odoc 3
panglesd 2f88fa7
Do not rely on odoc's `handle_file`
panglesd 41316e5
Promote tests changed from odoc 3 indexing
panglesd b1dc7a7
Promote test from odoc 3 indexing
panglesd 451f019
Raise lower bound on odoc following update to odoc 3
panglesd f446b0c
Add 'vendor/sherlodoc/' from commit '77ecc829dea23a312a50a74852c32633…
Julow 2c3a7cf
Merge commit '451f0197792836d6e5e2ad3679a040d31f4dd30e' into vendor-s…
Julow 8087cf6
Merge commit '184fc921a4dd19c4a402d8450024e909595082ca' into vendor-s…
Julow e4d74a6
Set Dune rules and Opam dependencies
Julow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,7 @@ | |
(cram enable) | ||
|
||
(using mdx 0.3) | ||
|
||
; Sherlodoc | ||
(using menhir 2.1) | ||
(using directory-targets 0.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
*.annot | ||
*.cmo | ||
*.cma | ||
*.cmi | ||
*.a | ||
*.o | ||
*.cmx | ||
*.cmxs | ||
*.cmxa | ||
|
||
.merlin | ||
*.install | ||
*.coverage | ||
*.sw[lmnop] | ||
|
||
_build/ | ||
_doc/ | ||
_coverage/ | ||
_opam/ | ||
**/perf.data | ||
**/perf.data.old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version = 0.26.1 | ||
profile = janestreet | ||
let-binding-spacing = compact | ||
sequence-style = separator | ||
doc-comments = after-when-possible | ||
exp-grouping = preserve | ||
break-cases = toplevel | ||
cases-exp-indent = 4 | ||
cases-matching-exp-indent = normal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"ocaml.sandbox": { | ||
"kind": "opam", | ||
"switch": "sherlodoc" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Arthur Wendling, Tarides | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
**Try it online at [doc.sherlocode.com](https://doc.sherlocode.com) !** | ||
|
||
Sherlodoc is a search engine for OCaml documentation (inspired by [Hoogle](https://hoogle.haskell.org/)), which allows you to search through OCaml libraries by names and approximate type signatures: | ||
|
||
- Search by name: [`list map`](https://doc.sherlocode.com/?q=list%20map) | ||
- Search inside documentation comments: [`raise Not_found`](https://doc.sherlocode.com/?q=raise%20Not_found) | ||
- Fuzzy type search is introduced with a colon, e.g. [`: map -> list`](https://doc.sherlocode.com/?q=%3A%20map%20-%3E%20list) | ||
- Search by name and type with a colon separator [`Bogue : Button.t`](https://doc.sherlocode.com/?q=Bogue%20%3A%20Button.t) | ||
- An underscore `_` can be used as a wildcard in type queries: [`(int -> _) -> list -> _`](https://doc.sherlocode.com/?q=(int%20-%3E%20_)%20-%3E%20list%20-%3E%20_) | ||
- Type search supports products and reordering of function arguments: [`array -> ('a * int -> bool) -> array`](https://doc.sherlocode.com/?q=%3A%20array%20-%3E%20(%27a%20*%20int%20-%3E%20bool)%20-%3E%20array) | ||
|
||
## Local usage | ||
|
||
First, install sherlodoc and odig: | ||
|
||
```bash | ||
$ opam pin add 'https://github.com/art-w/sherlodoc.git' # optional | ||
|
||
$ opam install sherlodoc odig | ||
``` | ||
|
||
[Odig](https://erratique.ch/software/odig) can generate the odoc documentation of your current switch with: | ||
|
||
```bash | ||
$ odig odoc # followed by `odig doc` to browse your switch documentation | ||
``` | ||
|
||
Which sherlodoc can then index to create a search database: | ||
|
||
```bash | ||
# name your sherlodoc database | ||
$ export SHERLODOC_DB=/tmp/sherlodoc.marshal | ||
|
||
# if you are using OCaml 4, we recommend the `ancient` database format: | ||
$ opam install ancient | ||
$ export SHERLODOC_DB=/tmp/sherlodoc.ancient | ||
|
||
# index all odoc files generated by odig for your current switch: | ||
$ sherlodoc index $(find $OPAM_SWITCH_PREFIX/var/cache/odig/odoc -name '*.odocl' | grep -v __) | ||
``` | ||
|
||
Enjoy searching from the command-line or run the webserver: | ||
|
||
```bash | ||
$ sherlodoc search "map : list" | ||
$ sherlodoc search # interactice cli | ||
|
||
$ opam install dream | ||
$ sherlodoc serve # webserver at http://localhost:1234 | ||
``` | ||
|
||
The different commands support a `--help` argument for more details/options. | ||
|
||
In particular, sherlodoc supports three different file formats for its database, which can be specified either in the filename extension or through the `--db-format=` flag: | ||
- `ancient` for fast database loading using mmap, but is only compatible with OCaml 4. | ||
- `marshal` for when ancient is unavailable, with slower database opening. | ||
- `js` for integration with odoc static html documentation for client-side search without a server. | ||
|
||
## Integration with Odoc | ||
|
||
Odoc 2.4.0 adds a search bar inside the statically generated html documentation. [Integration with dune is in progress](https://github.com/ocaml/dune/pull/9772), you can try it inside a fresh opam switch with: (warning! this will recompile any installed package that depends on dune!) | ||
|
||
```bash | ||
$ opam pin https://github.com/emileTrotignon/dune.git#search-odoc-new | ||
|
||
$ dune build @doc # in your favorite project | ||
``` | ||
|
||
Otherwise, manual integration with odoc requires to add to every call of `odoc html-generate` the flags `--search-uri sherlodoc.js --search-uri db.js` to activate the search bar. You'll also need to generate a search database `db.js` and provide the `sherlodoc.js` dependency (a version of the sherlodoc search engine with odoc support, compiled to javascript): | ||
|
||
```bash | ||
$ sherlodoc index --db=_build/default/_doc/_html/YOUR_LIB/db.js \ | ||
$(find _build/default/_doc/_odocls/YOUR_LIB -name '*.odocl' | grep -v __) | ||
|
||
$ sherlodoc js > _build/default/_doc/_html/sherlodoc.js | ||
``` | ||
|
||
## How it works | ||
|
||
The sherlodoc database uses [Suffix Trees](https://en.wikipedia.org/wiki/Suffix_tree) to search for substrings in value names, documentation and types. During indexation, the suffix trees are compressed to state machine automatas. The children of every node are also sorted, such that a sub-tree can be used as a priority queue during search enumeration. | ||
|
||
To rank the search results, sherlodoc computes a static evaluation of each candidate during indexation. This static scoring biases the search to favor short names, short types, the presence of documentation, etc. When searching, a dynamic evaluation dependent on the user query is used to adjust the static ordering of the results: | ||
|
||
- How similar is the result name to the search query? (to e.g. prefer results which respect the case: [`map`](https://doc.sherlocode.com/?q=map) vs [`Map`](https://doc.sherlocode.com/?q=Map)) | ||
- How similar are the types? (using a tree diff algorithm, as for example [`('a -> 'b -> 'a) -> 'a -> 'b list -> 'a`](https://doc.sherlocode.com/?q=(%27a%20-%3E%20%27b%20-%3E%20%27a)%20-%3E%20%27a%20-%3E%20%27b%20list%20-%3E%20%27a) and [`('a -> 'b -> 'b) -> 'a list -> 'b -> 'b`](https://doc.sherlocode.com/?q=(%27a%20-%3E%20%27b%20-%3E%20%27b)%20-%3E%20%27a%20list%20-%3E%20%27b%20-%3E%20%27b) are isomorphic yet point to `fold_left` and `fold_right` respectively) | ||
|
||
For fuzzy type search, sherlodoc aims to provide good results without requiring a precise search query, on the basis that the user doesn't know the exact type of the things they are looking for (e.g. [`string -> file_descr`](https://doc.sherlocode.com/?q=string%20-%3E%20file_descr) is incomplete but should still point in the right direction). In particular when exploring a package documentation, the common question "how do I produce a value of type `foo`" can be answered with the query `: foo` (and "which functions consume a value of type `bar`" with `: bar -> _`). This should also work when the type can only be produced indirectly through a callback (for example [`: Eio.Switch.t`](https://doc.sherlocode.com/?q=%3A%20Eio.Switch.t) has no direct constructor). To achieve this, sherlodoc performs a type decomposition based on the polarity of each term: A value produced by a function is said to be positive, while an argument consumed by a function is negative. This simplifies away the tree shape of types, allowing their indexation in the suffix trees. The cardinality of each value type is also indexed, to e.g. differentiate between [`list -> list`](https://doc.sherlocode.com/?q=list%20-%3E%20list) and [`list -> list -> list`](https://doc.sherlocode.com/?q=list%20-%3E%20list%20-%3E%20list). | ||
|
||
While the polarity search results are satisfying, sherlodoc offers very limited support for polymorphic variables, type aliases and true type isomorphisms. You should check out the extraordinary [Dowsing](https://github.com/Drup/dowsing) project for this! | ||
|
||
And if you speak French, a more detailed [presentation of Sherlodoc](https://www.irill.org/videos/OUPS/2023-03/wendling.html) (and [Sherlocode](https://sherlocode.com)) was given at the [OCaml Users in PariS (OUPS)](https://oups.frama.io/) in March 2023. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(ocamllex unescape) | ||
|
||
(executable | ||
(name main) | ||
(public_name sherlodoc) | ||
(package odoc-driver) | ||
(libraries | ||
cmdliner | ||
index | ||
query | ||
db_store | ||
unix | ||
(select | ||
serve.ml | ||
from | ||
(www -> serve.available.ml) | ||
(!www -> serve.unavailable.ml))) | ||
(preprocess | ||
(pps ppx_blob)) | ||
(preprocessor_deps ../jsoo/sherlodoc.js)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
let guess_db_format db_format db_filename = | ||
match db_format with | ||
| Some db_format -> db_format | ||
| None -> begin | ||
let ext = Filename.extension db_filename in | ||
let ext_len = String.length ext in | ||
let ext = if ext_len = 0 then ext else String.sub ext 1 (ext_len - 1) in | ||
try List.assoc ext Db_store.available_backends with | ||
| Not_found -> | ||
Format.fprintf | ||
Format.err_formatter | ||
"Unknown db format extension %S (expected: %s)@." | ||
ext | ||
(String.concat ", " @@ List.map fst Db_store.available_backends) ; | ||
exit 1 | ||
end | ||
|
||
open Cmdliner | ||
|
||
let db_format = | ||
let env = | ||
let doc = "Database format" in | ||
Cmd.Env.info "SHERLODOC_FORMAT" ~doc | ||
in | ||
let kind = Arg.enum Db_store.available_backends in | ||
Arg.(value & opt (some kind) None & info [ "format" ] ~docv:"DB_FORMAT" ~env) | ||
|
||
let db_filename = | ||
let env = | ||
let doc = "The database to query" in | ||
Cmd.Env.info "SHERLODOC_DB" ~doc | ||
in | ||
Arg.(required & opt (some string) None & info [ "db"; "o" ] ~docv:"DB" ~env) | ||
|
||
let db_path = | ||
let env = | ||
let doc = "The database to query" in | ||
Cmd.Env.info "SHERLODOC_DB" ~doc | ||
in | ||
Arg.(required & opt (some file) None & info [ "db" ] ~docv:"DB" ~env) | ||
|
||
let with_db fn db_path = | ||
let apply fn db_format db_filename = | ||
let db_format = guess_db_format db_format db_filename in | ||
fn db_format db_filename | ||
in | ||
Term.(const apply $ fn $ db_format $ db_path) | ||
|
||
let cmd_search = | ||
let info = Cmd.info "search" ~doc:"Command-line search" in | ||
Cmd.v info (with_db Search.term db_path) | ||
|
||
let cmd_index = | ||
let doc = "Index odocl files to create a Sherlodoc database" in | ||
let info = Cmd.info "index" ~doc in | ||
Cmd.v info (with_db Index.term db_filename) | ||
|
||
let cmd_serve = | ||
let doc = "Webserver interface" in | ||
let info = Cmd.info "serve" ~doc in | ||
Cmd.v info (with_db Serve.term db_path) | ||
|
||
let cmd_jsoo = | ||
let doc = "For dune/odoc integration, sherlodoc compiled as javascript" in | ||
let info = Cmd.info "js" ~doc in | ||
let target = | ||
let doc = "Name of the file to create" in | ||
Arg.(value & pos 0 string "" & info [] ~docv:"QUERY" ~doc) | ||
in | ||
let emit_js_dep filename = | ||
let close, h = if filename = "" then false, stdout else true, open_out filename in | ||
output_string h [%blob "../jsoo/sherlodoc.js"] ; | ||
if close then close_out h | ||
in | ||
Cmd.v info Term.(const emit_js_dep $ target) | ||
|
||
let cmd = | ||
let doc = "Sherlodoc" in | ||
let version = "0.2" in | ||
let info = Cmd.info "sherlodoc" ~version ~doc in | ||
Cmd.group info [ cmd_search; cmd_index; cmd_serve; cmd_jsoo ] | ||
|
||
let () = exit (Cmd.eval cmd) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to consider sherlodoc as vendored: we want the tests to be run, the warnings to be displayed, ...