Add PHP syntax highlighting

This commit is contained in:
Jellyfrog 2022-03-23 17:53:17 +01:00
parent 68c91c68ad
commit 083ea286ae
3 changed files with 17 additions and 0 deletions

10
Cargo.lock generated
View File

@ -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"

View File

@ -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"] }

View File

@ -43,6 +43,7 @@ pub enum LapceLanguage {
Tsx,
Python,
Toml,
Php,
}
impl LapceLanguage {
@ -57,6 +58,7 @@ pub fn from_path(path: &Path) -> Option<LapceLanguage> {
"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()