78 lines
3.0 KiB
Rust
78 lines
3.0 KiB
Rust
use std::sync::Arc;
|
|
use tokio::sync::RwLock;
|
|
use tower_lsp::{LspService, Server};
|
|
|
|
mod analysis_db;
|
|
mod rebuild;
|
|
|
|
use analysis_db::SharedDb;
|
|
|
|
struct Backend {
|
|
db: SharedDb,
|
|
}
|
|
|
|
#[tower_lsp::async_trait]
|
|
impl tower_lsp::LanguageServer for Backend {
|
|
async fn initialize(
|
|
&self,
|
|
_: tower_lsp::lsp_types::InitializeParams,
|
|
) -> tower_lsp::jsonrpc::Result<tower_lsp::lsp_types::InitializeResult> {
|
|
Ok(tower_lsp::lsp_types::InitializeResult {
|
|
capabilities: tower_lsp::lsp_types::ServerCapabilities {
|
|
text_document_sync: Some(
|
|
tower_lsp::lsp_types::TextDocumentSyncCapability::Kind(
|
|
tower_lsp::lsp_types::TextDocumentSyncKind::FULL,
|
|
),
|
|
),
|
|
// Declaramos capacidades desde já para evitar churn posterior.
|
|
definition_provider: Some(tower_lsp::lsp_types::OneOf::Left(true)),
|
|
document_symbol_provider: Some(tower_lsp::lsp_types::OneOf::Left(true)),
|
|
workspace_symbol_provider: Some(tower_lsp::lsp_types::OneOf::Left(true)),
|
|
hover_provider: Some(true.into()),
|
|
references_provider: Some(tower_lsp::lsp_types::OneOf::Left(true)),
|
|
rename_provider: Some(tower_lsp::lsp_types::OneOf::Left(true)),
|
|
completion_provider: Some(tower_lsp::lsp_types::CompletionOptions {
|
|
resolve_provider: Some(false),
|
|
trigger_characters: Some(vec![".".into(), ":".into()]),
|
|
..Default::default()
|
|
}),
|
|
semantic_tokens_provider: Some(
|
|
tower_lsp::lsp_types::SemanticTokensServerCapabilities::SemanticTokensOptions(
|
|
tower_lsp::lsp_types::SemanticTokensOptions {
|
|
legend: tower_lsp::lsp_types::SemanticTokensLegend {
|
|
// preenchido no PR-12
|
|
token_types: vec![],
|
|
token_modifiers: vec![],
|
|
},
|
|
full: Some(
|
|
tower_lsp::lsp_types::SemanticTokensFullOptions::Bool(true),
|
|
),
|
|
range: None,
|
|
..Default::default()
|
|
},
|
|
),
|
|
),
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
})
|
|
}
|
|
|
|
async fn initialized(&self, _: tower_lsp::lsp_types::InitializedParams) {}
|
|
|
|
async fn shutdown(&self) -> tower_lsp::jsonrpc::Result<()> {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let stdin = tokio::io::stdin();
|
|
let stdout = tokio::io::stdout();
|
|
|
|
let db: SharedDb = Arc::new(RwLock::new(analysis_db::AnalysisDb::default()));
|
|
|
|
let (service, socket) = LspService::new(|_client| Backend { db: db.clone() });
|
|
Server::new(stdin, stdout, socket).serve(service).await;
|
|
}
|