Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

[tree-sitter] add variable identifier support in assignments expressions #276

Merged
merged 2 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions grammars/tree-sitter-ruby.cson
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ scopes:
'")"': 'punctuation.definition.parameters'

'method > identifier': 'entity.name.function'
'assignment > identifier': 'variable'

'singleton_method > identifier:nth-child(3)': 'entity.name.function'
'setter > identifier': 'entity.name.function'
'call > identifier:nth-child(2)': 'entity.name.function'
Expand Down
22 changes: 22 additions & 0 deletions spec/tree-sitter-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,26 @@ describe('Tree-sitter Ruby grammar', () => {
'.source.ruby .keyword.control'
)
})

it('tokenizes variable in assignment expressions', async () => {
const editor = await atom.workspace.open('foo.rb')
editor.setText(dedent`
a = 10
`)

expect(editor.scopeDescriptorForBufferPosition([0, 0]).toString()).toBe(
'.source.ruby .variable'
)
})

it('does not tokenizes method call in assignment expressions', async () => {
const editor = await atom.workspace.open('foo.rb')
editor.setText(dedent`
foo() = 10
`)

expect(editor.scopeDescriptorForBufferPosition([0, 0]).toString()).not.toBe(
'.source.ruby .variable'
)
})
})