gluon_language_server/command/
initialize.rs1use jsonrpc_core::IoHandler;
2
3use lsp_types::{
4 CompletionOptions, InitializeError, InitializeParams, InitializeResult, ServerCapabilities,
5 ServerInfo, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind,
6 WorkDoneProgressOptions,
7};
8
9use crate::{rpc::LanguageServerCommand, BoxFuture};
10
11use super::*;
12
13struct Initialize(RootedThread);
14impl LanguageServerCommand<InitializeParams> for Initialize {
15 type Future = BoxFuture<Self::Output, ServerError<Self::Error>>;
16 type Output = InitializeResult;
17 type Error = InitializeError;
18 fn execute(
19 &self,
20 change: InitializeParams,
21 ) -> BoxFuture<InitializeResult, ServerError<InitializeError>> {
22 let thread = self.0.clone();
23 async move {
24 let import = thread.get_macros().get("import").expect("Import macro");
25 let import = import
26 .downcast_ref::<Import<CheckImporter>>()
27 .expect("Check importer");
28 if let Some(ref uri) = change.root_uri {
29 import.add_path(
30 uri.to_file_path()
31 .map_err(|()| "Unable to convert root_uri to file path")?,
32 );
33 }
34
35 Ok(InitializeResult {
36 server_info: Some(ServerInfo {
37 name: "Gluon language server".into(),
38 version: Some(match option_env!("GIT_COMMIT") {
39 Some(git_commit) => format!("{}-{}", env!("CARGO_PKG_VERSION"), git_commit),
40 None => env!("CARGO_PKG_VERSION").into(),
41 }),
42 }),
43 capabilities: ServerCapabilities {
44 text_document_sync: Some(TextDocumentSyncCapability::Kind(
45 TextDocumentSyncKind::Incremental,
46 )),
47 completion_provider: Some(CompletionOptions {
48 resolve_provider: Some(true),
49 trigger_characters: Some(vec![".".into()]),
50 work_done_progress_options: WorkDoneProgressOptions {
51 work_done_progress: None,
52 },
53 all_commit_characters: None,
54 }),
55 signature_help_provider: Some(SignatureHelpOptions {
56 trigger_characters: None,
57 retrigger_characters: None,
58 work_done_progress_options: WorkDoneProgressOptions {
59 work_done_progress: None,
60 },
61 }),
62 hover_provider: Some(true.into()),
63 document_formatting_provider: Some(lsp_types::OneOf::Left(true)),
64 document_highlight_provider: Some(lsp_types::OneOf::Left(true)),
65 document_symbol_provider: Some(lsp_types::OneOf::Left(true)),
66 workspace_symbol_provider: Some(lsp_types::OneOf::Left(true)),
67 definition_provider: Some(lsp_types::OneOf::Left(true)),
68 ..ServerCapabilities::default()
69 },
70 })
71 }
72 .boxed()
73 }
74
75 fn invalid_params(&self) -> Option<Self::Error> {
76 Some(InitializeError { retry: false })
77 }
78}
79
80pub fn register(io: &mut IoHandler, thread: &RootedThread) {
81 io.add_async_method(request!("initialize"), Initialize(thread.clone()));
82}