Skip to content

Commit

Permalink
fix(ocamllsp): workspace symbols fallback to _build folder if source …
Browse files Browse the repository at this point in the history
…file does not exist
  • Loading branch information
tatchi committed May 10, 2023
1 parent ce21883 commit 63645a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions ocaml-lsp-server/src/workspace_symbol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ end

exception Cancelled

let symbols_from_cm_file ~filter root_uri (cancel : Fiber.Cancel.t option)
cm_file =
let symbols_from_cm_file ~build_dir ~filter root_uri
(cancel : Fiber.Cancel.t option) cm_file =
let cmt =
let filename = string_of_cm cm_file in
let cancelled =
Expand All @@ -230,7 +230,14 @@ let symbols_from_cm_file ~filter root_uri (cancel : Fiber.Cancel.t option)
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
let uri =
let sourcefile = Filename.concat root_uri fname in
let path =
if Fpath.exists (Fpath.of_string sourcefile) then sourcefile
else build_dir ^ "/" ^ fname
in
Uri.of_path path
in
filter (Document_symbol.symbols_of_outline uri outline))
| _ -> [])

Expand Down Expand Up @@ -288,7 +295,7 @@ let run ({ query; _ } : WorkspaceSymbolParams.t)
Uri.to_path uri
in
List.concat_map
~f:(symbols_from_cm_file ~filter path cancel)
~f:(symbols_from_cm_file ~build_dir ~filter path cancel)
cm_files))
with Cancelled -> Error `Cancelled

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 @@ -120,7 +120,7 @@ describe("workspace/symbol", () => {
"lib_x 12 /workspace_symbol_A/lib/lib.ml 6:0 6:14",
"user 15 /workspace_symbol_A/lib/lib.ml 3:0 5:1",
"name 7 /workspace_symbol_A/lib/lib.ml 4:2 4:14",
"hello 12 /workspace_symbol_A/lib/gen.ml 0:0 0:19",
"hello 12 /workspace_symbol_A/_build/default/lib/gen.ml 0:0 0:19",
"t 15 /workspace_symbol_A/lib/LibTypes.mli 0:0 0:15",
"x 12 /workspace_symbol_A/vendor/vendored_lib.ml 0:0 0:9",
]
Expand Down Expand Up @@ -201,7 +201,7 @@ describe("workspace/symbol", () => {
"lib_x 12 /workspace_symbol_A/lib/lib.ml 6:0 6:14",
"user 15 /workspace_symbol_A/lib/lib.ml 3:0 5:1",
"name 7 /workspace_symbol_A/lib/lib.ml 4:2 4:14",
"hello 12 /workspace_symbol_A/lib/gen.ml 0:0 0:19",
"hello 12 /workspace_symbol_A/_build/default/lib/gen.ml 0:0 0:19",
"t 15 /workspace_symbol_A/lib/LibTypes.mli 0:0 0:15",
"x 12 /workspace_symbol_A/vendor/vendored_lib.ml 0:0 0:9",
"workspace_B 12 /workspace_symbol_B/main.ml 0:0 0:31",
Expand Down

0 comments on commit 63645a4

Please sign in to comment.