diff --git a/grammars/tree-sitter-php.cson b/grammars/tree-sitter-php.cson index fedb99e..86547c3 100644 --- a/grammars/tree-sitter-php.cson +++ b/grammars/tree-sitter-php.cson @@ -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' diff --git a/spec/tree-sitter-spec.js b/spec/tree-sitter-spec.js index 1073965..65eb8d6 100644 --- a/spec/tree-sitter-spec.js +++ b/spec/tree-sitter-spec.js @@ -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" + ] + ); }); });