atom / language-typescript

TypeScript language package for Atom
Other
21 stars 33 forks source link

Grammar generator mishandles function arguments that span multiple lines #21

Open ryanolsonx opened 6 years ago

ryanolsonx commented 6 years ago

Prerequisites

Description

If you create a typescript function with arguments on separate lines, they don't get the proper scopes associated with them and end up not getting highlighted correctly by the syntax theme.

Here's an example function that is highlighted correctly (because all of the args on the same line): image

Here's an example of that same function but highlighted incorrectly (because of the args on different lines): image

In looking at scopes, I see that the html created for the one-liner function declaration's first argument looks like:

<span class="syntax--variable syntax--parameter syntax--ts">arg1</span>
<span class="syntax--meta syntax--type syntax--annotation syntax--ts">
  <span class="syntax--keyword syntax--operator syntax--type syntax--annotation syntax--ts">:</span> 
  <span class="syntax--support syntax--type syntax--primitive syntax--ts">number</span>
</span>

and the first argument for the multi-line arguments looks like:

<span class="syntax--meta syntax--var syntax--expr syntax--ts">
  <span class="leading-whitespace">  </span>
  <span class="syntax--variable syntax--other syntax--readwrite syntax--ts">arg1</span>: 
  <span class="syntax--variable syntax--other syntax--readwrite syntax--ts">number</span>
  <span class="syntax--punctuation syntax--separator syntax--comma syntax--ts">,</span>
</span>

Which is clearly wrong.

Steps to Reproduce

  1. Create new typescript file with a function declaration, where the arguments are on separate lines (as seen above).
  2. Check if types are highlighted (or if you want to be thorough, compare scopes with a single line function).

Expected behavior: Arguments for a function that spans multiple lines should get the right scopes

Actual behavior: Arguments for a function that spans multiple lines are getting variable scopes instead of parameter scopes.

Reproduces how often: 💯

Versions

Atom: 1.27.1 Apm: 1.19.0 OS: Windows 10