oak_actionscript/lsp/
mod.rs1#![doc = include_str!("readme.md")]
2#[cfg(feature = "oak-pretty-print")]
3pub mod formatter;
4#[cfg(feature = "oak-highlight")]
5pub mod highlighter;
6
7use crate::{ActionScriptLanguage, parser::ActionScriptElementType};
8use core::range::Range;
9use oak_core::tree::RedNode;
10
11#[cfg(feature = "lsp")]
12use {
13 futures::Future,
14 oak_hover::{Hover, HoverProvider},
15 oak_lsp::service::LanguageService,
16 oak_vfs::Vfs,
17};
18
19#[cfg(feature = "lsp")]
20#[cfg(feature = "lsp")]
22pub struct ActionScriptHoverProvider;
23
24#[cfg(feature = "lsp")]
25impl HoverProvider<ActionScriptLanguage> for ActionScriptHoverProvider {
26 fn hover(&self, node: &RedNode<ActionScriptLanguage>, _range: Range<usize>) -> Option<Hover> {
27 let kind = node.green.kind;
28
29 let contents = match kind {
30 ActionScriptElementType::Class => "### ActionScript Class\nDefines a blueprint for objects.",
31 ActionScriptElementType::Interface => "### ActionScript Interface\nDefines a contract for classes.",
32 ActionScriptElementType::Function => "### ActionScript Function\nDefines a block of code that performs a task.",
33 _ => return None,
34 };
35
36 Some(Hover { contents: contents.to_string(), range: Some(node.span()) })
37 }
38}
39
40#[cfg(feature = "lsp")]
41#[cfg(feature = "lsp")]
43pub struct ActionScriptLanguageService<V: Vfs> {
44 vfs: V,
45 workspace: oak_lsp::workspace::WorkspaceManager,
46 hover_provider: ActionScriptHoverProvider,
47}
48
49#[cfg(feature = "lsp")]
50impl<V: Vfs> ActionScriptLanguageService<V> {
51 pub fn new(vfs: V) -> Self {
53 Self { vfs, workspace: oak_lsp::workspace::WorkspaceManager::default(), hover_provider: ActionScriptHoverProvider }
54 }
55}
56
57#[cfg(feature = "lsp")]
58impl<V: Vfs + Send + Sync + 'static + oak_vfs::WritableVfs> LanguageService for ActionScriptLanguageService<V> {
59 type Lang = ActionScriptLanguage;
60 type Vfs = V;
61
62 fn vfs(&self) -> &Self::Vfs {
63 &self.vfs
64 }
65
66 fn workspace(&self) -> &oak_lsp::workspace::WorkspaceManager {
67 &self.workspace
68 }
69
70 fn get_root(&self, uri: &str) -> impl Future<Output = Option<RedNode<'_, ActionScriptLanguage>>> + Send + '_ {
71 let source = self.vfs().get_source(uri);
72 async move {
73 let _source = source?;
74 None
76 }
77 }
78
79 fn hover(&self, uri: &str, range: Range<usize>) -> impl Future<Output = Option<oak_lsp::Hover>> + Send + '_ {
80 let uri = uri.to_string();
81 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() }
82 }
83
84 fn completion(&self, _uri: &str, _offset: usize) -> impl Future<Output = Vec<oak_lsp::types::CompletionItem>> + Send + '_ {
85 async move { vec![] }
86 }
87}