问题
This seems like it should be easy.
I'm creating a CLI command gem, so the command is in bin/gem_name
which has no .rb
extension. When I try to edit that file in RubyMine, it doesn't give it a language mode (sorry, don't know the proper term) to make syntax highlighting and other niftyness in RubyMine work.
How can I tell RubyMine that this is, in fact, a Ruby file?
回答1:
There are several ways to tell RubyMine that a file is of a particular type:
Begin the command file with a hashbang line that RubyMine recognizes as being Ruby. I don't know what exactly it recognizes, but all of the scripts that gems put in to my bin dir begin with
#!/usr/bin/env ruby
and when I make a new script which begins with that line RubyMine also recognizes it as being Ruby (even before I open it). I did notice that when I had a file without this line and then added it I had to quit and restart RubyMine for it to take effect.
Just open the file in RubyMine. When I open a file that RubyMine doesn't recognize, it asks me what type it is and remembers what I tell it.
Register the file manually:
- Go to Preferences -> IDE Settings -> File Types
- Under File Types, select "Ruby files"
- Under Registered Patterns, add a new pattern that matches
gem_name
It would be painful to have to do this for a lot of files, but it might be useful in some cases.
I'm surprised that method 2 didn't work for you already. Maybe you told RubyMine that the file was a text file. Check the Text file type in the File types preferences to be sure your file isn't registered as text.
回答2:
Right click on the filename in the project view.
Select "Associate with File Type..."
Select "Ruby"
来源:https://stackoverflow.com/questions/24547163/how-do-i-tell-rubymine-the-file-type-when-the-file-has-no-extension