Skip to main content

oak_graphql/lsp/
mod.rs

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