diff --git a/ocaml-lsp-server/src/workspace_symbol.ml b/ocaml-lsp-server/src/workspace_symbol.ml index 2f0ef9a6a..dbdab220b 100644 --- a/ocaml-lsp-server/src/workspace_symbol.ml +++ b/ocaml-lsp-server/src/workspace_symbol.ml @@ -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 = @@ -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)) | _ -> []) @@ -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 diff --git a/ocaml-lsp-server/test/e2e/__tests__/workspace-symbol.test.ts b/ocaml-lsp-server/test/e2e/__tests__/workspace-symbol.test.ts index 7d77fa570..9d86f1016 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/workspace-symbol.test.ts +++ b/ocaml-lsp-server/test/e2e/__tests__/workspace-symbol.test.ts @@ -120,6 +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/_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", ] @@ -200,6 +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/_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", diff --git a/ocaml-lsp-server/test/e2e/__tests__/workspace_symbol_A/lib/dune b/ocaml-lsp-server/test/e2e/__tests__/workspace_symbol_A/lib/dune index 0b5c5e2bc..b97308520 100644 --- a/ocaml-lsp-server/test/e2e/__tests__/workspace_symbol_A/lib/dune +++ b/ocaml-lsp-server/test/e2e/__tests__/workspace_symbol_A/lib/dune @@ -4,5 +4,11 @@ (flags :standard -w -32-38-27-34) (name lib)) - (copy_files# ../vendor/*.ml{,i}) + +(rule + (target gen.ml) + (action + (with-stdout-to + %{target} + (echo "let hello = \"world\""))))