How do I tell RubyMine the file type when the file has no extension?

人走茶凉 提交于 2019-12-23 12:29:12

问题


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:

  1. 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.

  2. 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.

  3. 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:


  1. Right click on the filename in the project view.

  2. Select "Associate with File Type..."

  3. Select "Ruby"



来源:https://stackoverflow.com/questions/24547163/how-do-i-tell-rubymine-the-file-type-when-the-file-has-no-extension

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!