1use crate::SmalltalkLanguage;
2use core::range::Range;
3use futures::Future;
4use oak_core::tree::RedNode;
5use oak_hover::{Hover, HoverProvider};
6use oak_lsp::service::LanguageService;
7use oak_vfs::Vfs;
8
9pub struct SmalltalkHoverProvider;
10
11impl HoverProvider<SmalltalkLanguage> for SmalltalkHoverProvider {
12 fn hover(&self, node: &RedNode<SmalltalkLanguage>, _range: Range<usize>) -> Option<Hover> {
13 let contents = format!("### Smalltalk Node\nKind: {:?}", node.green.kind);
14 Some(Hover { contents, range: Some(node.span()) })
15 }
16}
17
18pub struct SmalltalkLanguageService<V: Vfs> {
19 vfs: V,
20 workspace: oak_lsp::workspace::WorkspaceManager,
21 hover_provider: SmalltalkHoverProvider,
22}
23
24impl<V: Vfs> SmalltalkLanguageService<V> {
25 pub fn new(vfs: V) -> Self {
26 Self { vfs, workspace: oak_lsp::workspace::WorkspaceManager::default(), hover_provider: SmalltalkHoverProvider }
27 }
28}
29
30impl<V: Vfs + Send + Sync + 'static + oak_vfs::WritableVfs> LanguageService for SmalltalkLanguageService<V> {
31 type Lang = SmalltalkLanguage;
32 type Vfs = V;
33
34 fn vfs(&self) -> &Self::Vfs {
35 &self.vfs
36 }
37 fn workspace(&self) -> &oak_lsp::workspace::WorkspaceManager {
38 &self.workspace
39 }
40
41 fn get_root(&self, _uri: &str) -> impl Future<Output = Option<RedNode<'_, SmalltalkLanguage>>> + Send + '_ {
42 async move { None }
43 }
44
45 fn hover(&self, uri: &str, range: Range<usize>) -> impl Future<Output = Option<oak_lsp::Hover>> + Send + '_ {
46 let uri = uri.to_string();
47 async move { self.with_root(&uri, |root| self.hover_provider.hover(&root, range).map(|h| oak_lsp::Hover { contents: h.contents, range: h.range })).await.flatten() }
48 }
49}