atom / language-ruby-on-rails

Ruby on Rails package for Atom
Other
48 stars 41 forks source link

All files being opened with Ruby syntax instead of Rails #34

Open xeron opened 9 years ago

xeron commented 9 years ago

Atom: 0.208.0 OSX: 10.10.3

I've tried controllers, models, helpers and migrations. Always Ruby. Same issue with atom --safe.

xeron commented 9 years ago

Sometimes it works as expected, sometimes it doesn't. Looks like some sort of race condition here?

jazzpi commented 9 years ago

Yes, there's a race condition since both the HTML (Rails) and HTML (Ruby - ERB) grammars match files ending in .html.erb. Related: #3 and atom/atom#2734

There has been a package to work around this by allowing you to match file types to grammars (file-types), but it broke some time ago. Working off the workaround at execjosh/atom-file-types#17, I've put the following in my init.coffee that fixed the issue:

atom.workspace.observeTextEditors (editor) ->
  path = editor.getPath()
  return unless path?

  fileTypes =
    '.html.erb': 'text.html.ruby'

  for extension of fileTypes when \
      path.toLowerCase().endsWith(extension.toLowerCase()) and
      (longestExtension ? "").length < extension.length
    longestExtension = extension

  return unless longestExtension?
  g = atom.grammars.grammarForScopeName fileTypes[longestExtension]
  return unless g?
  editor.setGrammar g

By adding to the fileTypes object, you can do more workaround for other file types.

xeron commented 9 years ago

In my case this also affect models, controllers, helpers and migrations. Reopening of projects helps sometimes (even w/o restart of Atom). But this is always random. And while project is opened it's always persistent, so all files being opened with Ruby or with Rails syntax, but never mix of both.

Steps to reproduce are like that:

  1. Open a project
  2. Open any model/controller/helper/migration
  3. If syntax is Rails then close a project and repeat from step 1
  4. You'll get Ruby syntax after several tries
jazzpi commented 9 years ago

Oh, yes, now I'm noticing that. You can just add '.rb': 'source.ruby.rails' to the fileTypes from my workaround to fix that too.

xeron commented 9 years ago

May be related to https://github.com/atom/first-mate/issues/17

alepore commented 9 years ago

a config like this should work on atom 1.0.8+:

"*":
  core:
    customFileTypes:
      "text.html.ruby": [
        "erb"
      ]
jamieorc commented 7 years ago

I'm experiencing this with Atom 1.12.2: controller files are being recognized as Ruby rather than Rails files.

philippneugebauer commented 7 years ago

I encounter the same problem as @jamieorc on MacOS

srabuini commented 7 years ago

Same here with Atom MacOS 1.19.2 (I think that it never worked properly since the beta versions, though). I recently discovered that disabling the language-ruby package and enabling it again, it starts working properly.

jamieorc commented 6 years ago

Still encountering this issue.

kimyu92 commented 5 years ago

Atom: 1.32 Mac OS: 10.14 only had encountered issue with this particular version recently, and have to work around with what ~@alepore proposed~ @mcelicalderon proposed below 👇 which is editting config.cson

"*":
  core:
    customFileTypes:
      "source.ruby.rails": [
        "rb"
      ]
mcelicalderon commented 5 years ago

This is what fixed it for me, slightly different to @alepore 's solution. On your ~/.atom./config.cson file, add:

"*":
  core:
    customFileTypes:
      "source.ruby.rails": [
        "rb"
      ]
zhisme commented 5 years ago

This is what fixed it for me, slightly different to @alepore 's solution. On your ~/.atom./config.cson file, add:

"*":
  core:
    customFileTypes:
      "source.ruby.rails": [
        "rb"
      ]

This solution is a temp fix. For example it will not handle syntax highlight in Gemfile for rails But works fine for *.rb files

kimyu92 commented 5 years ago

@zhisme to workaround with Gemfile as well as rake file type, just add more file types into the config

"*":
  core:
    customFileTypes:
      "source.ruby.rails": [
        "rb"
        "rake"
        "Gemfile"
      ]
zeiv commented 5 years ago

I disagree that this needs reproduction, seems like people continue to have problems with this, and on my part I have never across a variety of operating systems and Atom version been able to have my Rails projects ruby files highlight with this ruby-on-rails format instead of the default Ruby one. Surely this can be fixed instead of having to add a special config to every rails project?

xeron commented 5 years ago

When I reported this bug it was random between Ruby and ROR syntax. With the current version it's always Ruby I think. I don't use Atom anymore tho and this bug is one of the reasons.

LucasKuhn commented 4 years ago

Still not fixed :(