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:
Open File: Preferences: Extensions.
Search for Ruby by Peng Lv, and install it.
Open File: Preferences: Settings.
Click the button in the top right to open the JSON settings file:
Add these settings:
{
"ruby.useLanguageServer": true,
"ruby.intellisense": "rubyLocate"
}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 SettingsScroll 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:
- Left-click function name that you want to open.
- Ctrl + t
- Ctrl + enter
Or:
- Change setting
Editor > Goto Location: Multiple
to begotoAndPeek
orgoto
- 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
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 cursor, in the same window. First time it asks for the TAGS file.
C-4 . goes to the method under the cursor. Opens a new window. First time it asks for the TAGS file.
M-, cycles to the next selection.
Related Topics
Ruby Way to Group Anagrams in String Array
Rake Assets:Precompile Gets Killed When There Is a Console Session Open in Production
How to Specify "Http Request Header" in Openuri
How to Instruct Capistrano 3 to Load My Shell Environment Variables Set at Remote Host
Stream Multiple Body Using Async Sinatra
How to Check for Stdin Input in a Ruby Script
How to Run Phantomjs on Heroku
How to Format a String with Floats in Ruby Using #{Variable}
Passing @Object into a Rails Partial Render
How to Get My Aws Lambda to Access Gems Stored in Vendor/Bundle
Get Link and Href Text from HTML Doc with Nokogiri & Ruby
How to Validate the Presence of a Belongs to Association with Rails
Are There Better Ways to Prevent 'Yield' When No Block Is Passed In
Rails: Switch Connection on Each Request But Keep a Connection Pool
Can a Ruby Script Tell What Directory It's In
Pry Not Stopping When Called from a Ruby Script That Reads from Stdin