slashmili/alchemist.vim

definition_not_found% for local definition in small project (wrong working directory?)

jvdvleuten opened this issue · 5 comments

I used the debugging mode and also checked the log file, please see below. I had a simple Mix project defined with:

mix new my_project
cd my_project
mix compile

Local definitions did not work unfortunately when looking up a definition in the pre-created test file. On a bigger project with Phoenix, local definitions did work. Maybe I am missing something crucial in the directory setup of a smaller project?

When looking up a definition in the "Lookup Project's Library" from the debug page, I get:

my_project % /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense_client -d./ -c1 -l2 --request=definition < sample.exs
definition_not_found%

Even after running mix compile after I added the sample.exs files I get the same error.

In the log file:

Initializing ElixirSense server for environment "dev" (Elixir version 1.10.2)

Working directory is "/Users/jvdvleuten/git"

ok:localhost:/tmp/elixir-sense-jvdvleuten/1587297811646570000.sock

ElixirSense: {u'request_id': 1, u'payload': {u'column': None, u'found': False, u'line': None, u'type': None, u'file': None}, u'error': None}
response:
definition_not_found

What I find strange is that the working directory is the /git/ directory and not the /git/my_project directory. Has that something to do with it maybe? I am running the command from the /git/my_project folder. With the phoenix project it stays in the correct working directory.

I do get a lot of warnings at the beginning of the log file, but this is also the case with working jumping to elixir definitions, which do work.

However, as I said, it starts with project_dir(matched) to my git directory in stead of git/my_project directory. I am unsure why.. my git folder does contain otp and elixir folder as per the manual.

project_dir(matched): /Users/jvdvleuten/git
column: 1
line: 2
source: Enum.map
CustomModule
CustomModule.foo

Load server settings from: /var/folders/7n/1h6w2_7d5jq7s2yz97mjqylc0000gn/T/alchemist_server/zS2UserszS2jvdvleutenzS2git
warning: Alchemist.Helpers.ModuleInfo.all_applications_modules/0 is undefined (module Alchemist.Helpers.ModuleInfo is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/core/introspection.ex:73: ElixirSense.Core.Introspection.all_modules/0



warning: Alchemist.Helpers.ModuleInfo.docs?/2 is undefined (module Alchemist.Helpers.ModuleInfo is not available or is yet to be defined)

Found at 2 locations:

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/core/introspection.ex:615: ElixirSense.Core.Introspection.find_kernel_function/1

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/core/introspection.ex:617: ElixirSense.Core.Introspection.find_kernel_function/1



warning: Alchemist.Helpers.ModuleInfo.expand_alias/2 is undefined (module Alchemist.Helpers.ModuleInfo is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/core/introspection.ex:647: ElixirSense.Core.Introspection.find_aliased_function/2



warning: Alchemist.Helpers.ModuleInfo.has_function?/2 is undefined (module Alchemist.Helpers.ModuleInfo is not available or is yet to be defined)

Found at 2 locations:

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/core/introspection.ex:628: ElixirSense.Core.Introspection.find_imported_function/2

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/core/introspection.ex:655: ElixirSense.Core.Introspection.find_function_in_module/1



warning: Code.get_docs/2 is deprecated. Code.get_docs/2 always returns nil as its outdated documentation is no longer stored on BEAM files. Use Code.fetch_docs/1 instead

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/core/introspection.ex:68: ElixirSense.Core.Introspection.get_docs/2



warning: Code.ensure_compiled?/1 is deprecated. Use Code.ensure_compiled/1 instead (see the proper disclaimers in its docs)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/core/ast.ex:64: ElixirSense.Core.Ast.add_directive_modules_to_env/3



warning: ElixirSense.all_modules/0 is undefined (module ElixirSense is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/server/request_handler.ex:38: ElixirSense.Server.RequestHandler.handle_request/2



warning: ElixirSense.definition/3 is undefined (module ElixirSense is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/server/request_handler.ex:18: ElixirSense.Server.RequestHandler.handle_request/2



warning: ElixirSense.docs/3 is undefined (module ElixirSense is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/server/request_handler.ex:14: ElixirSense.Server.RequestHandler.handle_request/2



warning: ElixirSense.expand_full/3 is undefined (module ElixirSense is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/server/request_handler.ex:26: ElixirSense.Server.RequestHandler.handle_request/2



warning: ElixirSense.match/1 is undefined (module ElixirSense is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/server/request_handler.ex:34: ElixirSense.Server.RequestHandler.handle_request/2



warning: ElixirSense.quote/1 is undefined (module ElixirSense is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/server/request_handler.ex:30: ElixirSense.Server.RequestHandler.handle_request/2



warning: ElixirSense.signature/3 is undefined (module ElixirSense is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/server/request_handler.ex:10: ElixirSense.Server.RequestHandler.handle_request/2



warning: ElixirSense.suggestions/3 is undefined (module ElixirSense is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/server/request_handler.ex:22: ElixirSense.Server.RequestHandler.handle_request/2



warning: ElixirSense.Server.ContextLoader.set_context/2 is undefined (module ElixirSense.Server.ContextLoader is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/server/request_handler.ex:42: ElixirSense.Server.RequestHandler.handle_request/2



warning: SelfDestructTimer.reset/0 is undefined (module SelfDestructTimer is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense/server/tcp_server.ex:77: ElixirSense.Server.TCPServer.connection_handler/2



warning: ElixirSense.Providers.References.find/6 is undefined (module ElixirSense.Providers.References is not available or is yet to be defined)

  /Users/jvdvleuten/.vim/plugged/alchemist.vim/elixir_sense/lib/elixir_sense.ex:317: ElixirSense.references/3

1. Elixir/OTP/Python version

Elixir: 1.10.2

OTP: 22

Python: 3.7.7

2. Are you using VIM or Neovim? Please provide the version.

VIM 8.2

3. Which pluging are you using:

[ ] basic omnifunc
[ ] YouCompleteMe
[Y] deoplete

4. Which steps of Debugging passed?

[Y] Elixir Module definition
[Y] Elixir Function definition
[Y] Elixir Module/Function docs
[] Your Project Module definition
[] Your Project Function definition

5. Do you have a specific setup? Like Docker and etc

No, normal setup with VIM.

I did edit the elixir_sense.py file and commented out the following lines:

        if running_servers_logs == None:
            running_servers_logs = os.listdir(self._get_tmp_dir())
        paths = self._cwd.split(os.sep)
        mix_dir = []
        for i in range(len(paths)):
            project_dir = os.sep.join(paths[:len(paths)-i])
            if not project_dir:
                continue
            # log_tmp = "%s" % project_dir.replace("/", "zS2")
            # if log_tmp in running_servers_logs:
            #     self._log("project_dir(matched): "+str(project_dir))
            #     return project_dir

            if os.path.exists(os.path.join(project_dir, "mix.exs")):
                mix_dir.append(project_dir)

        self._log("mix_dir: "+str(mix_dir))
        if len(mix_dir):
            return mix_dir.pop()

        return self._cwd

Which fixes my issue. I can't seem to grasp what it is trying to do with the log_tmp and zS2 variables. However, it now correctly finds the mix.exs file, even in my small project and in debugging mode which fixes the issue.

Great plugin! Works like a charm again. :) I obviously have a wrong configuration or directory structure which messes with getting the correct working project directory. Can you maybe explain what this function is trying to do, or what I am doing wrong in my project setup? Thanks !!

Hi @jvdvleuten,

I'm glad that you'r enjoying it while puts you in troubles!

elixir_sense server runs separate as the vim instance. When alchemist.vim wants to send the request to elixir_sense server, it needs to check if there is a server already running for your project and if it's running, what is the socket file it needs to use to talk to the server.

it does it by translating your working directory to a file in tmp dir. it replaces the / in your path to zS2. So /home/user/projects/phoenix translates to /YOUR-TMP-DIR~/zS2homezS2userzS2projectszS2phoenix

So if you removed that line, it means every command you send to the server, it create a new server(check number of elixir process, it should many of them)

Thanks for the reply!

Fairly new to vim, elixir and all that stuff. So lots of figuring out and maybe part of the journey...

I did check my processes after going to definitions for a while and looking up documentation in VIM, and this does increase the number of erlang processes. Which is strange.. I tried both the activity monitor (Mac) and ps in terminal. On the first try it fails with socket not found, thereafter everything works. It also does not increase the number of folders in the $TMPDIR/alchemist_server.

Maybe to fix the issues completely, do you know by any chance why my working directory is one directory up than where the mix.exs resides in for my small project? I can't figure out why it does that unless I comment the lines out. I do see my "git" folder in the $TMPDIR/alchemist_server, maybe that is a mistake and I have to delete it to force it to match on my real project?

I followed these steps

cd /tmp
mix new my_project
cd my_project
mix compile
vim lib/my_project.ex (and trigger by auto complete or docs lookup)

and I only see /var/folders/h8/..../T/alchemist_server/zS2privatezS2tmpzS2my_project in my temp directory.

They way that this scripts lookup the mix_dir is by
https://github.com/slashmili/alchemist.vim/blob/master/elixir_sense.py#L437-L452

Looks up at your current directory, if there is a mix.exs this is the root of your project otherwise goes one directory up and checks it until it finds mix.exs file

That's what I thought it was doing, but somehow it called my root git folder. Anyway, I reset my computer, the alchemist_server TMPDIR was cleared and now everything is working correctly. I think my ~/git/ folder ended up in the TMPDIR, which was being used (catched earlier) than my project folder. Strange.. I must have messed something up while figuring vim out. Did not run in any other issues again, have been using the plugin for quite some time now :)

Thanks for the response and your time!