Skip to content

Commit

Permalink
feat: add namespace highlights and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Jun 7, 2024
1 parent 1cc88cc commit 0a0b851
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
35 changes: 35 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,41 @@
(yield_expression "from" @keyword)
(function_static_declaration "static" @keyword)

; Namespace

(namespace_definition
name: (namespace_name
(name) @module))

(namespace_name
(name) @module)

(namespace_use_clause
[
(name) @type
(qualified_name
(name) @type)
alias: (name) @type
])

(namespace_use_clause
type: "function"
[
(name) @function
(qualified_name
(name) @function)
alias: (name) @function
])

(namespace_use_clause
type: "const"
[
(name) @constant
(qualified_name
(name) @constant)
alias: (name) @constant
])

; Variables

(relative_scope) @variable.builtin
Expand Down
34 changes: 33 additions & 1 deletion test/highlight/keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,39 @@
// <- @keyword

namespace A\B;
// <- @keyword
//^^^^^^^ @keyword
// ^ @module
// ^ @module

use Foo\Baz as Baaz;
//^ @keyword
// ^^^ @module
// ^^^ @type
// ^^ @keyword
// ^^^^ @type

use function Foo\foo as fooo;
// ^^^^^^^^ @keyword
// ^^^ @function
// ^^^^ @function

use const Foo\FOO as FOOO;
// ^^^^^ @keyword
// ^^^ @constant
// ^^^^ @constant

use Foo\Baz\{
// ^^^ @module
// ^^^ @module
Bar,
//^^^ @type
function foo,
//^^^^^^^^ @keyword
// ^^^ @function
const FOO,
//^^^^^ @keyword
// ^^^ @constant
};

if ($a and $b or $c xor $d) {} elseif ($b) {} else {}
// <- @keyword
Expand Down
5 changes: 3 additions & 2 deletions test/highlight/types.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

function b(int $a, string $b, Person $e): Dog {}
function b(int $a, string $b, Person $e): Foo\Dog {}
// ^^^ @type.builtin
// ^^^^^^ @type.builtin
// ^^^^^^ @type
// ^^^ @type
// ^^^ @module
// ^^^ @type

function a(array $b) {
// ^^^^^ @type.builtin
Expand Down

0 comments on commit 0a0b851

Please sign in to comment.