Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to folder %w notation created Ruby arrays #945

Closed
5 tasks done
Roko131 opened this issue Mar 6, 2024 · 4 comments
Closed
5 tasks done

Not able to folder %w notation created Ruby arrays #945

Roko131 opened this issue Mar 6, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@Roko131
Copy link

Roko131 commented Mar 6, 2024

Thanks in advance for your bug report!

  • Have you reproduced issue in safe mode?
  • Have you used the debugging guide to try to resolve the issue?
  • Have you checked our FAQs to make sure your question isn't answered there?
  • Have you checked to make sure your issue does not already exist?
  • Have you checked you are on the latest release of Pulsar?

What happened?

Pulsar not recognizing %w notations arrays as array, therefore not being able to folder them.
(%w notation is a different way in ruby to create arrays)

Atom v 1.60 does recognizing %w notations so in Atom I'm able to folder it, this bug only happens in Pulsar

Expanded:
image
Foldered:
image

Pulsar version

1.114.0

Which OS does this happen on?

🐧 Debian based (Linux Mint, Ubuntu, etc.)

OS details

Pop Os 22.04

Which CPU architecture are you running this on?

x86_64/AMD64

What steps are needed to reproduce this?

  1. Open a new Ruby file, i.e. myfile.rb
  2. Create 2 arrays, one using regular syntax, second using %w notation syntax:
arr1 = [
  'str1',
  'str2',
  'str3',
]
arr2 = %w[
  str1
  str2
  str3
]
  1. Notice you can only folder arr1, but not arr2

Additional Information:

There are other notations besides %w,
Same bug apply for any of them (foldable in Atom, not in Pulsar):

  • %i Array of Symbols
  • %q String
  • %r Regular Expression
  • %s Symbol
  • %w Array of Strings
  • %x Backtick (capture subshell result)
@Roko131 Roko131 added the bug Something isn't working label Mar 6, 2024
@savetheclocktower savetheclocktower self-assigned this Mar 6, 2024
@savetheclocktower
Copy link
Contributor

This should be a quick fix; it'll be ready for 1.115 in mid-March. Thanks for the report!

@savetheclocktower
Copy link
Contributor

The commit above should fix this. It'll land right before 1.115 is released. Thanks again!

@Roko131
Copy link
Author

Roko131 commented Mar 10, 2024

Thank you, I took a look at the commit. just to make sure we get all the cases:
From the docs (bottom page, last row):

  • If you are using “(”, “[”, “{”, “<” you must close it with “)”, “]”, “}”, “>” respectively.
  • You may use most other non-alphanumeric characters for percent string delimiters such as “%”, “|”, “^”, etc.

So the way I see it:

it's for either:

  • w
  • W
  • i
  • I

And for each of them, to open we can use parentheses:

  • ()
  • []
  • {}
  • <>

And lastly most other non-alphanumeric characters... so just to name a few (all work in atom v 1.60):

- '
- "
- ^
- %
- |
- $
- <space> hmm probably only make sense to use in a single line
- #
- @
- *
- Etc...................
# some examples using 'w' but they would also work using 'W' 'I' or 'i'
ar = %w[
  st1
  st2
]

ar = %w{
  st1
  st2
}

ar = %w'
  st1
  st2
'
ar = %w"
  st1
  st2
"

ar = %w%
  st1
  st2
%

ar = %w@
  st1
  st2
@

ar = %w!
  st1
  st2
!

ar = %w!
  st1
  st2
!

ar = %w*
  st1
  st2
*

Oh and one last thing, not sure it it's a typo or not:
Comment says ; Handle %w[ and %i[. but code below has "%w(" "%i("
It could be that I just don't understand how it works though
image

@savetheclocktower
Copy link
Contributor

Thank you, I took a look at the commit. just to make sure we get all the cases:

Yes, these will be covered. Of the special percent notations:

  • only %w and %i make sense as folding candidates, since the others are used to define strings
  • Tree-sitter will mark them the same way no matter which characters are used as delimiters (allowing us to target the node types string_array and symbol_array for the folds

Of the changes to highlights.scm you see in that commit:

  • The tree-sitter-ruby parser incorrectly marks the opening delimiter of a %w as %w(, no matter which character is used as a delimiter; this also applies to the closing ). It also marks the opening delimiter of a %W as %w(, ignoring the difference in case. The %i syntax has the same issue. This isn't a huge problem; all it affects is how we target this node in a Tree-sitter query. Technically, it's not good Tree-sitter practice, but it does make our lives easier that we don't have to write a separate query for every single possible delimiter permutation.
  • Because of the above behavior, even something like %W{ will still get targeted properly.
  • We usually mark delimiters with scope names that describe the delimiter itself, hence the scope names with bracket.round and bracket.square. But because the delimiters can be so many different things, we also define a fallback scope name for punctuation that omits any description of the characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants