reovim_lang_python/
lib.rs

1//! Python 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/// Python language support
14pub struct PythonLanguage;
15
16impl LanguageSupport for PythonLanguage {
17    fn language_id(&self) -> &'static str {
18        "python"
19    }
20
21    fn file_extensions(&self) -> &'static [&'static str] {
22        &["py", "pyi", "pyw"]
23    }
24
25    fn tree_sitter_language(&self) -> reovim_plugin_treesitter::Language {
26        tree_sitter_python::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/// Python language plugin
43pub struct PythonPlugin;
44
45impl Plugin for PythonPlugin {
46    fn id(&self) -> PluginId {
47        PluginId::new("reovim:lang-python")
48    }
49
50    fn name(&self) -> &'static str {
51        "Python Language"
52    }
53
54    fn description(&self) -> &'static str {
55        "Python 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(PythonLanguage),
70        });
71    }
72}