JakeBecker / elixir-ls

A frontend-independent IDE "smartness" server for Elixir. Implements the JSON-based "Language Server Protocol" standard and provides debugger support via VS Code's debugger protocol.
Apache License 2.0
846 stars 52 forks source link

Error with import MyApp.{ModA, ModB} (Originally in elixir-lsp fork) #168

Closed zachdaniel closed 4 years ago

zachdaniel commented 5 years ago

Copying @manukall's original issue below:

Environment

When visiting a file that is using a module that has a line like import MyApp.{ModA, ModB} in it's using macro, the following error is raised:

LSP :: an exception was raised:
    ** (FunctionClauseError) no function clause matching in Code.ensure_loaded/1
        (elixir) lib/code.ex:985: Code.ensure_loaded({{:., [], [ElixirLsTest, :{}]}, [], [ModA, ModB]})
        (elixir_sense) lib/alchemist/helpers/module_info.ex:64: Alchemist.Helpers.ModuleInfo.get_module_funs/1
        (elixir_sense) lib/alchemist/helpers/module_info.ex:52: Alchemist.Helpers.ModuleInfo.has_function?/2
        (elixir) lib/enum.ex:2948: Enum.find_list/3
        (elixir_sense) lib/elixir_sense/core/introspection.ex:628: ElixirSense.Core.Introspection.find_imported_function/2
        (elixir_sense) lib/elixir_sense/core/introspection.ex:602: ElixirSense.Core.Introspection.actual_mod_fun/4
        (elixir_sense) lib/elixir_sense/providers/docs.ex:12: ElixirSense.Providers.Docs.all/4
        (elixir_sense) lib/elixir_sense.ex:50: ElixirSense.docs/3

I've set up a test repo at manukall/elixir_ls_test. When opening the file lib/elixir_ls_test/using.ex I get the above error.


I was able to do some slight debugging, and found that adding the below function head to elixir_sense's metadata_builder.ex resolved the issue. I don't have time to look into it further at the moment, unfortunately. I'm unsure if this is an elixir sense issue or an elixir-ls issue.

+  defp pre({:import, [line: line, column: _column], [{{:., _, [module, :{}]}, _, imports}]} = ast, state) when is_atom(module) do
+    imports_modules = imports |> Enum.map(fn {:__aliases__, _, mods} ->
+      Module.concat([module | mods])
+    end)
+    pre_import(ast, state, line, imports_modules)
+  end
+
   # import without options
   defp pre({:import, meta, [module_info]}, state) do
     pre({:import, meta, [module_info, []]}, state)
zachdaniel commented 5 years ago

Actually, I don't know if that did fix it, unfortunately. It seemed to be working for a while but isn't now? Unsure what could have changed.

lukaszsamson commented 5 years ago

Root issue fixed in https://github.com/elixir-lsp/elixir_sense/pull/30 update elixir_sense dependancy to fix this

JakeBecker commented 4 years ago

This project has moved!

It's now being maintained by proactive volunteers from the Elixir community over at elixir-lsp/elixir-ls. Updates will continue to be published from that repo to the original VS Code extension, so no need to switch plugins if you're using VS Code.

To avoid inundating the new maintainers with issues, please verify that your issue persists with the latest version of the extension (which is published from the new repo) before re-filing your issue there.

Thanks for using ElixirLS!