reovim_lang_json/
lib.rs

1//! JSON language support for reovim
2
3use std::{any::TypeId, sync::Arc};
4
5use {
6    reovim_core::{
7        event_bus::EventBus,
8        plugin::{Plugin, PluginContext, PluginId, PluginStateRegistry},
9    },
10    reovim_plugin_treesitter::{LanguageSupport, RegisterLanguage, TreesitterPlugin},
11};
12
13/// JSON language support
14pub struct JsonLanguage;
15
16impl LanguageSupport for JsonLanguage {
17    fn language_id(&self) -> &'static str {
18        "json"
19    }
20
21    fn file_extensions(&self) -> &'static [&'static str] {
22        &["json", "jsonc"]
23    }
24
25    fn tree_sitter_language(&self) -> reovim_plugin_treesitter::Language {
26        tree_sitter_json::LANGUAGE.into()
27    }
28
29    fn highlights_query(&self) -> &'static str {
30        include_str!("queries/highlights.scm")
31    }
32}
33
34/// JSON language plugin
35pub struct JsonPlugin;
36
37impl Plugin for JsonPlugin {
38    fn id(&self) -> PluginId {
39        PluginId::new("reovim:lang-json")
40    }
41
42    fn name(&self) -> &'static str {
43        "JSON Language"
44    }
45
46    fn description(&self) -> &'static str {
47        "JSON language support with syntax highlighting"
48    }
49
50    fn dependencies(&self) -> Vec<TypeId> {
51        vec![TypeId::of::<TreesitterPlugin>()]
52    }
53
54    fn build(&self, _ctx: &mut PluginContext) {
55        // No commands to register
56    }
57
58    fn subscribe(&self, bus: &EventBus, _state: Arc<PluginStateRegistry>) {
59        // Register this language with treesitter
60        bus.emit(RegisterLanguage {
61            language: Arc::new(JsonLanguage),
62        });
63    }
64}