atom / language-ruby

Ruby package for Atom
Other
101 stars 144 forks source link

Support for non-HTML `erb` files #180

Open walles opened 7 years ago

walles commented 7 years ago

Hi!

We have lots of non-HTML erb files in our Puppet repo.

If you try editing one of those, Atom assumes they are HTML files, and tries to apply HTML highlighting to them.

Primarily I'd like the erb mode to be able to highlight the non-ruby parts of the file using whatever mode is best.

Secondarily, if that's not possible, I'd like the erb mode to assume all non-ruby parts of the file are just plain text.

walles commented 7 years ago

Here's what a yaml file looks like with erb highlighting: mis-highlighted

Here's what it should have looked like, but if I tell Atom it's YAML I don't get any erb highlighting: better-highlighting

winstliu commented 7 years ago

YAML should already support ERB? https://github.com/atom/language-yaml/blob/master/grammars/yaml.cson#L17

walles commented 7 years ago

Opened https://github.com/atom/language-yaml/pull/57 for YAML files.

But this is a generic problem; here's a Java .properties file for example, in our repo there are lots of others like sh, xml, json, ini, ...

Here's what language-ruby thinks it should look like: skarmavbild 2016-12-08 kl 08 51 35

And here's what I think it should look like: skarmavbild 2016-12-08 kl 08 51 55

winstliu commented 7 years ago

How common is it for plain .erb files to be HTML Ruby?

walles commented 7 years ago

I have never seen one, but who knows?

The only .erb files I work with are the ones in our Puppet repo. Stats for only-.erb files in our repo as classified by file are:

$ find . -name \*.erb|egrep '^[.][^.]*[.][^.]*$'|xargs file|cut -c90-|sort|uniq -c|sort -gr
 258 ASCII text
  40 ASCII English text
  34 Bourne-Again shell script text executable
  10 a python script text executable
   7 a /usr/bin/perl -w script text executable
   7 PGP public key block
   5 POSIX shell script text executable
   5 ASCII C++ program text
   3 ASCII text, with very long lines
   3 ASCII text, with no line terminators
   2 a bash script text executable
   2 XML  document text
   2 ASCII English text, with very long lines
   1 very short file (no magic)
   1 a /usr/bin/ruby script text executable
   1 a /usr/bin/python script text executable
   1 UTF-8 Unicode text
   1 PHP script text
   1 ASCII C++ program text, with very long lines
$

I realize file's classification may not be awesome, but it gives a hint anyway.

I sampled some of the ASCII-files at random and found JSON, Apache configs, YAML, shell, and some don't knows.

tozz commented 7 years ago

This was a terrible change, broke things that had been working for years (only got the update recently due to Atom upgrade issues). Should changes like this just be up to one person modifying the behavior of an entire language? And to answer the question asked before, I have hundreds of html .erb files... Then again, I've worked at Spotify so I'm not surprised about the behaviour.

It's an "easy" fix to override this, but it's just as easy to make .erb not being parsed as HTML in the first place (without changing it for everyone who is using Atom).

walles commented 7 years ago

Why can't you just name your files .rhtml or .html.erb?

Den lör 14 jan 2017 09:03Erik Johansson notifications@github.com skrev:

This was a terrible change, broke things that had been working for years. Should changes like this just be up to one person modifying the behavior of an entire language? And to answer the question asked before, I have hundreds of html .erb files... Then again, I've worked at Spotify so I'm not surprised about the behaviour.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/atom/language-ruby/issues/180#issuecomment-272609320, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJp-agpcVBbl1f9nNl7ww2vTVyszFNuks5rSIFAgaJpZM4LGjuc .

tozz commented 7 years ago

It has been working fine in every editor and IDE (Atom, RubyMine, Sublime) for the last 10 years or so, Atom now being the only one not assuming HTML. The scope is text.html.erb, and I would argue .erb is fine for that, if you need another scope it should be defined and override .erb. ruby.erb something similar.

This is an example of breaking convention for the sake of being right (in the wrong place no less).

andrewcrowly2 commented 7 years ago

Not sure the status of this, but erb templates is a huge part chef. The templates in our chef-repo are mostly rb.erb files.