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

Commit d283f7a

Browse files
class properties
1 parent 7b2d5bd commit d283f7a

File tree

2 files changed

+181
-8
lines changed

2 files changed

+181
-8
lines changed

grammars/tree-sitter-php.cson

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,7 @@ scopes:
177177
'"]"': 'punctuation.section.array.end.php'
178178
'";"': 'punctuation.terminator.expression.php'
179179

180-
# FIXME I think this selector is too broad
181-
# '"static"': 'storage.modifier'
182-
'"public"': 'storage.modifier.php'
183-
'"private"': 'storage.modifier.php'
184-
'"protected"': 'storage.modifier.php'
180+
'visibility_modifier, static_modifier': 'storage.modifier.php'
185181
'"global"': 'storage.modifier'
186182
'"const"': 'storage.modifier'
187183
'"abstract"': 'storage.modifier.abstract.php'

spec/tree-sitter-spec.js

Lines changed: 180 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,9 +1786,186 @@ ${caret}
17861786
// SKIP TS-php handles this
17871787
// it('tokenizes classes declared immediately after another class ends', () => {})
17881788

1789-
describe('properties', () => {
1790-
it('tokenizes types', () => {
1791-
// up next...
1789+
describe("properties", () => {
1790+
it("tokenizes types", () => {
1791+
editor.setContent(`
1792+
class A {
1793+
public int $a = 1;
1794+
}
1795+
`);
1796+
1797+
// public
1798+
expect(editor).toHaveScopesAtPosition(
1799+
[2, 2],
1800+
[
1801+
"source.php",
1802+
"meta.class.php",
1803+
"meta.class.body.php",
1804+
"storage.modifier.php"
1805+
]
1806+
);
1807+
// FIXME not supported by tree-sitter-php until > 0.19.0
1808+
// int
1809+
// expect(editor).toHaveScopesAtPosition(
1810+
// [2, 9],
1811+
// [
1812+
// "source.php",
1813+
// "meta.class.php",
1814+
// "meta.class.body.php",
1815+
// "keyword.other.type.php"
1816+
// ]
1817+
// );
1818+
// $
1819+
expect(editor).toHaveScopesAtPosition(
1820+
[2, 13],
1821+
[
1822+
"source.php",
1823+
"meta.class.php",
1824+
"meta.class.body.php",
1825+
"variable.other.php",
1826+
"punctuation.definition.variable.php"
1827+
]
1828+
);
1829+
// a
1830+
expect(editor).toHaveScopesAtPosition(
1831+
[2, 14],
1832+
[
1833+
"source.php",
1834+
"meta.class.php",
1835+
"meta.class.body.php",
1836+
"variable.other.php"
1837+
]
1838+
);
1839+
});
1840+
1841+
// FIXME not supported by tree-sitter-php until > 0.19.0
1842+
// it("tokenizes nullable types", () => {})
1843+
1844+
it("tokenizes 2 modifiers correctly", () => {
1845+
editor.setContent(`
1846+
class Foo {
1847+
public static $bar = 'baz';
1848+
}
1849+
`);
1850+
1851+
// public
1852+
expect(editor).toHaveScopesAtPosition(
1853+
[2, 2],
1854+
[
1855+
"source.php",
1856+
"meta.class.php",
1857+
"meta.class.body.php",
1858+
"storage.modifier.php"
1859+
]
1860+
);
1861+
// static
1862+
expect(editor).toHaveScopesAtPosition(
1863+
[2, 9],
1864+
[
1865+
"source.php",
1866+
"meta.class.php",
1867+
"meta.class.body.php",
1868+
"storage.modifier.php"
1869+
]
1870+
);
1871+
// $
1872+
expect(editor).toHaveScopesAtPosition(
1873+
[2, 16],
1874+
[
1875+
"source.php",
1876+
"meta.class.php",
1877+
"meta.class.body.php",
1878+
"variable.other.php",
1879+
"punctuation.definition.variable.php"
1880+
]
1881+
);
1882+
// bar
1883+
expect(editor).toHaveScopesAtPosition(
1884+
[2, 17],
1885+
[
1886+
"source.php",
1887+
"meta.class.php",
1888+
"meta.class.body.php",
1889+
"variable.other.php"
1890+
]
1891+
);
1892+
});
1893+
1894+
// FIXME typed properties not supported by tree-sitter-php until > 0.19.0
1895+
// it('tokenizes namespaces', () => {});
1896+
1897+
it("tokenizes multiple properties", () => {
1898+
// FIXME the TM spec includes property types which aren't yet
1899+
// supported by our version of TS-php. Update this spec to match after
1900+
// TS-php has been updated w/ support for prop types.
1901+
editor.setContent(`
1902+
class A {
1903+
private static $c1, $c2;
1904+
}
1905+
`);
1906+
1907+
// private
1908+
expect(editor).toHaveScopesAtPosition(
1909+
[2, 2],
1910+
[
1911+
"source.php",
1912+
"meta.class.php",
1913+
"meta.class.body.php",
1914+
"storage.modifier.php"
1915+
]
1916+
);
1917+
// static
1918+
expect(editor).toHaveScopesAtPosition(
1919+
[2, 10],
1920+
[
1921+
"source.php",
1922+
"meta.class.php",
1923+
"meta.class.body.php",
1924+
"storage.modifier.php"
1925+
]
1926+
);
1927+
// $
1928+
expect(editor).toHaveScopesAtPosition(
1929+
[2, 17],
1930+
[
1931+
"source.php",
1932+
"meta.class.php",
1933+
"meta.class.body.php",
1934+
"variable.other.php",
1935+
"punctuation.definition.variable.php"
1936+
]
1937+
);
1938+
// c1
1939+
expect(editor).toHaveScopesAtPosition(
1940+
[2, 18],
1941+
[
1942+
"source.php",
1943+
"meta.class.php",
1944+
"meta.class.body.php",
1945+
"variable.other.php"
1946+
]
1947+
);
1948+
// $
1949+
expect(editor).toHaveScopesAtPosition(
1950+
[2, 22],
1951+
[
1952+
"source.php",
1953+
"meta.class.php",
1954+
"meta.class.body.php",
1955+
"variable.other.php",
1956+
"punctuation.definition.variable.php"
1957+
]
1958+
);
1959+
// c2
1960+
expect(editor).toHaveScopesAtPosition(
1961+
[2, 23],
1962+
[
1963+
"source.php",
1964+
"meta.class.php",
1965+
"meta.class.body.php",
1966+
"variable.other.php"
1967+
]
1968+
);
17921969
});
17931970
});
17941971

0 commit comments

Comments
 (0)