1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use clap::Args;
use tower_lsp::{
async_trait,
jsonrpc::{self},
lsp_types::*,
Client, LanguageServer, LspService, Server,
};
use tracing::info;
#[derive(Debug, Args)]
pub struct LspCommand {}
impl LspCommand {
pub async fn run(self) -> anyhow::Result<()> {
info!("Starting server");
let stdin = tokio::io::stdin();
let stdout = tokio::io::stdout();
let (service, socket) = LspService::new(|client| StcLangServer { client });
Server::new(stdin, stdout, socket).serve(service).await;
Ok(())
}
}
pub struct StcLangServer {
#[allow(unused)]
client: Client,
}
#[async_trait]
impl LanguageServer for StcLangServer {
async fn initialize(&self, _params: InitializeParams) -> jsonrpc::Result<InitializeResult> {
Ok(InitializeResult {
capabilities: ServerCapabilities { ..Default::default() },
server_info: Some(ServerInfo {
name: "stc-ts-lsp".to_string(),
version: Some(env!("CARGO_PKG_VERSION").to_string()),
}),
})
}
async fn shutdown(&self) -> jsonrpc::Result<()> {
Ok(())
}
async fn hover(&self, _params: HoverParams) -> jsonrpc::Result<Option<Hover>> {
Ok(Some(Hover {
contents: HoverContents::Scalar(MarkedString::String("hover test".to_string())),
range: None,
}))
}
}