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

Locate failing with "not in environment" #898

Closed
ulugbekna opened this issue Oct 26, 2022 · 3 comments · Fixed by ocaml/opam-repository#22456
Closed

Locate failing with "not in environment" #898

ulugbekna opened this issue Oct 26, 2022 · 3 comments · Fixed by ocaml/opam-repository#22456
Assignees
Labels
bug Something isn't working lsp merlin

Comments

@ulugbekna
Copy link
Collaborator

ulugbekna commented Oct 26, 2022

Problem

Go-to-def, go-to-declaration stop working after the first time going to the file of interest.

How to reproduce:

  1. open src/import.ml in vscode_ocaml_platform project.
  2. trigger go-to-def on Ocaml_version module name line 210. This opens .../ocaml_version.ml
  3. switch back to file src/import.ml
  4. trigger again go-to-def on Ocaml_version → locate fails with message “not in environment: Ocaml_version”

Interesting observations:

  • I thought whether opening ocaml_version.ml is causing this problem, so I put code in ocaml_lsp_server.ml (ocaml-lsp project) that would ignore the notification textDocument/didOpen if the file name is ocaml_version.ml . Indeed! After adding this code, I don’t observe this problem, so opening the file must be causing the problem.

    • either olsp opens a file and that triggers some problem in environments
    • or merlin is getting incorrect environment when a file is opened
  • match Env_lookup.in_namespaces nss ident env with
    is the first place that’s causing the error. Env_lookup.in_namespaces nss ident env returns None. The function that it invokes is Env.find_module_by_name that uses Location.(!input_name) that's equal to import.ml on the first run of go-to-def and ocaml_version.ml on the second run. Changing it on Query_commands.dispatch as such Location.(input_name := (Mpipeline.final_config pipeline).Mconfig.query.filename); before the main pattern match doesn't help.

  • Invoking go-to-def on some other symbol in import.ml and coming back to Ocaml_version symbol and then doing go-to-def seems to fix it.


Something similar was reported here before - ocamllabs/vscode-ocaml-platform#970
The error message isn't exactly the same however

@ulugbekna
Copy link
Collaborator Author

Hi Ulysse, do you have any ideas why this may be happening or where I should look? @voodoos

@voodoos
Copy link
Collaborator

voodoos commented Oct 27, 2022

I would guess a configuration issue ?
Maybe OCaml-LSP doesn't refresh the configuration when coming back to the initial file ?
(I will try to reproduce when I find some time.)

@ulugbekna ulugbekna added bug Something isn't working merlin lsp labels Oct 28, 2022
@ulugbekna ulugbekna self-assigned this Oct 28, 2022
rgrinberg added a commit to rgrinberg/opam-repository that referenced this issue Nov 6, 2022
CHANGES:

## Fixes

- Fix random requests failing after switching documents (ocaml/ocaml-lsp#904, fixes ocaml/ocaml-lsp#898)

- Do not offer related diagnostic information unless the user enables in client
  capabilities (ocaml/ocaml-lsp#905)

- Do not offer diagnostic tags unless the client supports them (ocaml/ocaml-lsp#909)

- Do not attach extra data to diagnostics unless the client supports this
  (ocaml/ocaml-lsp#910)

- Use /bin/sh instead of /bin/bash. This fixes ocamllsp on NixOS
@ulugbekna
Copy link
Collaborator Author

Fixed in #904

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lsp merlin
Projects
None yet
2 participants