reovim_lang_javascript/
lib.rs

1//! JavaScript 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/// JavaScript language support
14pub struct JavaScriptLanguage;
15
16impl LanguageSupport for JavaScriptLanguage {
17    fn language_id(&self) -> &'static str {
18        "javascript"
19    }
20
21    fn file_extensions(&self) -> &'static [&'static str] {
22        &["js", "jsx", "mjs", "cjs"]
23    }
24
25    fn tree_sitter_language(&self) -> reovim_plugin_treesitter::Language {
26        tree_sitter_javascript::LANGUAGE.into()
27    }
28
29    fn highlights_query(&self) -> &'static str {
30        include_str!("queries/highlights.scm")
31    }
32
33    fn folds_query(&self) -> Option<&'static str> {
34        Some(include_str!("queries/folds.scm"))
35    }
36
37    fn textobjects_query(&self) -> Option<&'static str> {
38        Some(include_str!("queries/textobjects.scm"))
39    }
40}
41
42/// JavaScript language plugin
43pub struct JavaScriptPlugin;
44
45impl Plugin for JavaScriptPlugin {
46    fn id(&self) -> PluginId {
47        PluginId::new("reovim:lang-javascript")
48    }
49
50    fn name(&self) -> &'static str {
51        "JavaScript Language"
52    }
53
54    fn description(&self) -> &'static str {
55        "JavaScript language support with syntax highlighting and semantic analysis"
56    }
57
58    fn dependencies(&self) -> Vec<TypeId> {
59        vec![TypeId::of::<TreesitterPlugin>()]
60    }
61
62    fn build(&self, _ctx: &mut PluginContext) {
63        // No commands to register
64    }
65
66    fn subscribe(&self, bus: &EventBus, _state: Arc<PluginStateRegistry>) {
67        // Register this language with treesitter
68        bus.emit(RegisterLanguage {
69            language: Arc::new(JavaScriptLanguage),
70        });
71    }
72}