Add rudimentary PHP syntax highlighting
This commit is contained in:
parent
6739c31594
commit
a1fe5abeaf
9 changed files with 197 additions and 1 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -8004,6 +8004,15 @@ dependencies = [
|
||||||
"tree-sitter",
|
"tree-sitter",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tree-sitter-php"
|
||||||
|
version = "0.19.1"
|
||||||
|
source = "git+https://github.com/tree-sitter/tree-sitter-php?rev=d38adb26304d9b9d38e9a3b4aae0ec4b29bf9462#d38adb26304d9b9d38e9a3b4aae0ec4b29bf9462"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"tree-sitter",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tree-sitter-python"
|
name = "tree-sitter-python"
|
||||||
version = "0.20.2"
|
version = "0.20.2"
|
||||||
|
@ -9432,6 +9441,7 @@ dependencies = [
|
||||||
"tree-sitter-json 0.20.0",
|
"tree-sitter-json 0.20.0",
|
||||||
"tree-sitter-lua",
|
"tree-sitter-lua",
|
||||||
"tree-sitter-markdown",
|
"tree-sitter-markdown",
|
||||||
|
"tree-sitter-php",
|
||||||
"tree-sitter-python",
|
"tree-sitter-python",
|
||||||
"tree-sitter-racket",
|
"tree-sitter-racket",
|
||||||
"tree-sitter-ruby",
|
"tree-sitter-ruby",
|
||||||
|
|
|
@ -114,6 +114,7 @@ tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", re
|
||||||
tree-sitter-rust = "0.20.3"
|
tree-sitter-rust = "0.20.3"
|
||||||
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }
|
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }
|
||||||
tree-sitter-python = "0.20.2"
|
tree-sitter-python = "0.20.2"
|
||||||
|
tree-sitter-php = { git = "https://github.com/tree-sitter/tree-sitter-php", rev = "d38adb26304d9b9d38e9a3b4aae0ec4b29bf9462" }
|
||||||
tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", rev = "342d9be207c2dba869b9967124c679b5e6fd0ebe" }
|
tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", rev = "342d9be207c2dba869b9967124c679b5e6fd0ebe" }
|
||||||
tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259" }
|
tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259" }
|
||||||
tree-sitter-ruby = "0.20.0"
|
tree-sitter-ruby = "0.20.0"
|
||||||
|
|
|
@ -137,6 +137,7 @@ pub fn init(languages: Arc<LanguageRegistry>, node_runtime: Arc<NodeRuntime>) {
|
||||||
tree_sitter_yaml::language(),
|
tree_sitter_yaml::language(),
|
||||||
vec![Arc::new(yaml::YamlLspAdapter::new(node_runtime))],
|
vec![Arc::new(yaml::YamlLspAdapter::new(node_runtime))],
|
||||||
);
|
);
|
||||||
|
language("php", tree_sitter_php::language(), vec![]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
|
11
crates/zed/src/languages/php/config.toml
Normal file
11
crates/zed/src/languages/php/config.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
name = "PHP"
|
||||||
|
path_suffixes = ["php"]
|
||||||
|
first_line_pattern = '^#!.*php'
|
||||||
|
line_comment = "// "
|
||||||
|
autoclose_before = ";:.,=}])>"
|
||||||
|
brackets = [
|
||||||
|
{ start = "{", end = "}", close = true, newline = true },
|
||||||
|
{ start = "[", end = "]", close = true, newline = true },
|
||||||
|
{ start = "(", end = ")", close = true, newline = true },
|
||||||
|
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
|
||||||
|
]
|
122
crates/zed/src/languages/php/highlights.scm
Normal file
122
crates/zed/src/languages/php/highlights.scm
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
(php_tag) @tag
|
||||||
|
"?>" @tag
|
||||||
|
|
||||||
|
; Types
|
||||||
|
|
||||||
|
(primitive_type) @type.builtin
|
||||||
|
(cast_type) @type.builtin
|
||||||
|
(named_type (name) @type) @type
|
||||||
|
(named_type (qualified_name) @type) @type
|
||||||
|
|
||||||
|
; Functions
|
||||||
|
|
||||||
|
(array_creation_expression "array" @function.builtin)
|
||||||
|
(list_literal "list" @function.builtin)
|
||||||
|
|
||||||
|
(method_declaration
|
||||||
|
name: (name) @function.method)
|
||||||
|
|
||||||
|
(function_call_expression
|
||||||
|
function: [(qualified_name (name)) (name)] @function)
|
||||||
|
|
||||||
|
(scoped_call_expression
|
||||||
|
name: (name) @function)
|
||||||
|
|
||||||
|
(member_call_expression
|
||||||
|
name: (name) @function.method)
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
name: (name) @function)
|
||||||
|
|
||||||
|
; Member
|
||||||
|
|
||||||
|
(property_element
|
||||||
|
(variable_name) @property)
|
||||||
|
|
||||||
|
(member_access_expression
|
||||||
|
name: (variable_name (name)) @property)
|
||||||
|
(member_access_expression
|
||||||
|
name: (name) @property)
|
||||||
|
|
||||||
|
; Variables
|
||||||
|
|
||||||
|
(relative_scope) @variable.builtin
|
||||||
|
|
||||||
|
((name) @constant
|
||||||
|
(#match? @constant "^_?[A-Z][A-Z\\d_]+$"))
|
||||||
|
((name) @constant.builtin
|
||||||
|
(#match? @constant.builtin "^__[A-Z][A-Z\d_]+__$"))
|
||||||
|
|
||||||
|
((name) @constructor
|
||||||
|
(#match? @constructor "^[A-Z]"))
|
||||||
|
|
||||||
|
((name) @variable.builtin
|
||||||
|
(#eq? @variable.builtin "this"))
|
||||||
|
|
||||||
|
(variable_name) @variable
|
||||||
|
|
||||||
|
; Basic tokens
|
||||||
|
[
|
||||||
|
(string)
|
||||||
|
(string_value)
|
||||||
|
(encapsed_string)
|
||||||
|
(heredoc)
|
||||||
|
(heredoc_body)
|
||||||
|
(nowdoc_body)
|
||||||
|
] @string
|
||||||
|
(boolean) @constant.builtin
|
||||||
|
(null) @constant.builtin
|
||||||
|
(integer) @number
|
||||||
|
(float) @number
|
||||||
|
(comment) @comment
|
||||||
|
|
||||||
|
"$" @operator
|
||||||
|
|
||||||
|
; Keywords
|
||||||
|
|
||||||
|
"abstract" @keyword
|
||||||
|
"as" @keyword
|
||||||
|
"break" @keyword
|
||||||
|
"case" @keyword
|
||||||
|
"catch" @keyword
|
||||||
|
"class" @keyword
|
||||||
|
"const" @keyword
|
||||||
|
"continue" @keyword
|
||||||
|
"declare" @keyword
|
||||||
|
"default" @keyword
|
||||||
|
"do" @keyword
|
||||||
|
"echo" @keyword
|
||||||
|
"else" @keyword
|
||||||
|
"elseif" @keyword
|
||||||
|
"enddeclare" @keyword
|
||||||
|
"endforeach" @keyword
|
||||||
|
"endif" @keyword
|
||||||
|
"endswitch" @keyword
|
||||||
|
"endwhile" @keyword
|
||||||
|
"extends" @keyword
|
||||||
|
"final" @keyword
|
||||||
|
"finally" @keyword
|
||||||
|
"foreach" @keyword
|
||||||
|
"function" @keyword
|
||||||
|
"global" @keyword
|
||||||
|
"if" @keyword
|
||||||
|
"implements" @keyword
|
||||||
|
"include_once" @keyword
|
||||||
|
"include" @keyword
|
||||||
|
"insteadof" @keyword
|
||||||
|
"interface" @keyword
|
||||||
|
"namespace" @keyword
|
||||||
|
"new" @keyword
|
||||||
|
"private" @keyword
|
||||||
|
"protected" @keyword
|
||||||
|
"public" @keyword
|
||||||
|
"require_once" @keyword
|
||||||
|
"require" @keyword
|
||||||
|
"return" @keyword
|
||||||
|
"static" @keyword
|
||||||
|
"switch" @keyword
|
||||||
|
"throw" @keyword
|
||||||
|
"trait" @keyword
|
||||||
|
"try" @keyword
|
||||||
|
"use" @keyword
|
||||||
|
"while" @keyword
|
3
crates/zed/src/languages/php/injections.scm
Normal file
3
crates/zed/src/languages/php/injections.scm
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
((text) @injection.content
|
||||||
|
(#set! injection.language "html")
|
||||||
|
(#set! injection.combined))
|
8
crates/zed/src/languages/php/outline.scm
Normal file
8
crates/zed/src/languages/php/outline.scm
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
(class_declaration
|
||||||
|
"class" @context
|
||||||
|
name: (name) @name
|
||||||
|
) @item
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
"function" @context
|
||||||
|
name: (_) @name) @item
|
40
crates/zed/src/languages/php/tags.scm
Normal file
40
crates/zed/src/languages/php/tags.scm
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
(namespace_definition
|
||||||
|
name: (namespace_name) @name) @module
|
||||||
|
|
||||||
|
(interface_declaration
|
||||||
|
name: (name) @name) @definition.interface
|
||||||
|
|
||||||
|
(trait_declaration
|
||||||
|
name: (name) @name) @definition.interface
|
||||||
|
|
||||||
|
(class_declaration
|
||||||
|
name: (name) @name) @definition.class
|
||||||
|
|
||||||
|
(class_interface_clause [(name) (qualified_name)] @name) @impl
|
||||||
|
|
||||||
|
(property_declaration
|
||||||
|
(property_element (variable_name (name) @name))) @definition.field
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
name: (name) @name) @definition.function
|
||||||
|
|
||||||
|
(method_declaration
|
||||||
|
name: (name) @name) @definition.function
|
||||||
|
|
||||||
|
(object_creation_expression
|
||||||
|
[
|
||||||
|
(qualified_name (name) @name)
|
||||||
|
(variable_name (name) @name)
|
||||||
|
]) @reference.class
|
||||||
|
|
||||||
|
(function_call_expression
|
||||||
|
function: [
|
||||||
|
(qualified_name (name) @name)
|
||||||
|
(variable_name (name)) @name
|
||||||
|
]) @reference.call
|
||||||
|
|
||||||
|
(scoped_call_expression
|
||||||
|
name: (name) @name) @reference.call
|
||||||
|
|
||||||
|
(member_call_expression
|
||||||
|
name: (name) @name) @reference.call
|
|
@ -6,4 +6,4 @@
|
||||||
(function_definition
|
(function_definition
|
||||||
"async"? @context
|
"async"? @context
|
||||||
"def" @context
|
"def" @context
|
||||||
name: (_) @name) @item
|
name: (_) @name) @item
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue