Skip to content

Commit

Permalink
Issue 83: Prevent "#{}" expansion in literal heredocs
Browse files Browse the repository at this point in the history
The atom-brackets package is configured to expand "#" into "#{$1}" in `comment.documentation.heredoc.elixir` contexts. To avoid this and close elixir-editors#83, this changes literal heredoc contexts (`~S`) to have a more specific tag, `comment.documentation.heredoc.literal.elixir`.

Tested by `apm link`ing the modified `language-elixir` locally and confirmed that "#" no longer expanded in literal heredocs.  Also modified existing tests to expect the new name where appropriate.
  • Loading branch information
mshenfield committed Feb 18, 2018
1 parent 75d4187 commit 1dd9a3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions grammars/elixir.cson
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
'begin': '@(module|type)?doc ~S"""'
'comment': '@doc with heredocs is treated as documentation'
'end': '\\s*"""'
'name': 'comment.documentation.heredoc.elixir'
'name': 'comment.documentation.heredoc.literal.elixir'
'patterns': [
{
'include': '#escaped_char'
Expand All @@ -64,7 +64,7 @@
'begin': "@(module|type)?doc ~S'''"
'comment': '@doc with heredocs is treated as documentation'
'end': "\\s*'''"
'name': 'comment.documentation.heredoc.elixir'
'name': 'comment.documentation.heredoc.literal.elixir'
'patterns': [
{
'include': '#escaped_char'
Expand Down
18 changes: 9 additions & 9 deletions spec/elixir-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,14 @@ describe "Elixir grammar", ->
expect(tokens[2]).toEqual value: '\n"""', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']

{tokens} = grammar.tokenizeLine('@doc ~S"""\nTest\n"""')
expect(tokens[0]).toEqual value: '@doc ~S"""', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']
expect(tokens[1]).toEqual value: '\nTest', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']
expect(tokens[2]).toEqual value: '\n"""', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']
expect(tokens[0]).toEqual value: '@doc ~S"""', scopes: ['source.elixir', 'comment.documentation.heredoc.literal.elixir']
expect(tokens[1]).toEqual value: '\nTest', scopes: ['source.elixir', 'comment.documentation.heredoc.literal.elixir']
expect(tokens[2]).toEqual value: '\n"""', scopes: ['source.elixir', 'comment.documentation.heredoc.literal.elixir']

{tokens} = grammar.tokenizeLine("@doc ~S'''\nTest\n'''")
expect(tokens[0]).toEqual value: "@doc ~S'''", scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']
expect(tokens[1]).toEqual value: '\nTest', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']
expect(tokens[2]).toEqual value: "\n'''", scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']
expect(tokens[0]).toEqual value: "@doc ~S'''", scopes: ['source.elixir', 'comment.documentation.heredoc.literal.elixir']
expect(tokens[1]).toEqual value: '\nTest', scopes: ['source.elixir', 'comment.documentation.heredoc.literal.elixir']
expect(tokens[2]).toEqual value: "\n'''", scopes: ['source.elixir', 'comment.documentation.heredoc.literal.elixir']

it "does not highlight other sigil heredocs as comments", ->
{tokens} = grammar.tokenizeLine("@doc '''\nTest\n'''")
Expand All @@ -650,19 +650,19 @@ describe "Elixir grammar", ->
expect(tokens[0]).not.toEqual value: '@doc ~r"""', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']

{tokens} = grammar.tokenizeLine('@doc ~R"""\nTest\n"""')
expect(tokens[0]).not.toEqual value: '@doc ~R"""', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']
expect(tokens[0]).not.toEqual value: '@doc ~R"""', scopes: ['source.elixir', 'comment.documentation.heredoc.literal.elixir']

{tokens} = grammar.tokenizeLine('@doc ~c"""\nTest\n"""')
expect(tokens[0]).not.toEqual value: '@doc ~c"""', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']

{tokens} = grammar.tokenizeLine('@doc ~C"""\nTest\n"""')
expect(tokens[0]).not.toEqual value: '@doc ~C"""', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']
expect(tokens[0]).not.toEqual value: '@doc ~C"""', scopes: ['source.elixir', 'comment.documentation.heredoc.literal.elixir']

{tokens} = grammar.tokenizeLine('@doc ~w"""\nTest\n"""')
expect(tokens[0]).not.toEqual value: '@doc ~w"""', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']

{tokens} = grammar.tokenizeLine('@doc ~W"""\nTest\n"""')
expect(tokens[0]).not.toEqual value: '@doc ~W"""', scopes: ['source.elixir', 'comment.documentation.heredoc.elixir']
expect(tokens[0]).not.toEqual value: '@doc ~W"""', scopes: ['source.elixir', 'comment.documentation.heredoc.literal.elixir']

describe "functions", ->
it "tokenizes single line functions without parameters", ->
Expand Down

0 comments on commit 1dd9a3b

Please sign in to comment.