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

Commit

Permalink
class properties
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonrcarter committed Aug 2, 2021
1 parent 7b2d5bd commit d283f7a
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 8 deletions.
6 changes: 1 addition & 5 deletions grammars/tree-sitter-php.cson
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ scopes:
'"]"': 'punctuation.section.array.end.php'
'";"': 'punctuation.terminator.expression.php'

# FIXME I think this selector is too broad
# '"static"': 'storage.modifier'
'"public"': 'storage.modifier.php'
'"private"': 'storage.modifier.php'
'"protected"': 'storage.modifier.php'
'visibility_modifier, static_modifier': 'storage.modifier.php'
'"global"': 'storage.modifier'
'"const"': 'storage.modifier'
'"abstract"': 'storage.modifier.abstract.php'
Expand Down
183 changes: 180 additions & 3 deletions spec/tree-sitter-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1786,9 +1786,186 @@ ${caret}
// SKIP TS-php handles this
// it('tokenizes classes declared immediately after another class ends', () => {})

describe('properties', () => {
it('tokenizes types', () => {
// up next...
describe("properties", () => {
it("tokenizes types", () => {
editor.setContent(`
class A {
public int $a = 1;
}
`);

// public
expect(editor).toHaveScopesAtPosition(
[2, 2],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"storage.modifier.php"
]
);
// FIXME not supported by tree-sitter-php until > 0.19.0
// int
// expect(editor).toHaveScopesAtPosition(
// [2, 9],
// [
// "source.php",
// "meta.class.php",
// "meta.class.body.php",
// "keyword.other.type.php"
// ]
// );
// $
expect(editor).toHaveScopesAtPosition(
[2, 13],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"variable.other.php",
"punctuation.definition.variable.php"
]
);
// a
expect(editor).toHaveScopesAtPosition(
[2, 14],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"variable.other.php"
]
);
});

// FIXME not supported by tree-sitter-php until > 0.19.0
// it("tokenizes nullable types", () => {})

it("tokenizes 2 modifiers correctly", () => {
editor.setContent(`
class Foo {
public static $bar = 'baz';
}
`);

// public
expect(editor).toHaveScopesAtPosition(
[2, 2],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"storage.modifier.php"
]
);
// static
expect(editor).toHaveScopesAtPosition(
[2, 9],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"storage.modifier.php"
]
);
// $
expect(editor).toHaveScopesAtPosition(
[2, 16],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"variable.other.php",
"punctuation.definition.variable.php"
]
);
// bar
expect(editor).toHaveScopesAtPosition(
[2, 17],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"variable.other.php"
]
);
});

// FIXME typed properties not supported by tree-sitter-php until > 0.19.0
// it('tokenizes namespaces', () => {});

it("tokenizes multiple properties", () => {
// FIXME the TM spec includes property types which aren't yet
// supported by our version of TS-php. Update this spec to match after
// TS-php has been updated w/ support for prop types.
editor.setContent(`
class A {
private static $c1, $c2;
}
`);

// private
expect(editor).toHaveScopesAtPosition(
[2, 2],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"storage.modifier.php"
]
);
// static
expect(editor).toHaveScopesAtPosition(
[2, 10],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"storage.modifier.php"
]
);
// $
expect(editor).toHaveScopesAtPosition(
[2, 17],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"variable.other.php",
"punctuation.definition.variable.php"
]
);
// c1
expect(editor).toHaveScopesAtPosition(
[2, 18],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"variable.other.php"
]
);
// $
expect(editor).toHaveScopesAtPosition(
[2, 22],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"variable.other.php",
"punctuation.definition.variable.php"
]
);
// c2
expect(editor).toHaveScopesAtPosition(
[2, 23],
[
"source.php",
"meta.class.php",
"meta.class.body.php",
"variable.other.php"
]
);
});
});

Expand Down

0 comments on commit d283f7a

Please sign in to comment.