Skip to main content

oak_wolfram/lsp/
mod.rs

1//! Wolfram Language Server Protocol (LSP) support.
2
3/// Wolfram syntax highlighter.
4pub mod highlighter;
5
6use crate::language::WolframLanguage;
7use core::range::Range;
8use oak_core::tree::RedNode;
9#[cfg(feature = "lsp")]
10use {futures::Future, oak_lsp::service::LanguageService, oak_lsp::types::Hover as LspHover, oak_vfs::Vfs};
11
12/// Language service for Wolfram.
13#[cfg(feature = "lsp")]
14pub struct WolframLanguageService<V: Vfs> {
15    /// The virtual file system.
16    vfs: V,
17    /// The workspace manager for managing document state.
18    workspace: oak_lsp::workspace::WorkspaceManager,
19}
20
21impl<V: Vfs> WolframLanguageService<V> {
22    /// Creates a new `WolframLanguageService`.
23    pub fn new(vfs: V) -> Self {
24        Self { vfs, workspace: oak_lsp::workspace::WorkspaceManager::new() }
25    }
26}
27impl<V: Vfs + Send + Sync + 'static + oak_vfs::WritableVfs> LanguageService for WolframLanguageService<V> {
28    type Lang = WolframLanguage;
29    type Vfs = V;
30    fn vfs(&self) -> &Self::Vfs {
31        &self.vfs
32    }
33    fn workspace(&self) -> &oak_lsp::workspace::WorkspaceManager {
34        &self.workspace
35    }
36    fn get_root(&self, _uri: &str) -> impl Future<Output = Option<RedNode<'_, WolframLanguage>>> + Send + '_ {
37        async move { None }
38    }
39    fn hover(&self, _uri: &str, _range: Range<usize>) -> impl Future<Output = Option<LspHover>> + Send + '_ {
40        async move { None }
41    }
42}