#316 open
Aaron Aberg

Redcar doesn't set the proper document type for Rails models and controllers

Reported by Aaron Aberg | September 17th, 2010 @ 08:54 AM | in 0.14

Anytime I want to edit a model or a controller, Redcar detects that its a Ruby file. This is good, but it would be even better if it could figure out that controllers and models better fit in the "Ruby on Rails" document category.

Comments and changes to this ticket

  • Kostas Liakakis

    Kostas Liakakis February 15th, 2012 @ 12:10 PM

    Any update to this please?
    This is still the case and is quite disappointing as it also affects build-in snippets.

    Isn't there any dot-file configuration option to set in a directory and force a specific language setting?

    Thanks,

    -Kostas

  • Steven! Ragnarök

    Steven! Ragnarök May 24th, 2012 @ 05:55 PM

    Can Aaron or Kostas give me a description of both the current behavior and the expected behavior? I do not use snippets so I do not know how to test this but I am going to take a stab at fixing it.

    If I understand the problem.

    What happens:

    When working on a Rails project and opening a model.
    Only Ruby snippets are available by default.

    what should happen:

    When working on a Rails project and opening a model.
    Ruby and Ruby on Rails Model snippets should both be available by default.

    And ditto for Controllers. If you can show me what the second step means, i.e. how to invoke the default snippet list, I'll try to fix it. I've done some plugin work with the Vim plugins for Fancy, Ruby, and Io so I have some amount of experience.

    Furthermore, it appears as though this behavior is specified in the Ruby on Rails and Ruby tmbundles, could this bug or contention be in either of those and not in Redcar, can someone confirm that these tmbundles work from TextMate.

  • Kostas Liakakis

    Kostas Liakakis May 25th, 2012 @ 10:52 AM

    Hello,

    Thanks for taking the time to look into this.

    As I look at it, Rails snippets not working is really a side-effect. The main problem is the language is set as Ruby, rather than Ruby On Rails. The setting is available, sometime ago I took a dive into it, but came out none-the-wiser. All I could make out (or thought I did) was that both settings used the .rb extention criteria and somehow Ruby setting got precedence.

    One can change the language setting by hand, but this has to be done again and again everytime a source file is opened in the editor. So to sum up:

    What happens:
    - When you opening Rails project's .rb files, they get a language setting of Ruby.

    What should happen:
    - When you opening Rails project's .rb files, they get a language setting of RubyOnRails. At least if the file resides in the "controller" or "models" subdirectories.

    I really have no idea what is the case in Textmate. Ruby setting works good enough, so this not a showstopper or anything alike. It is just that the RoR setting provides for better highlighting of Rails constructs, more/different snippets and other things I might not be aware of.

    Thanks again for your interest.

    -K.

  • delisa

    delisa May 25th, 2012 @ 08:54 PM

    • State changed from “new” to “open”
    • Tag changed from tab info, snippet to tab info, grammar, snippet

    Would it make sense to have a per-project override setting for which grammar to use with a filename regex? Something like (in YAML):

    file_grammars:
      Ruby On Rails: /\.rb$/
      RSpec: /_spec\.rb$/
    
  • Kostas Liakakis

    Kostas Liakakis May 25th, 2012 @ 09:44 PM

    Of course it would!!

    It would also allow one to cover all those corner cases where the global grammar setting got things wrong.

  • delisa

    delisa May 25th, 2012 @ 10:11 PM

    • Assigned user changed from “Daniel Lucraft” to “delisa”
    • Milestone set to 0.14
    • Milestone order changed from “197450” to “0”

    Sounds good then. :) It's on my list of things to do over this weekend; it should be simple to implement.

  • Steven! Ragnarök

    Steven! Ragnarök May 26th, 2012 @ 01:05 AM

    Delisa, how do I tell what the current language is? One of the things I noticed is that the Ruby on Rails tmbundle recognizes models by their inheritance of ActiveRecord::Base and not by presence in app/models. I'm not really clear on how to change to (or have multiple) sublanguages i.e. Ruby+Rails Model, Ruby+Rails Controller Ruby+RSpec Test

    Could you elaborate on how that stuff is done from a developer perspective? Overrides are fine, but it would be nice if things worked as expected out of the box.

  • delisa

    delisa May 27th, 2012 @ 01:25 PM

    Redcar uses the settings pulled from TextMate language definitions to set the grammar of a file. First it checks by the first line of a file, then by the extension if no first line matches are found, as shown here:
    https://github.com/redcar/redcar/blob/master/plugins/edit_view_swt/...

    In the Ruby bundle specifically, it checks the first line for a regex indicating a ruby executable (<firstLineMatch>) and then for a whole host of file extensions (in the <fileTypes> block). The Ruby language file can be viewed here:
    https://github.com/redcar/redcar-bundles/blob/master/Bundles/Ruby.t...

    The Rails bundle on the other hand, only checks for the rb, rxml, and builder extensions:
    https://github.com/redcar/redcar-bundles/blob/master/Bundles/Ruby%2...

    Per our conversation in IRC yesterday, it looks like our options are:

    1. Add an override for per-file settings in the .redcar project directory
    2. Extend TextMate language definitions with a new property (like relativePath) to first try to determine file grammar by relative path in a project, e.g. assume Ruby on Rails instead of Ruby when the relative path of a file is something like app/controllers/*.rb
    3. Add prioritization to the order in which language files are checked to match, and assume a file is Ruby on Rails-type before Ruby
    4. Completely redo how this is handled in a Redcar-native way?
  • Kostas Liakakis

    Kostas Liakakis May 31st, 2012 @ 07:24 AM

    I'd humbly suggest if the .redcar override can be coded fast without too much hassle, you should add it in. Then at your leisure choose one of the other options to implement as well in the long term.

    I believe the override will allow one to deal with the particular problem right now but it will also provide more flexibility in future situations.

    -K.

  • Kostas Liakakis

    Kostas Liakakis June 21st, 2012 @ 06:05 PM

    Hello,

    After all this talk I have to admit that this might not have been a Redcar issue after all. At least not totally. I recently upgraded from Fedora 16 to 17 and, to my suprise, Redcar now gets language settings correctly!

    So this might be attributed to some gtksourceview quirk or whatever else system-dependent Redcar depends on that got upgraded by the F16 to F17 switch. However, having some more control on the Redcar side, or even some evidence on how the decision is made so one can blame the correct party, would be nice to have. I'll gladly keep using the latest git version of Redcar and test whatever is added.

    Nevertheless, with an out-of-the-box Fedora 17 installation, Redcar behaves as it should regarding automatic source language setting.

    Thanks to whoever spent time on this issue.

    -Kostas.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

A programmer's text editor for Gnome.

Pages