Navigate to Ruby Function Definition in VS Code

Navigate to Ruby function definition in VS Code

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 to autocomplete working.

Update [2022]

Coming back to this with VSCode 1.67.0 on Ubuntu 22.04, I no longer require solargraph. However, I did struggle a bit to figure out the exact steps to get it working:

  1. Open File: Preferences: Extensions.

  2. Search for Ruby by Peng Lv, and install it.

  3. Open File: Preferences: Settings.

  4. Click the button in the top right to open the JSON settings file:
    Sample Image

  5. Add these settings:

    {
    "ruby.useLanguageServer": true,
    "ruby.intellisense": "rubyLocate"
    }
  6. Restart VSCode.

Is it possible to navigate from feature file to step definition in VSCode

You can install Cucumber (Gherkin) Full Support extension from the VSCode Marketplace:

After install is finished, reload VSCode.
Now in order to make it work for Ruby, you need to:

  • Press Ctrl + , to open User Settings

  • Scroll down to Cucumber Auto Complete

  • On the right side you need to modify these settings (you can find 2 examples of how to do this on the extension page). In my case, I added the following:

      "cucumberautocomplete.steps": [
    "features/step_definitions/*.rb"
    ],
    "cucumberautocomplete.syncfeatures": "features/*feature"
  • Reload VSCode

  • Open a .feature file and right click any step, you should have Go To Definition and Peek Definition working.

Hope you get it working!

How to open 'Go to definition' in other split tab for same file in VS Code?

There are 2 ways to achieve this.

Either:

  1. Left-click function name that you want to open.
  2. Ctrl + t
  3. Ctrl + enter

Or:

  1. Change setting Editor > Goto Location: Multiple to be gotoAndPeek or goto
  2. Ctrl + Alt + [click on function name]

Both methods will open the definition in the split to the right (or create a new split if this is the right-most split).

You like?

How I can make `ctrl + click` to go to definition in visual studio code editor for mac OS?

First and foremost, please note that in VS Code for macOS, the familiar Ctrl + click from Windows / Linux operating systems has been replaced with + click (i.e.: "command + click"). Try that first before proceeding any further as that shortcut should work out of the box without any special modifications.

However, if the above still doesn't work for you then try fixing the problem by editing your settings.json file. To do that, press F1, type settings json, then click Open Settings (JSON), and then do one of the following:

To use + click as your "Go to definition" shortcut, ensure the following line exists in your JSON settings:

"editor.multiCursorModifier": "alt",

What this does is it explicitly sets VS Code's "add another cursor" shortcut to option + click (try it out for yourself!), thus freeing up + click to be used for the "Go to definition" operation.

Conversely, to use option + click as your "Go to definition" shortcut instead, add:

"editor.multiCursorModifier": "ctrlCmd",

Note: the above line will actually set the "add another cursor" shortcut to + click (not Ctrl + + click, as implied by the JSON value).

How to show uses of function in Visual Studio Code?

you can use shift+f12 for get better view of usage

https://github.com/Microsoft/vscode-tips-and-tricks

read this and you can get better idea

How search for method in VSCode?

For search method name you can use CTRL + P and then start search with #

for example : #register

Or press CTRL + T and type method name

Sample Image

Quick navigate to the definition code of a function from another ruby gem in Emacs using ctags

Use the following command it the directory where your gems are installed:

ctags -e -a --Ruby-kinds=-fF -o TAGS -R .

Afterwards press M-. in Emacs while your cursor is over the Watir word. Emacs will prompt you for the location of the TAGS file and afterwards it will jump to the definition of the type.

Basic etags usage in Emacs:

M-. goes to the method under the cur­sor, in the same win­dow. First time it asks for the TAGS file.
C-4 . goes to the method under the cur­sor. Opens a new win­dow. First time it asks for the TAGS file.
M-, cycles to the next selection.



Related Topics



Leave a reply



Submit