Skip to main content

oak_css/lsp/
mod.rs

1#![doc = include_str!("readme.md")]
2use crate::CssLanguage;
3use oak_core::tree::RedNode;
4/// Highlighter module.
5#[cfg(feature = "oak-highlight")]
6pub mod highlighter;
7
8#[cfg(feature = "lsp")]
9use {oak_lsp::service::LanguageService, oak_vfs::Vfs, std::future::Future};
10/// MCP module.
11/// Formatter module.
12#[cfg(feature = "lsp")]
13#[cfg(feature = "oak-pretty-print")]
14pub mod formatter;
15/// Language service implementation for CSS.
16#[cfg(feature = "lsp")]
17pub struct CssLanguageService<V: Vfs> {
18    vfs: V,
19    workspace: oak_lsp::workspace::WorkspaceManager,
20}
21#[cfg(feature = "lsp")]
22impl<V: Vfs> CssLanguageService<V> {
23    /// Creates a new `CssLanguageService`.
24    pub fn new(vfs: V) -> Self {
25        Self { vfs, workspace: oak_lsp::workspace::WorkspaceManager::default() }
26    }
27}
28#[cfg(feature = "lsp")]
29impl<V: Vfs + Send + Sync + 'static + oak_vfs::WritableVfs> LanguageService for CssLanguageService<V> {
30    type Lang = CssLanguage;
31    type Vfs = V;
32    fn vfs(&self) -> &Self::Vfs {
33        &self.vfs
34    }
35    fn workspace(&self) -> &oak_lsp::workspace::WorkspaceManager {
36        &self.workspace
37    }
38    fn get_root(&self, uri: &str) -> impl Future<Output = Option<RedNode<'_, CssLanguage>>> + Send + '_ {
39        let source = self.vfs().get_source(uri);
40        async move {
41            let _source = source?;
42            // TODO: Implement actual parsing here if needed
43            None
44        }
45    }
46}