Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

ExDef tag not found #54

Closed
troq opened this issue Aug 24, 2016 · 17 comments
Closed

ExDef tag not found #54

troq opened this issue Aug 24, 2016 · 17 comments

Comments

@troq
Copy link

troq commented Aug 24, 2016

I'm trying to use the jump to tag definition in alchemist, but when I run :ExDef I get a tag not found error on every tag that I try. Here is my alchemist config and a gif of the error:

let g:alchemist#elixir_erlang_src = '/usr/local/share/src'
autocmd FileType elixir nmap <buffer> gd <c-]>

@slashmili
Copy link
Owner

Hmm It might be because the Hello.UserSocket is not compiled (https://github.com/slashmili/alchemist.vim/wiki#important-notes)

Can you try to run mix compile and try the autocomplete again?

That's known issue(not an issue really) because auto complete uses alchemist-server and if there is no beam file for Hello.UserSocket, it can't find source file for module Hello.UserSocket

@troq
Copy link
Author

troq commented Aug 24, 2016

It still doesn't work after mix compile. I was running it with mix
phoenix.server before so I don't think that'd be the issue. Is there a
debug command I can run to give more info?

On Wednesday, August 24, 2016, Milad notifications@github.com wrote:

Hmm It might be because the Hello.UserSocket is not compiled (
https://github.com/slashmili/alchemist.vim/wiki#important-notes)

Can you try to run mix compile and try the autocomplete again?

That's known issue(not an issue really) because auto complete uses
alchemist-server and if there is no beam file for Hello.UserSocket, it
can't find source file for module Hello.UserSocket


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#54 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AB-JyEcACH76qP3spWtA5RgdHYhmJWGvks5qjDR6gaJpZM4Jr696
.

@slashmili
Copy link
Owner

you can enable debug variable in ~/.vim/bundle/alchemist.vim/alchemist_client, the logs go to syslog. try to trigger jump to definition and see what command is executed in syslog, for ex:

Aug 25 10:41:03 Milads-MacBook-Pro alchemist_client[5167]: DEFLX { "Hello.UserSocket", [ context: Elixir, imports: [Hello.EndPoint], aliases: []] }

You will see DEFLX and DEFL in the log. DEFLX is sent by vim plugin to the client and DEFL is what actually is sent to alchemist-server. DEFLX has some extra functionality like finding the line of the code that a module or a function is defined.

then you can run alchemist client directly and execute the command directly:

~/.vim/bundle/alchemist.vim/alchemist_client -d ~/mix/project/path
DEFLX { "Hello.UserSocket", [ context: Elixir, imports: [Hello.EndPoint], aliases: []] }

If it didn't return the file name, check alchemist-server directly,

$ cd ~/mix/project/path
elixir ~/.dotfiles/.vim/bundle/alchemist.vim/alchemist-server/run.exs --env=dev
DEFL { "Hello.UserSocket,nil", [ context: Elixir, imports: [Hello.EndPoint], aliases: []] }
~/mix/project/path/channels/user_socjet.ex
END-OF-DEFL

After running alchemist server, it's waiting for a command to be entered in STDIN . Past the DEFL command and enter. If IEx is able to find the source file would return the path.

Let me know if you get file path back from alchemist-server.

@troq
Copy link
Author

troq commented Aug 26, 2016

Running the command in alchemist client didn't work but alchemist-server worked. Here's what I ran (both commands were copied directly from syslog):

image

@slashmili
Copy link
Owner

That is indeed strange.

Both of them works for me:

~/d/t/hello $ ~/.vim/bundle/alchemist.vim/alchemist_client -d ./
DEFLX { "Hello.UserSocket", [ context: Elixir, imports: [Hello.Endpoint], aliases: []] }
/Users/milad/dev/tmp/hello/web/channels/user_socket.ex:1
END-OF-DEFLX                                                                                                             
~/d/t/hello $ elixir ~/.dotfiles/.vim/bundle/alchemist.vim/alchemist-server/run.exs --env=dev
DEFL { "Hello.UserSocket,nil", [ context: Elixir, imports: [Hello.Endpoint], aliases: []] }
/Users/milad/dev/tmp/hello/web/channels/user_socket.ex
END-OF-DEFL

Is it possible for you to do more debugging in alchemist.vim/alchemist.py at _send_deflx function? At line 173, it gets the result back from alchemist-server and I want to see if it returns it correctly. looks like at 177 the client doesn't get back any file name as result and return(which apparently it shouldn't)

slashmili added a commit that referenced this issue Aug 26, 2016
It might help in debugging #54
@hykw
Copy link

hykw commented Sep 7, 2016

So am I. I also cannot jumping with E426: tag not found: ***MODULENAME*** error.

@slashmili
Copy link
Owner

@hykw can you also try the same steps as @troq? Also please mention elixir version that you are running on your machine

@hykw
Copy link

hykw commented Sep 8, 2016

I followed the steps, and found out that at least aliases doesn't work correctly.

Notice: I replaced the module name in the following snippets with Sample and TestModule, so it differs with the actual module name I pushed thru STDIN.

$ elixir alchemist-server/run.exs --env=dev
DEFL { "Sample.TestModule,nil", [ context: Elixir, imports: [Sample.TestModule], aliases: [{Sample, Sample.}]] }

15:22:12.411 [error] GenServer #PID<0.117.0> terminating
** (SyntaxError) nofile:1: syntax error before: '}'
    (elixir) src/elixir.erl:184: :elixir.eval/3
    (elixir) lib/code.ex:168: Code.eval_string/3
    alchemist-server/lib/api/defl.exs:83: Alchemist.API.Defl.normalize/1
    alchemist-server/lib/api/defl.exs:13: Alchemist.API.Defl.request/1
    alchemist-server/lib/helpers/process_commands.exs:20: Alchemist.Helpers.ProcessCommands.process/2
    alchemist-server/lib/server/io.exs:21: Alchemist.Server.IO.handle_info/2
    (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4
Last message: :timeout
State: "dev"
** (EXIT from #PID<0.47.0>) an exception was raised:
    ** (SyntaxError) nofile:1: syntax error before: '}'
        (elixir) src/elixir.erl:184: :elixir.eval/3
        (elixir) lib/code.ex:168: Code.eval_string/3
        alchemist-server/lib/api/defl.exs:83: Alchemist.API.Defl.normalize/1
        alchemist-server/lib/api/defl.exs:13: Alchemist.API.Defl.request/1
        alchemist-server/lib/helpers/process_commands.exs:20: Alchemist.Helpers.ProcessCommands.process/2
        alchemist-server/lib/server/io.exs:21: Alchemist.Server.IO.handle_info/2
        (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4

It works to be cut in aliases, but it cannot find the file.

$ elixir alchemist-server/run.exs --env=dev
DEFL { "Sample.TestModule,nil", [ context: Elixir, imports: [Sample.TestModule], aliases: []] }

END-OF-DEFL

Also I found that it correctly finds and jumps to the definitions, when called in routes.ex. In the snippets, Guardian.Plug.VerifySession, Guardian.Plug.LoadResource and Sample.Plug.ConnAssigns are found-able.

pipeline :browser_session do
  plug Guardian.Plug.VerifySession
  plug Guardian.Plug.LoadResource

  plug Sample.Plug.ConnAssigns
end

@slashmili
Copy link
Owner

Hey @hykw thanks for the details. I'll come back to you later :)

@slashmili
Copy link
Owner

@hykw So there are few points:

  1. Autocomplete works after your files are compiled and judging by the name of module, you'r trying to jump to a Test file which is exs which doesn't compile...
  2. The sample that you provided has a wrong alchemist-server protocol which could be easily fixed by the plugin. I believe you had an unfinished line like:
defmodule  Foo
alias Sample.

and before completing the syntax you tried to run ExDef (or maybe you have auto save on or ...). As I mentioned I'll send a patch to not include unfinished like this into alias list

Let me know if my assumptions are correct

@hykw
Copy link

hykw commented Sep 11, 2016

I've prepared a sample project, which reproduces the issue. Doesn't it occure in your environment?
https://github.com/hykw/alchemist-vim_exdef_test

The issue occures in my environment with the following steps:

$ cd src
$ mix phoenix.new

Confirmed the beam files are in _build/dev/lib/sample/ebin/ (I've checked in the files into GitHub, just in case)

$ vi web/router.ex
  • Line 2
    • cursor is on e as in Sample.web(pic1)
    • :ExDef works. jumped to web/web.ex(pic2)
  • Line 19
    • on t as in PageController(pic3)
    • :ExDef fails(pic4)

c.f.
/var/log/message is following.

Sep 11 14:20:43 myserver alchemist_client: Load server settings from: /tmp/alchemist_server/zShomezShitoshi-hayakawazSazSalchemist-vim_exdef_testzSsrc
Sep 11 14:20:43 myserver alchemist_client: response for PING: PONG\nEND-OF-PING\n
Sep 11 14:20:43 myserver alchemist_client: DEFLX { "PageController", [ context: Elixir, imports: [Sample.Router], aliases: []] }
Sep 11 14:20:43 myserver alchemist_client: DEFL { "PageController,nil", [ context: Elixir, imports: [Sample.Router], aliases: []] }
Sep 11 14:20:43 myserver alchemist_client: response for DEFL: \nEND-OF-DEFL\n
  • pic1
    pic1
  • pic2
    pic2
  • pic3
    pic3
  • pic4
    pic4

@slashmili
Copy link
Owner

@hykw thanks a lot for spending time on debugging the issue.

This case is a bit different! which I didn't cover :(

The reason that you can use PageController in the code is because scope is a macro that knows PageController is under Sample module but it's a bit hard to know that in this plugin.

@hykw
Copy link

hykw commented Sep 11, 2016

I've found the correct/wrong case. It fails if alias is set in a module. It doesn't matter called with absoletely(Foo.Bar.foo()) or relatively(Bar.foo()).

Sample code:
https://github.com/hykw/alchemist-vim_exdef_test/blob/master/src/web/controllers/page_controller.ex

The difference beetween Sample.WrongCase and Sample.CorrectCase are alias. It doesn't work in Sample.WrongCase but it does work in Sample.CorrectCase!

@slashmili
Copy link
Owner

Correct it doesn't work in Sample.WrongCase module because of multi line alias (issue #46) which I didn't manage to fix it yet :( try to put the alias in Sample.WrongCase in one line and it should work

@hykw
Copy link

hykw commented Sep 11, 2016

Oops, as you mentioned it worked with one line alias.

alias Sample.Module1

def index(conn, _) do
  foo = Sample.Module1.foo
end

@troq
Copy link
Author

troq commented Oct 1, 2016

@slashmili sorry for being MIA (busy month!). For some reason, ExDef is working as expected now. I'm guessing the bug was caused by an issue with my system state rather than alchemist itself. I'll close the issue for now and reopen if it reoccurs in the future.

@troq troq closed this as completed Oct 1, 2016
@slashmili
Copy link
Owner

Great 👍

Sorry I couldn't help much

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants