Skip to content
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

Workspace symbol wrong path #671

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Unreleased

## Fixes

- Fix workspace symbols that could have a wrong path in some cases ([#675](https://github.com/ocaml/ocaml-lsp/pull/671))

# 1.10.6

## Fixes
Expand Down
5 changes: 3 additions & 2 deletions ocaml-lsp-server/src/workspace_symbol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,16 @@ let symbols_from_cm_file ~filter root_uri cm_file =
| Some sourcefile -> (
match Filename.extension sourcefile with
| ".ml" | ".mli" -> (
let sourcepath = Filename.concat root_uri sourcefile in
match browse_of_cmt cmt with
| None -> []
| Some browse ->
let outline =
let browse_tree = Merlin_analysis.Browse_tree.of_node browse in
Outline.get [ browse_tree ]
in
let uri = Uri.of_path sourcepath in
let loc = Mbrowse.node_loc browse in
let fname = loc.loc_start.pos_fname in
let uri = Uri.of_path (Filename.concat root_uri fname) in
filter (Document_symbol.symbols_of_outline uri outline))
| _ -> [])

Expand Down
4 changes: 4 additions & 0 deletions ocaml-lsp-server/test/e2e/__tests__/workspace-symbol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ describe("workspace/symbol", () => {
"a_b_t 15 file://<workspace_symbol_A>/bin/a.ml 3:2 3:21",
"a_x 12 file://<workspace_symbol_A>/bin/a.ml 0:0 0:11",
"main_y 12 file://<workspace_symbol_A>/bin/main.ml 0:0 0:22",
"vendored_x 12 file://<workspace_symbol_A>/lib/lib.ml 14:0 14:31",
"lib_type 12 file://<workspace_symbol_A>/lib/lib.ml 12:0 12:38",
"lib_private_fn 12 file://<workspace_symbol_A>/lib/lib.ml 10:0 10:38",
"hd 12 file://<workspace_symbol_A>/lib/lib.ml 8:0 8:16",
"lib_x 12 file://<workspace_symbol_A>/lib/lib.ml 6:0 6:14",
"user 15 file://<workspace_symbol_A>/lib/lib.ml 3:0 5:1",
"name 7 file://<workspace_symbol_A>/lib/lib.ml 4:2 4:14",
"t 15 file://<workspace_symbol_A>/lib/LibTypes.mli 0:0 0:15",
"x 12 file://<workspace_symbol_A>/vendor/vendored_lib.ml 0:0 0:9",
]
`);
});
Expand Down Expand Up @@ -177,13 +179,15 @@ describe("workspace/symbol", () => {
"a_b_t 15 file://<workspace_symbol_A>/bin/a.ml 3:2 3:21",
"a_x 12 file://<workspace_symbol_A>/bin/a.ml 0:0 0:11",
"main_y 12 file://<workspace_symbol_A>/bin/main.ml 0:0 0:22",
"vendored_x 12 file://<workspace_symbol_A>/lib/lib.ml 14:0 14:31",
"lib_type 12 file://<workspace_symbol_A>/lib/lib.ml 12:0 12:38",
"lib_private_fn 12 file://<workspace_symbol_A>/lib/lib.ml 10:0 10:38",
"hd 12 file://<workspace_symbol_A>/lib/lib.ml 8:0 8:16",
"lib_x 12 file://<workspace_symbol_A>/lib/lib.ml 6:0 6:14",
"user 15 file://<workspace_symbol_A>/lib/lib.ml 3:0 5:1",
"name 7 file://<workspace_symbol_A>/lib/lib.ml 4:2 4:14",
"t 15 file://<workspace_symbol_A>/lib/LibTypes.mli 0:0 0:15",
"x 12 file://<workspace_symbol_A>/vendor/vendored_lib.ml 0:0 0:9",
"workspace_B 12 file://<workspace_symbol_B>/main.ml 0:0 0:31",
]
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
(modules_without_implementation libTypes)
(flags :standard -w -32-38-27-34)
(name lib))


(copy_files# ../vendor/*.ml{,i})
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ let hd = List.hd
let lib_private_fn s = print_endline s

let lib_type: LibTypes.t = "lib_types"

let vendored_x = Vendored_lib.x
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x = 5