From 083ea286ae4c62a903655726dbb20b513484ddb6 Mon Sep 17 00:00:00 2001 From: Jellyfrog Date: Wed, 23 Mar 2022 17:53:17 +0100 Subject: [PATCH] Add PHP syntax highlighting --- Cargo.lock | 10 ++++++++++ lapce-core/Cargo.toml | 1 + lapce-core/src/language.rs | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 04160396..e04f03a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1864,6 +1864,7 @@ dependencies = [ "tree-sitter-go", "tree-sitter-highlight", "tree-sitter-javascript", + "tree-sitter-php", "tree-sitter-python", "tree-sitter-rust", "tree-sitter-toml", @@ -4089,6 +4090,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-php" +version = "0.19.1" +source = "git+https://github.com/tree-sitter/tree-sitter-php.git#ead3e4cc5f54602a6b54826c5d6881c9a9da15af" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-python" version = "0.19.1" diff --git a/lapce-core/Cargo.toml b/lapce-core/Cargo.toml index 07d33974..2ce7e2f7 100644 --- a/lapce-core/Cargo.toml +++ b/lapce-core/Cargo.toml @@ -17,4 +17,5 @@ tree-sitter-javascript = "0.20.0" tree-sitter-typescript = "0.20.0" tree-sitter-python = "0.19.1" tree-sitter-toml = "0.20.0" +tree-sitter-php = { git = "https://github.com/tree-sitter/tree-sitter-php.git", version = "0.19.1" } xi-rope = { git = "https://github.com/lapce/xi-editor", features = ["serde"] } diff --git a/lapce-core/src/language.rs b/lapce-core/src/language.rs index 09c48863..6542ca1f 100644 --- a/lapce-core/src/language.rs +++ b/lapce-core/src/language.rs @@ -43,6 +43,7 @@ pub enum LapceLanguage { Tsx, Python, Toml, + Php, } impl LapceLanguage { @@ -57,6 +58,7 @@ pub fn from_path(path: &Path) -> Option { "go" => LapceLanguage::Go, "py" => LapceLanguage::Python, "toml" => LapceLanguage::Toml, + "php" => LapceLanguage::Php, _ => return None, }) } @@ -71,6 +73,7 @@ pub fn comment_token(&self) -> &str { LapceLanguage::Tsx => "//", LapceLanguage::Python => "#", LapceLanguage::Toml => "#", + LapceLanguage::Php => "//", } } @@ -84,6 +87,7 @@ pub fn indent_unit(&self) -> &str { LapceLanguage::Tsx => " ", LapceLanguage::Python => " ", LapceLanguage::Toml => " ", + LapceLanguage::Php => " ", } } @@ -99,6 +103,7 @@ fn tree_sitter_language(&self) -> tree_sitter::Language { LapceLanguage::Tsx => tree_sitter_typescript::language_tsx(), LapceLanguage::Python => tree_sitter_python::language(), LapceLanguage::Toml => tree_sitter_toml::language(), + LapceLanguage::Php => tree_sitter_php::language(), } } @@ -120,6 +125,7 @@ pub(crate) fn new_highlight_config(&self) -> HighlightConfiguration { LapceLanguage::Tsx => tree_sitter_typescript::HIGHLIGHT_QUERY, LapceLanguage::Python => tree_sitter_python::HIGHLIGHT_QUERY, LapceLanguage::Toml => tree_sitter_toml::HIGHLIGHT_QUERY, + LapceLanguage::Php => tree_sitter_php::HIGHLIGHT_QUERY, }; HighlightConfiguration::new(language, query, "", "").unwrap()