Skip to content

Conversation

@katafrakt
Copy link
Contributor

This happens to me when the project is opened where a Mix project is not in the root directory, but in a subdirectory (i.e. a typocal monorepo setting). Expert can still resolve some things (go to definition), some don't work (hover docs), but when it comes to code lens, it just throws an exception.

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1\n    (elixir 1.19.4) lib/io.ex:738: IO.chardata_to_string(nil)\n    (elixir 1.19.4) lib/path.ex:835: Path.expand_home/1\n    (elixir 1.19.4) lib/path.ex:195: Path.expand/1\n    (xp_expert 0.1.0) lib/expert/provider/handlers/code_lens.ex:65: XPExpert.Provider.Handlers.CodeLens.normalize_path/1\n    (xp_expert 0.1.0) lib/expert/provider/handlers/code_lens.ex:57: XPExpert.Provider.Handlers.CodeLens.show_reindex_lens?/2\n    (xp_expert 0.1.0) lib/expert/provider/handlers/code_lens.ex:31: XPExpert.Provider.Handlers.CodeLens.reindex_lens/2\n    (xp_expert 0.1.0) lib/expert/provider/handlers/code_lens.ex:22: XPExpert.Provider.Handlers.CodeLens.handle/2\n    (xp_expert 0.1.0) lib/expert.ex:115: XPExpert.handle_request/2\n","type":1}}

Given that Project.mix_exs_path can explicitly (based on a type spec) return nil, this situation should be handled gracefully and the function should return false, not result in an exception.

This happens when the project is opened where a Mix project is not in
the root directory, but in a subdirectory. Expert can still resolve some
things, some don't work, but when it comes to code lens, it just throws
exception.

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1\n    (elixir 1.19.4) lib/io.ex:738: IO.chardata_to_string(nil)\n    (elixir 1.19.4) lib/path.ex:835: Path.expand_home/1\n    (elixir 1.19.4) lib/path.ex:195: Path.expand/1\n    (xp_expert 0.1.0) lib/expert/provider/handlers/code_lens.ex:65: XPExpert.Provider.Handlers.CodeLens.normalize_path/1\n    (xp_expert 0.1.0) lib/expert/provider/handlers/code_lens.ex:57: XPExpert.Provider.Handlers.CodeLens.show_reindex_lens?/2\n    (xp_expert 0.1.0) lib/expert/provider/handlers/code_lens.ex:31: XPExpert.Provider.Handlers.CodeLens.reindex_lens/2\n    (xp_expert 0.1.0) lib/expert/provider/handlers/code_lens.ex:22: XPExpert.Provider.Handlers.CodeLens.handle/2\n    (xp_expert 0.1.0) lib/expert.ex:115: XPExpert.handle_request/2\n","type":1}}

Given that Project.mix_exs_path can explicitly (based on a
type spec) return nil, so this situation should be handled gracefully.
@katafrakt katafrakt changed the title Fix code lens exception when mix.exs not found fix(engine): code lens exception when mix.exs not found Dec 30, 2025
Copy link
Collaborator

@doorgan doorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 💜

@doorgan doorgan merged commit f9c81da into elixir-lang:main Dec 30, 2025
37 of 38 checks passed
@katafrakt katafrakt deleted the code-lens-exception branch December 30, 2025 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants