Skip to content

Commit

Permalink
fix: locations of symbols the workspace
Browse files Browse the repository at this point in the history
use filname from the Browse_raw.node location
  • Loading branch information
tatchi authored and rgrinberg committed Apr 15, 2022
1 parent 6caad6c commit 3d3eb8a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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: 2 additions & 2 deletions ocaml-lsp-server/test/e2e/__tests__/workspace-symbol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe("workspace/symbol", () => {
"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>/lib/vendored_lib.ml 0:0 0:9",
"x 12 file://<workspace_symbol_A>/vendor/vendored_lib.ml 0:0 0:9",
]
`);
});
Expand Down Expand Up @@ -187,7 +187,7 @@ describe("workspace/symbol", () => {
"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>/lib/vendored_lib.ml 0:0 0:9",
"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

0 comments on commit 3d3eb8a

Please sign in to comment.