-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Highlight Ruby method definitions without arguments #1523
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8173ec6
Highlight Ruby method definitions without arguments
cbothner 2d2d9f1
Add a test for method definition
cbothner d4695ca
Fix highlighting of Ruby static methods
cbothner eee0b86
Change Crystal attribute test
cbothner 2946ba0
Change Crystal keyword test input
cbothner 1c7df91
Change ERB and HAML tests to reflect Ruby changes in 8173ec6
cbothner 5789c7d
Remove trailing comma
cbothner 5f60430
Fix multiline method definitions; don't match methods ending with "def"
cbothner 782ef55
Highlight `self` as keyword, `.` as punct. in class method definitions
cbothner 79efe51
Wrap the whole definition of a class method to give users the choice
cbothner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
class Circle | ||
def self.of_diameter(diameter) | ||
new diameter / 2 | ||
end | ||
|
||
def initialize(radius) | ||
@radius = radius | ||
end | ||
|
||
def circumference | ||
Math::PI * radius ** 2 | ||
end | ||
|
||
# Seattle style | ||
def grow_by factor: | ||
@radius = @radius * factor | ||
end | ||
end | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "class"], | ||
["class-name", ["Circle"]], | ||
["keyword", "def"], | ||
["function", "self.of_diameter"], | ||
["punctuation", "("], | ||
"diameter", | ||
["punctuation", ")"], | ||
["keyword", "new"], | ||
["class-name", ["diameter"]], | ||
["operator", "/"], | ||
["number", "2"], | ||
["keyword", "end"], | ||
["keyword", "def"], | ||
["function", "initialize"], | ||
["punctuation", "("], | ||
"radius", | ||
["punctuation", ")"], | ||
["variable", "@radius"], | ||
["operator", "="], | ||
" radius\n ", | ||
["keyword", "end"], | ||
["keyword", "def"], | ||
["function", "circumference"], | ||
["constant", "Math"], | ||
["punctuation", ":"], | ||
["punctuation", ":"], | ||
["constant", "PI"], | ||
["operator", "*"], | ||
" radius ", | ||
["operator", "*"], | ||
["operator", "*"], | ||
["number", "2"], | ||
["keyword", "end"], | ||
["comment", "# Seattle style"], | ||
["keyword", "def"], | ||
["function", "grow_by"], | ||
" factor", | ||
["punctuation", ":"], | ||
["variable", "@radius"], | ||
["operator", "="], | ||
["variable", "@radius"], | ||
["operator", "*"], | ||
" factor\n ", | ||
["keyword", "end"], | ||
["keyword", "end"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks that method definitions are highlighted correctly |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a little fun with a Ruby REPL and found that this pattern will also happily match:
But at the same time, it doesn't match
Changing the lookbehind group to
(\bdef\s+)
ought to solve these cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. (Although I’ve never seen someone put a newline between
def
and the method name)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, me either, but the compiler can handle it, so there is probably someone out there using it.