-
Notifications
You must be signed in to change notification settings - Fork 26
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
Ruby improvements #16
Conversation
Also replaced some non-null assertion operators to prevent failures when they are, in fact, null.
I also replaced some non-null assertion operators since they were causing errors when they were actually able to be |
You've added a bunch of keywords like attr_reader that aren't actually keywords according to the Ruby language spec: https://docs.ruby-lang.org/en/2.2.0/keywords_rdoc.html The tree-sitter grammar doesn't recognize them as keywords either, try putting class Foo
protected
def foo
1
end
private
def bar
1
end
end into http://tree-sitter.github.io/tree-sitter/playground and you get
Can you help me understand how the tokens |
I merged this but I undid the method parameter highlighting because it makes them inconsistent with references to those parameters: c99765f Also I would still like your feedback on the above question, this part feels like a hack that should be done by tree-sitter:
|
Oh you're correct, interesting. Most of those are actually methods of I've always seen In this commit, Weirdly, it looks like they're only considered keywords by the CSS? I'm not really sure why it's done that way.
You can also use them with an argument, like class Example
def methodA
end
private # all following methods in this class are private, and are inaccessible to outside objects
def methodP
end
end class Example
def methodA
end
def methodP
end
private :methodP
end
As for the method parameter colorization being inconsistent, I'd disagree with that being a problem but I can definitely see your point. My argument there would be that "it's how everyone else does it", but that's not a very good argument :) Unfortunately it'd be quite difficult to consistently colorize those variables since tree-sitter doesn't distinguish between method parameters and any other variables when used in the method itself. |
Oh and you can add a random variable in the middle of the class, but it wouldn't actually do anything as far as I'm aware. class Example
def methodA
end
foo
def methodP
end
end |
So I discussed this with some other Rubyists because I couldn't really figure out why I felt like these should be highlighted as keywords even though they aren't. e.g. why should The two responses I think fit best with my opinion are:
These were specifically in regards to I'm not sure if this necessary fits with the philosophy of the extension, that'd be your call :) Admittedly, it's pretty arbitrary and just based on what existing highlighters do. |
It sounds like they should be keywords, if they are nested under a class. So private should be a keyword here: class Foo
private
end and here: class Foo
private :foo
end but not here: private = 1 |
This resolves some issues I pointed out in #12.
Ruby method parameters
Before
![Screen Shot 2019-05-26 at 4 46 09 PM](https://user-images.githubusercontent.com/2977353/58388005-ca482c80-7fd5-11e9-8204-82896c86e3bd.png)
After
![Screen Shot 2019-05-26 at 4 45 49 PM](https://user-images.githubusercontent.com/2977353/58388002-bc92a700-7fd5-11e9-9363-2259e8a5c8a6.png)
Ruby keywords
This doesn't quite catch everything because the method catchers are a bit too aggressive (e.g.
attr_reader :variable_name
should haveattr_reader
caught as a keyword but is not), will need to fix that later.Before
![Screen Shot 2019-05-26 at 4 46 50 PM](https://user-images.githubusercontent.com/2977353/58388013-eb108200-7fd5-11e9-82d1-a4986d4265b4.png)
After
![Screen Shot 2019-05-26 at 4 47 03 PM](https://user-images.githubusercontent.com/2977353/58388014-eba91880-7fd5-11e9-8fe0-9d41eb884e24.png)
Changed symbols from
constant.numeric
toconstant.language
Before
![Screen Shot 2019-05-26 at 4 49 01 PM](https://user-images.githubusercontent.com/2977353/58388035-3591fe80-7fd6-11e9-944f-6ec8bdd4d973.png)
After
![Screen Shot 2019-05-26 at 4 49 08 PM](https://user-images.githubusercontent.com/2977353/58388036-3591fe80-7fd6-11e9-832a-5676b1e0233c.png)