当文件没有扩展名时,如何告诉 RubyMine 文件类型? [英] How do I tell RubyMine the file type when the file has no extension?

查看:66
本文介绍了当文件没有扩展名时,如何告诉 RubyMine 文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来应该很容易.

我正在创建一个 CLI 命令 gem,所以命令位于 bin/gem_name 中,它没有 .rb 扩展名.当我尝试在 RubyMine 中编辑该文件时,它没有为其提供语言模式(抱歉,不知道正确的术语)来使 RubyMine 中的语法突出显示和其他功能发挥作用.

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.

我如何告诉 RubyMine 这实际上是一个 Ruby 文件?

How can I tell RubyMine that this is, in fact, a Ruby file?

推荐答案

有几种方法可以告诉 RubyMine 文件属于特定类型:

There are several ways to tell RubyMine that a file is of a particular type:

  1. 以 RubyMine 识别为 Ruby 的 hashbang 行开始命令文件.我不知道它到底能识别什么,但是所有 gems 放入我的 bin 目录的脚本都以

  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

当我创建一个以该行开头的新脚本时,RubyMine 也会将其识别为 Ruby(甚至在我打开它之前).我确实注意到,当我有一个没有这一行的文件然后添加它时,我必须退出并重新启动 RubyMine 才能生效.

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.

只需在 RubyMine 中打开文件即可.当我打开一个 RubyMine 无法识别的文件时,它会问我它是什么类型并记住我告诉它的内容.

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.

手动注册文件:

  • 转到首选项 -> IDE 设置 -> 文件类型
  • 在文件类型下,选择Ruby 文件"
  • 在注册模式下,添加一个与 gem_name
  • 匹配的新模式
  • 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.

我很惊讶方法 2 对您不起作用.也许您告诉 RubyMine 该文件是一个文本文件.检查文件类型首选项中的文本文件类型,以确保您的文件未注册为文本.

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.

这篇关于当文件没有扩展名时,如何告诉 RubyMine 文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆