Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
lsp: Add clangd readonly token modifier to semantic token rules to highlight constant variables as constant (#49065)
ozacode5a69d89497e
diff --git a/crates/languages/src/cpp.rs b/crates/languages/src/cpp.rsindex 85a3fb50452..3207b492f4b 100644--- a/crates/languages/src/cpp.rs+++ b/crates/languages/src/cpp.rs@@ -1,3 +1,15 @@+use settings::SemanticTokenRules;++use crate::LanguageDir;++pub(crate) fn semantic_token_rules() -> SemanticTokenRules {+ let content = LanguageDir::get("cpp/semantic_token_rules.json")+ .expect("missing cpp/semantic_token_rules.json");+ let json = std::str::from_utf8(&content.data).expect("invalid utf-8 in semantic_token_rules");+ settings::parse_json_with_comments::<SemanticTokenRules>(json)+ .expect("failed to parse cpp semantic_token_rules.json")+}+#[cfg(test)]mod tests {use gpui::{AppContext as _, BorrowAppContext, TestAppContext};diff --git a/crates/languages/src/cpp/semantic_token_rules.json b/crates/languages/src/cpp/semantic_token_rules.jsonnew file mode 100644index 00000000000..627a5c5f187--- /dev/null+++ b/crates/languages/src/cpp/semantic_token_rules.json@@ -0,0 +1,7 @@+[+ {+ "token_type": "variable",+ "token_modifiers": ["readonly"],+ "style": ["constant"]+ }+]diff --git a/crates/languages/src/lib.rs b/crates/languages/src/lib.rsindex 275b8c58ecd..240935d2f81 100644--- a/crates/languages/src/lib.rs+++ b/crates/languages/src/lib.rs@@ -125,6 +125,7 @@ pub fn init(languages: Arc<LanguageRegistry>, fs: Arc<dyn Fs>, node: NodeRuntimeLanguageInfo {name: "cpp",adapters: vec![c_lsp_adapter],+ semantic_token_rules: Some(cpp::semantic_token_rules()),..Default::default()},LanguageInfo {