elixir-editors / language-elixir

Elixir language support for the Atom editor.
Other
181 stars 40 forks source link

More interpolation support #24

Closed dalexj closed 8 years ago

dalexj commented 8 years ago

Requested Feature

I'd like to see the parsed markup of interpolated strings with elixir match/closely match the markup that the built in atom ruby language generates.

Reasoning

This will allow more theme/syntax highlighting packages to work more completely with elixir.

Other information

I have not spent the time to look into how language/grammar parsing works with atom, so I'm unsure how much work this will take, but I'm trying/will try to provide as much info as I can.

Here is an example of 2 strings, 1 in ruby - 1 in elixir, and the HTML generated by them to give a sense of differences

"a ruby string with #{code} inside"
"an elixir string with #{code} inside"
<span class="string quoted double interpolated ruby">
  <span class="punctuation definition string begin ruby">"</span>
  a ruby string with
  <span class="meta embedded line ruby">
    <span class="punctuation section embedded begin ruby">
      <span class="source ruby">#{</span>
    </span>
    <span class="source ruby">code</span>
    <span class="punctuation section embedded end ruby">
      <span class="source ruby">}</span>
    </span>
  </span>
  inside
  <span class="punctuation definition string end ruby">"</span>
</span>

<span class="string quoted double elixir">
  <span class="punctuation definition string begin elixir">"</span>
  an elixir string with
  <span class="source elixir embedded source">
    <span class="punctuation section embedded elixir">#{</span>
      code
    <span class="punctuation section embedded elixir">}</span>
  </span>
  inside
  <span class="punctuation definition string end elixir">"</span>
</span>

I think at the very least, I'd love to see the .interpolated class be added on any .double.quoted.string and to wrap inner code with classes .source.elixir so that themes will pick this up.

keathley commented 8 years ago

@dalexj is this still an issue that you're having?

dalexj commented 8 years ago

just updated to 0.7.2

it seems to be highlighting correctly inside interpolated strings, much appreciated

I'd still love a light wrapper around the contents between #{ and } to be a span.source.elixir similar to the ruby highlighting, so variable names, etc (anything not picked up by any deeper highlighting) could be highlighted differently than the surrounding string

keathley commented 8 years ago

There aren't any visual differences between the elixir implementation and the ruby implementation that I'm aware of. Is there is a specific use case that you want to support?

dalexj commented 8 years ago

yes it is most likely a more specific use case. my current theme gives me different highlighting inside string so its easier for me to see interpolated values:

I doubt adding the wrapper would break it for anyone else, because this is the way the ruby highlighting uses it

cjbottaro commented 8 years ago

Can we also get # to expand to #{} with the cursor placed in the middle when inside a string? Like how Ruby string interpolation works in Atom? :)

keathley commented 8 years ago

@cjbottaro can you open a separate issue for that?

keathley commented 8 years ago

Just to update I'm looking at this along with #38. The interpolation code is what was generated from the TM bundle and I'm having to do quite a bit of cleanup.

keathley commented 8 years ago

@cjbottaro Expanding # to #{} is actually handled in the bracket matcher package: https://github.com/atom/bracket-matcher.

It'll have to be fixed there

dalexj commented 8 years ago

@cjbottaro I've actually hacked into bracket matcher locally to expand this as needed, but never went through and made a full PR to the package. If you add the selector for elixir strings into the segments array lib/bracket-matcher.coffee around like 185, it should work. I think the selector you want is 'string.quoted.double.elixir' (not 100% sure since my elixir lang is hacked on that selector too)

keathley commented 8 years ago

@dalexj if you want to submit that upstream to bracket matcher that would be great. Otherwise I'll submit a PR once I'm done with the interpolated string changes. Also feel free to submit a PR with any improvements you've made and we can discuss them.

keathley commented 8 years ago

I've submitted a fix to bracket matcher: atom/bracket-matcher#221.

I'm going to close this for now because at this point there's no visual difference between the Ruby version and the elixir version. I have noticed a few themes that update ruby variables in strings by specifically targeting ruby. The solarized dark themes do this for instance. I'd check with the specific theme that you're using. If there is a specific problem that you're seeing then feel free to re-open the issue.