Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigate to Ruby function definition in VS Code

I'm pretty new to Visual Studio Code, and I'm trying to edit some Ruby code. I installed Ruby support, and I enabled the language server, but Ctrl-clicking on a function name doesn't work, and neither does F12. Both of these features work fine for Python code.

How can I navigate from a function call to its definition in Ruby code?

Here's the Ruby code I tried:

def foo
    puts "In foo."
end

foo()

Here are my settings:

{
    "explorer.confirmDelete": false,
    "explorer.confirmDragAndDrop": false,
    "terminal.integrated.fontSize": 15,
    "git.confirmSync": false,
    "ruby.useLanguageServer": true,
    "editor.rulers": [80, 120]
}

Here's the Python code that works fine:

def foo():
    print('In foo.')


foo()
like image 337
Don Kirkby Avatar asked Mar 12 '20 16:03

Don Kirkby


People also ask

How do you navigate to a function in VS Code?

VS Code provides two powerful commands to navigate in and across files with easy-to-use key bindings. Hold Ctrl and press Tab to view a list of all files open in an editor group. To open one of these files, use Tab again to pick the file you want to navigate to, then release Ctrl to open it.

How do you jump to a function in Visual Studio?

For jumping to function in currently opened file use Ctrl+Shift+O . From docs: You can navigate symbols inside a file with Ctrl+Shift+O.

Can I use Ruby on VS Code?

VSCode supports multiple languages like C, C++, Python, Ruby, etc.

How do I enable definition in Visual Studio?

Go To Definition If you are a keyboard user, place your text cursor somewhere inside the symbol name and press F12. If you are a mouse user, either select Go To Definition from the right-click menu or use the Ctrl-click functionality described in the following section.


Video Answer


1 Answers

Thanks to Chris's suggestion, I got a better error message. Following that lead, I found that Ruby's code navigation seems to require a second language server: solargraph. I don't know if you require both, but I can now navigate to Ruby definitions. I also have autocomplete working.

like image 87
Don Kirkby Avatar answered Oct 02 '22 13:10

Don Kirkby