mtsmfm / language_server-ruby

A Ruby Language Server implementation
MIT License
259 stars 8 forks source link

Fix an error that occurs during Definition #42

Closed steiley closed 6 years ago

steiley commented 7 years ago

The following error message always appears on the output of vs code when I select [go to definition] or [show definitions] with the file of my project in editor pane.

/app/lib/language_server/project.rb:15:in `find_definitions': undefined method `refs' for nil:NilClass (NoMethodError)
    from /app/lib/language_server/definition_provider/ad_hoc.rb:12:in `call'
    from /app/lib/language_server.rb:139:in `each'
    from /app/lib/language_server.rb:139:in `flat_map'
    from /app/lib/language_server.rb:139:in `block in <module:LanguageServer>'
    from /app/lib/language_server.rb:45:in `block in run'
    from /vendor/bundle/2.3.4/gems/language_server-protocol-0.4.0/lib/language_server/protocol/transport/stdio/reader.rb:27:in `read'
    from /app/lib/language_server.rb:34:in `run'
    from /app/exe/language_server-ruby:8:in `<top (required)>'
    from bin/language_server-ruby:8:in `load'
    from bin/language_server-ruby:8:in `<main>'

I think it happens because my project directory is out of scope. That seems good to me adding the project root directory to the load path in the initialization process.

What do you think?

mtsmfm commented 7 years ago

@steiley

Thank you for your reporting!

How do you boot the lang server?

In my thought, the server should be added to your project's Gemfile.

steiley commented 7 years ago

@mtsmfm Thank you for your response!

Sorry to forget to tell you that I use VS code(version 1.17.2). I installed the language server in a local ruby environment. The language server is booted by vscode-ruby-lsc.

I added to my project's Gemfile after receiving your advice. But the same error occurs.

Is there anything else I must do?

mtsmfm commented 7 years ago

@steiley

Sorry, my repos lack documentation 💦

Could you change ruby-lsc.commandWithArgs?

https://github.com/mtsmfm/vscode-ruby-lsc#ruby-lsccommandwithargs

Like following:

{
    "ruby-lsc.commandWithArgs": [
        "bundle", "exec", "language_server-ruby"
    ]
}

In my thought, the lang server will be booted via bundler as same as your application.

steiley commented 7 years ago

@mtsmfm

I changed ruby-lsc.commandWithArgs as you suggested But the result was the same.

A project directory isn't parsed unless this project root directory is added to $LOAD_PATH. It seems that there is no point to add that to $LOAD_PATH.

I want to use the Definition for rails development. For exampe contoller A(/rails_root/app/controllers/a.rb) use model B(/rails_root/app/models/b.rb) in a.rb. In that case I want to jump from a.rb to b.rb using the Definition.

Actucally it is not supposed to be.

That case may be not included in your assumption. I hope I can do this if possible.

mtsmfm commented 6 years ago

Sorry for the inconvenience. Adhoc definition provider still has some bugs so I've added --experimental-features flag and disabled it by default.

Close this PR for now but I'm happy if you sent me the code/project you opened at the time.