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

Go to Definition Not Working for Functions Defined in Same File #294

Closed
afrazkhan opened this issue Mar 13, 2018 · 8 comments
Closed

Go to Definition Not Working for Functions Defined in Same File #294

afrazkhan opened this issue Mar 13, 2018 · 8 comments

Comments

@afrazkhan
Copy link

Your environment

  • vscode-ruby version: 0.17.0
  • Ruby version: 2.4.3
  • VS Code version: 1.21.0
  • Operating System: MacOS 10.12.6
  • Hardware (optional): Macbook Air

Make sure you have ruby, ruby-debug-ide and ruby-debug-basex19
Couldn't find anything like "ruby-debug*" in extensions, sorry.

Expected behavior

The "Go to Definition" / "Peek Definition" feature finds local file definitions.

Actual behavior

Above features work for definitions if they are located in other files, but not the same file. i.e. If I look do "Go to Definition" for a function, it is only found if that function is defined in a different file, not the file I triggered the find from.

Steps to reproduce the problem

"Go to Definition" on a function defined in the same file.

@jcw-
Copy link

jcw- commented Mar 20, 2018

Recently, "Go To Definition" disappeared for me and others - this is because somehow it was switched to being powered by solargraph (I didn't have solargraph installed). I'm guessing #248 changed this default.

It's possible you're experiencing a difference between rubyLocate and solargraph - check your ruby.intellisense setting, as described here:
microsoft/vscode#45915

I've since since tried both of the settings and rubyLocate works much better ("Go To Definition" fails the majority of the time for me with the solargraph setting).

@afrazkhan
Copy link
Author

Thanks, but now the feature doesn't work at all :D

Putting that setting in means "Go to Definition" doesn't find anything, and removing it means the menu item "Go to Definition" doesn't even appear.

Looking in "Default Settings" (as opposed to "User Settings"), I see that there is no option "ruby.intellisense", for whatever that's worth.

@gurgeous
Copy link
Contributor

There are several ways to get "Go to Definition" working:

  1. Install the Solargraph extension, which provides code completion and excellent doc lookups. It's an ambitious attempt to fully parse your Ruby project with Ruby. This extension is progressing rapidly and the author (@castwide) is also contributing to vscode-ruby.

  2. The rubyLocate feature created by @HookyQR and built into vscode-ruby. You'll have to set ruby.intellisense to rubyLocate to turn this on. It uses Javascript code to parse your ruby files and look for definitions. This is built in and decently fast, but as far as I know it doesn't deal with dependencies (like gems).

  3. I am working on a third option called Bust A Gem that uses TAGS files specifically for Go to Definition. I can't recommend it yet because it's too new, but you are welcome to experiment by installing the extension.

We probably need to buff up the readme, as well as the warnings/errors produced by vscode.ruby for these various scenarios. I will probably attempt to address that once my outstanding PRs have been merged.

@afrazkhan
Copy link
Author

Thanks mate. So just to confirm, with option 2, I'd be putting in the following into my user settings:

"ruby.intellisense": "rubyLocate",

When I have that, I get the old "No definition found ..." for Go to Definition.

When I change it to "solargraph", or omit the option (and I have solagraph installed), the entire option of Go to Definition is unavailable.

@gurgeous
Copy link
Contributor

That's correct - setting it to rubyLocate should turn on the rubyLocate feature built into vscode-ruby. It might fail to work for various reasons and the error messages may not be implemented. For example, it only works if you open a project (not a file). For more debugging hints try "Help > Toggle Developer Tools". You can also see if it seems to be indexing by checking your status bar. A VS code restart might be required to turn it on.

Solargraph has its own set of constraints, which I'm not as familiar with. Last time I tried it I was able to get great results for stdlib methods and decent results for stuff in my project.

@afrazkhan
Copy link
Author

So! Turns out that solargraph wasn't installed. I'm sure it was up until last week, but perhaps it had something to do with RVM (some things to do with a new Ruby changed on my machine last week).

Keeping it set to solargraph seems to be working pretty well, so I'll see how it goes. "rubyLocate" still doesn't work, and bringing up debugging as suggested shows problems all over the place ;)

This was the last thing that was keeping me from switching from Atom, so I guess I'll be configuring all my keyboard shortcuts and whatnot for the rest of the day. Thanks buddy!

@pavelz
Copy link

pavelz commented Apr 4, 2023

not working again. I wonder what is the fix these days

@akiouchiyama
Copy link

not working again. I wonder what is the fix these days

Not working here to. I've installed the Ruby by Peng Lv and add this:
{
"ruby.useLanguageServer": true,
"ruby.intellisense": "rubyLocate"
}

to my settings.json

But, it had no effect 😞

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

5 participants