mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 02:40:09 -04:00
highlights(hack): extend queries add tests
This commit is contained in:
parent
77c006eb08
commit
cc0bdabe5f
10 changed files with 280 additions and 5 deletions
|
|
@ -1,4 +1,16 @@
|
||||||
|
(variable) @variable
|
||||||
|
(identifier) @variable
|
||||||
|
((variable) @variable.builtin
|
||||||
|
(#eq? @variable.builtin "$this"))
|
||||||
|
|
||||||
|
(braced_expression) @none
|
||||||
|
|
||||||
|
(scoped_identifier
|
||||||
|
(qualified_identifier
|
||||||
|
(identifier) @type))
|
||||||
|
|
||||||
(comment) @comment
|
(comment) @comment
|
||||||
|
(heredoc) @comment
|
||||||
|
|
||||||
[
|
[
|
||||||
"function"
|
"function"
|
||||||
|
|
@ -10,14 +22,28 @@
|
||||||
"type"
|
"type"
|
||||||
"interface"
|
"interface"
|
||||||
"class"
|
"class"
|
||||||
|
"protected"
|
||||||
|
"private"
|
||||||
|
"public"
|
||||||
|
"using"
|
||||||
|
"namespace"
|
||||||
|
"attribute"
|
||||||
|
"const"
|
||||||
|
(xhp_modifier)
|
||||||
|
(final_modifier)
|
||||||
|
"extends"
|
||||||
|
"insteadof"
|
||||||
] @keyword
|
] @keyword
|
||||||
|
|
||||||
|
"use" @include
|
||||||
|
|
||||||
[
|
[
|
||||||
"new"
|
"new"
|
||||||
"print"
|
"print"
|
||||||
"echo"
|
"echo"
|
||||||
"newtype"
|
"newtype"
|
||||||
"clone"
|
"clone"
|
||||||
|
"as"
|
||||||
] @keyword.operator
|
] @keyword.operator
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
@ -39,10 +65,30 @@
|
||||||
"mixed"
|
"mixed"
|
||||||
"dynamic"
|
"dynamic"
|
||||||
"noreturn"
|
"noreturn"
|
||||||
] @type
|
] @type.builtin
|
||||||
|
|
||||||
(type_specifier
|
(type_specifier) @type
|
||||||
(qualified_identifier) @type)
|
(new_expression
|
||||||
|
(_) @type)
|
||||||
|
|
||||||
|
(alias_declaration "newtype" . (_) @type)
|
||||||
|
(alias_declaration "type" . (_) @type)
|
||||||
|
|
||||||
|
(class_declaration
|
||||||
|
name: (identifier) @type)
|
||||||
|
(type_parameter
|
||||||
|
name: (identifier) @type)
|
||||||
|
|
||||||
|
(collection
|
||||||
|
(qualified_identifier
|
||||||
|
(identifier) @type .))
|
||||||
|
|
||||||
|
(function_type_specifier) @function
|
||||||
|
(attribute_modifier) @attribute
|
||||||
|
[
|
||||||
|
"@required"
|
||||||
|
"@lateinit"
|
||||||
|
] @attribute
|
||||||
|
|
||||||
[
|
[
|
||||||
"="
|
"="
|
||||||
|
|
@ -79,6 +125,7 @@
|
||||||
"<=>"
|
"<=>"
|
||||||
"<<"
|
"<<"
|
||||||
">>"
|
">>"
|
||||||
|
"->"
|
||||||
"+"
|
"+"
|
||||||
"-"
|
"-"
|
||||||
"."
|
"."
|
||||||
|
|
@ -107,6 +154,7 @@
|
||||||
"/="
|
"/="
|
||||||
"%="
|
"%="
|
||||||
"**="
|
"**="
|
||||||
|
"=>"
|
||||||
|
|
||||||
;; type modifiers
|
;; type modifiers
|
||||||
"@"
|
"@"
|
||||||
|
|
@ -121,15 +169,90 @@
|
||||||
(variable) @parameter)
|
(variable) @parameter)
|
||||||
|
|
||||||
(call_expression
|
(call_expression
|
||||||
function: (qualified_identifier) @function)
|
function: (qualified_identifier (identifier) @function .))
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (scoped_identifier (identifier) @function .))
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (selection_expression
|
||||||
|
(qualified_identifier (identifier) @method .)))
|
||||||
|
|
||||||
|
(qualified_identifier
|
||||||
|
(_) @namespace .
|
||||||
|
(_))
|
||||||
|
|
||||||
|
(use_statement
|
||||||
|
(qualified_identifier
|
||||||
|
(_) @namespace .)
|
||||||
|
(use_clause))
|
||||||
|
|
||||||
|
(use_statement
|
||||||
|
(use_type "namespace")
|
||||||
|
(use_clause
|
||||||
|
(qualified_identifier
|
||||||
|
(identifier) @namespace .)
|
||||||
|
alias: (identifier)? @namespace))
|
||||||
|
|
||||||
|
(use_statement
|
||||||
|
(use_type "const")
|
||||||
|
(use_clause
|
||||||
|
(qualified_identifier
|
||||||
|
(identifier) @constant .)
|
||||||
|
alias: (identifier)? @constant))
|
||||||
|
|
||||||
|
(use_statement
|
||||||
|
(use_type "function")
|
||||||
|
(use_clause
|
||||||
|
(qualified_identifier
|
||||||
|
(identifier) @function .)
|
||||||
|
alias: (identifier)? @function))
|
||||||
|
|
||||||
|
(use_statement
|
||||||
|
(use_type "type")
|
||||||
|
(use_clause
|
||||||
|
(qualified_identifier
|
||||||
|
(identifier) @type .)
|
||||||
|
alias: (identifier)? @type))
|
||||||
|
|
||||||
|
(use_clause
|
||||||
|
(use_type "namespace")
|
||||||
|
(qualified_identifier
|
||||||
|
(_) @namespace .)
|
||||||
|
alias: (identifier)? @namespace)
|
||||||
|
|
||||||
|
(use_clause
|
||||||
|
(use_type "function")
|
||||||
|
(qualified_identifier
|
||||||
|
(_) @function .)
|
||||||
|
alias: (identifier)? @function)
|
||||||
|
|
||||||
|
(use_clause
|
||||||
|
(use_type "const")
|
||||||
|
(qualified_identifier
|
||||||
|
(_) @constant .)
|
||||||
|
alias: (identifier)? @constant)
|
||||||
|
|
||||||
|
(use_clause
|
||||||
|
(use_type "type")
|
||||||
|
(qualified_identifier
|
||||||
|
(_) @type .)
|
||||||
|
alias: (identifier)? @type)
|
||||||
|
|
||||||
(function_declaration
|
(function_declaration
|
||||||
name: (identifier) @function)
|
name: (identifier) @function)
|
||||||
|
(method_declaration
|
||||||
|
name: (identifier) @method)
|
||||||
|
|
||||||
(type_arguments
|
(type_arguments
|
||||||
[ "<" ">" ] @punctuation.bracket)
|
[ "<" ">" ] @punctuation.bracket)
|
||||||
[ "(" ")" "[" "]" "{" "}" "<<" ">>"] @punctuation.bracket
|
[ "(" ")" "[" "]" "{" "}" "<<" ">>"] @punctuation.bracket
|
||||||
|
|
||||||
|
(xhp_open
|
||||||
|
[ "<" ">" ] @tag.delimiter)
|
||||||
|
(xhp_close
|
||||||
|
[ "</" ">" ] @tag.delimiter)
|
||||||
|
|
||||||
[ "." ";" "::" ":" "," ] @punctuation.delimiter
|
[ "." ";" "::" ":" "," ] @punctuation.delimiter
|
||||||
|
|
||||||
(ternary_expression
|
(ternary_expression
|
||||||
|
|
@ -152,11 +275,20 @@
|
||||||
[
|
[
|
||||||
"for"
|
"for"
|
||||||
"while"
|
"while"
|
||||||
|
"foreach"
|
||||||
"do"
|
"do"
|
||||||
"continue"
|
"continue"
|
||||||
"break"
|
"break"
|
||||||
] @repeat
|
] @repeat
|
||||||
|
|
||||||
(string) @string
|
[
|
||||||
|
(string)
|
||||||
|
(xhp_string)
|
||||||
|
] @string
|
||||||
|
|
||||||
|
[
|
||||||
|
(xhp_open)
|
||||||
|
(xhp_close)
|
||||||
|
] @tag
|
||||||
|
|
||||||
(ERROR) @error
|
(ERROR) @error
|
||||||
|
|
|
||||||
6
tests/query/highlights/hack/as-foreach.hack
Normal file
6
tests/query/highlights/hack/as-foreach.hack
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
foreach (($array as vec[]) as $item) {}
|
||||||
|
// ^ repeat
|
||||||
|
// ^ type
|
||||||
|
|
||||||
|
# Our expectation test for the code below intentionally includes an ERROR.
|
||||||
|
foreach ($array as vec[] as $item) {}
|
||||||
8
tests/query/highlights/hack/async-functions.hack
Normal file
8
tests/query/highlights/hack/async-functions.hack
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
async function func0(): void {}
|
||||||
|
// ^ type.builtin
|
||||||
|
async function func1<T1 as int>() {}
|
||||||
|
// ^ type.builtin
|
||||||
|
// ^ keyword.operator
|
||||||
|
|
||||||
|
|
||||||
|
async ($x) ==> $x + 1;
|
||||||
15
tests/query/highlights/hack/attribute-type.hack
Normal file
15
tests/query/highlights/hack/attribute-type.hack
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<<A1>>
|
||||||
|
newtype T1 = ?shape(
|
||||||
|
// TODO: ?operator (? not captureable at the moment)
|
||||||
|
?'int' => int
|
||||||
|
// ^ operator
|
||||||
|
);
|
||||||
|
|
||||||
|
<<A3(1), A2(2,3,)>>
|
||||||
|
// ^ attribute
|
||||||
|
type T2 = (function(T1): string);
|
||||||
|
// ^ type
|
||||||
|
// ^ function (cannot capture keyword "function" as keyword.function)
|
||||||
|
|
||||||
|
<<A4(1), A5, A6(1,3,4)>>
|
||||||
|
newtype T3 as int = int;
|
||||||
23
tests/query/highlights/hack/generics.hack
Normal file
23
tests/query/highlights/hack/generics.hack
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
class Box<T> {
|
||||||
|
// ^ type
|
||||||
|
// ^ type
|
||||||
|
protected T $data;
|
||||||
|
// ^ keyword
|
||||||
|
// ^ type
|
||||||
|
|
||||||
|
public function __construct(T $data) {
|
||||||
|
// ^ type
|
||||||
|
// ^ parameter
|
||||||
|
// ^ keyword
|
||||||
|
// ^ method
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getData(): T {
|
||||||
|
// ^ method
|
||||||
|
// ^ keyword
|
||||||
|
return $this->data;
|
||||||
|
// ^ operator
|
||||||
|
// ^ variable.builtin
|
||||||
|
}
|
||||||
|
}
|
||||||
4
tests/query/highlights/hack/heredoc-dollar.hack
Normal file
4
tests/query/highlights/hack/heredoc-dollar.hack
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
<<<EOT
|
||||||
|
$('a') abc $(function{return;})
|
||||||
|
EOT;
|
||||||
|
// <- comment ^ comment
|
||||||
28
tests/query/highlights/hack/use.hack
Normal file
28
tests/query/highlights/hack/use.hack
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
use const Space\Const\C;
|
||||||
|
// ^ keyword
|
||||||
|
// ^ constant
|
||||||
|
use function Space\Func\F as E;
|
||||||
|
// ^ function
|
||||||
|
// ^ function
|
||||||
|
use type Space\Type\T;
|
||||||
|
// ^ keyword
|
||||||
|
use namespace Space\Name\N as M;
|
||||||
|
// ^ keyword
|
||||||
|
// ^ namespace
|
||||||
|
|
||||||
|
use namespace Space\Name2\N2, Space\Nothing\N3 as N8, type Space\Type2\N4,;
|
||||||
|
// ^ namespace
|
||||||
|
// ^ type
|
||||||
|
use namespace Space\Name\N10\{A as A2, B\};
|
||||||
|
// ^ namespace
|
||||||
|
// ^ namespace
|
||||||
|
// ^ namespace
|
||||||
|
use namespace Space\Name\{\C, Slash as Forward};
|
||||||
|
|
||||||
|
use \What\Is\This\{function A as A2, B, const H\S\L as stdlib, function F};
|
||||||
|
|
||||||
|
use type \{kind,};
|
||||||
|
use Q\B\{kind2,};
|
||||||
|
// ^ namespace
|
||||||
|
use type Q\B\{kind3,};
|
||||||
|
// <- include
|
||||||
3
tests/query/highlights/hack/using.hack
Normal file
3
tests/query/highlights/hack/using.hack
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
using ($new = new Object(), $file = new File('using', '+using')) {}
|
||||||
|
// <- keyword
|
||||||
|
// ^ type
|
||||||
10
tests/query/highlights/hack/xhp.hack
Normal file
10
tests/query/highlights/hack/xhp.hack
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
$user_name = 'Fred';
|
||||||
|
echo "<tt>Hello <strong>$user_name</tt></strong>";
|
||||||
|
|
||||||
|
// XHP: Typechecked, well-formed, and secure
|
||||||
|
$user_name = 'Andrew';
|
||||||
|
$xhp = <tt>Hello <strong>{$user_name}</strong></tt>;
|
||||||
|
// ^ tag
|
||||||
|
// ^ tag
|
||||||
|
// ^ string
|
||||||
|
echo await $xhp->toStringAsync();
|
||||||
46
tests/query/highlights/xhp-intro.hack
Normal file
46
tests/query/highlights/xhp-intro.hack
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
// From https://docs.hhvm.com/hack/XHP/introduction (MIT licensed)
|
||||||
|
|
||||||
|
use namespace Facebook\XHP\Core as x;
|
||||||
|
use type Facebook\XHP\HTML\{XHPHTMLHelpers, a, form};
|
||||||
|
|
||||||
|
|
||||||
|
final xhp class a_post extends x\element {
|
||||||
|
// ^ keyword
|
||||||
|
// ^ keyword
|
||||||
|
// ^ keyword
|
||||||
|
use XHPHTMLHelpers;
|
||||||
|
|
||||||
|
attribute string href @required;
|
||||||
|
// ^ attribute
|
||||||
|
attribute string target;
|
||||||
|
// ^ keyword
|
||||||
|
|
||||||
|
<<__Override>>
|
||||||
|
protected async function renderAsync(): Awaitable<x\node> {
|
||||||
|
$id = $this->getID();
|
||||||
|
|
||||||
|
$anchor = <a>{$this->getChildren()}</a>;
|
||||||
|
// ^ tag.delimiter
|
||||||
|
// ^ tag
|
||||||
|
$form = (
|
||||||
|
<form
|
||||||
|
id={$id}
|
||||||
|
method="post"
|
||||||
|
action={$this->:href}
|
||||||
|
target={$this->:target}
|
||||||
|
class="postLink">
|
||||||
|
{$anchor}
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
|
||||||
|
$anchor->setAttribute(
|
||||||
|
'onclick',
|
||||||
|
'document.getElementById("'.$id.'").submit(); return false;',
|
||||||
|
);
|
||||||
|
$anchor->setAttribute('href', '#');
|
||||||
|
// ^ method
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue