Skip to content

Commit 172601c

Browse files
authored
Merge pull request #1364 from ocaml/locate-state-reset
[locate] reset state from entry points
2 parents 5731826 + fb6773b commit 172601c

File tree

6 files changed

+104
-2
lines changed

6 files changed

+104
-2
lines changed

src/analysis/locate.ml

+6-2
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,6 @@ end = struct
703703
end
704704

705705
let locate ~config ~ml_or_mli ~path ~lazy_trie ~pos ~str_ident loc =
706-
File_switching.reset ();
707-
Fallback.reset ();
708706
Preferences.set ml_or_mli;
709707
log ~title:"locate"
710708
"present in the environment, walking up the typedtree looking for '%s'"
@@ -740,6 +738,8 @@ let from_longident ~config ~env ~lazy_trie ~pos nss ml_or_mli ident =
740738
locate ~config ~ml_or_mli ~path:tagged_path ~lazy_trie ~pos ~str_ident loc
741739

742740
let from_path ~config ~env ~local_defs ~pos ~namespace ml_or_mli path =
741+
File_switching.reset ();
742+
Fallback.reset ();
743743
let str_ident = Path.name path in
744744
if Utils.is_builtin_path path then
745745
`Builtin
@@ -761,6 +761,8 @@ let from_path ~config ~env ~local_defs ~pos ~namespace ml_or_mli path =
761761
| `Found (loc, _) -> find_source ~config loc str_ident
762762

763763
let from_string ~config ~env ~local_defs ~pos ?namespaces switch path =
764+
File_switching.reset ();
765+
Fallback.reset ();
764766
let browse = Mbrowse.of_typedtree local_defs in
765767
let lazy_trie =
766768
lazy (Typedtrie.of_browses ~local_buffer:true
@@ -808,6 +810,8 @@ let from_string ~config ~env ~local_defs ~pos ?namespaces switch path =
808810
| `Found (loc, _) -> find_source ~config loc path
809811

810812
let get_doc ~config ~env ~local_defs ~comments ~pos =
813+
File_switching.reset ();
814+
Fallback.reset ();
811815
let browse = Mbrowse.of_typedtree local_defs in
812816
let lazy_trie = lazy (Typedtrie.of_browses ~local_buffer:true
813817
[Browse_tree.of_browse browse]) in
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
A test showing that we manage to get docstrings even when they are not kept as
2+
attributes on the AST.
3+
4+
$ cat >test.ml <<EOF
5+
> let foo x y = (** incorrect doc for foo *)
6+
> x + y
7+
>
8+
> let bar = foo
9+
> EOF
10+
11+
$ $MERLIN single document -position 4:13 -filename test.ml < test.ml
12+
{
13+
"class": "return",
14+
"value": "incorrect doc for foo",
15+
"notifications": []
16+
}
17+
18+
And that it also works outside of the current buffer:
19+
20+
$ $OCAMLC -c -bin-annot -w +50 test.ml
21+
File "test.ml", line 1, characters 14-42:
22+
1 | let foo x y = (** incorrect doc for foo *)
23+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
Warning 50 [unexpected-docstring]: unattached documentation comment (ignored)
25+
26+
$ $MERLIN single document -position 1:18 -filename outside.ml << EOF
27+
> let bar = Test.foo
28+
> EOF
29+
{
30+
"class": "return",
31+
"value": "incorrect doc for foo",
32+
"notifications": []
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Reproduce [ocaml-lsp #344](https://github.com/ocaml/ocaml-lsp/issues/344): a symbol's
2+
documentation is some other random documentation from a library that was last pulled for
3+
completion. See the issue for details. The space is necessary for the position of
4+
documentation to be fetch-able.
5+
6+
$ cat >lib_doc.ml <<EOF
7+
>
8+
>
9+
>
10+
>
11+
>
12+
>
13+
>
14+
>
15+
>
16+
>
17+
>
18+
>
19+
>
20+
>
21+
>
22+
>
23+
>
24+
>
25+
>
26+
>
27+
>
28+
>
29+
> let k = ()
30+
> let m = List.map
31+
> EOF
32+
33+
we need merlin to keep state between requests, so using server
34+
35+
$ $MERLIN server stop-server
36+
37+
see that there is no doc for k
38+
39+
$ $MERLIN server document -position 23:5 < lib_doc.ml | jq '.value'
40+
"No documentation available"
41+
42+
we trigger the bug
43+
44+
$ $MERLIN server document -position 24:15 -filename lib_doc < lib_doc.ml
45+
{
46+
"class": "return",
47+
"value": " [map f [a1; ...; an]] applies function [f] to [a1, ..., an],
48+
and builds the list [[f a1; ...; f an]]
49+
with the results returned by [f]. Not tail-recursive.
50+
",
51+
"notifications": []
52+
}
53+
54+
random documentation is fetched for the same `document` request as before
55+
56+
$ $MERLIN server document -position 23:5 < lib_doc.ml
57+
{
58+
"class": "return",
59+
"value": "No documentation available",
60+
"notifications": []
61+
}
62+
63+
stop server
64+
65+
$ $MERLIN server stop-server

0 commit comments

Comments
 (0)