-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove extra server layer in front of tower-lsp's server (#49)
- Loading branch information
1 parent
9a2c0e5
commit f848798
Showing
5 changed files
with
149 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,19 @@ | ||
mod documents; | ||
mod notifier; | ||
mod server; | ||
mod tasks; | ||
|
||
use crate::notifier::TowerLspNotifier; | ||
use crate::server::{DjangoLanguageServer, LspNotification, LspRequest}; | ||
use crate::server::DjangoLanguageServer; | ||
use anyhow::Result; | ||
use server::LspResponse; | ||
use std::sync::Arc; | ||
use tokio::sync::RwLock; | ||
use tower_lsp::jsonrpc::Result as LspResult; | ||
use tower_lsp::lsp_types::*; | ||
use tower_lsp::{LanguageServer, LspService, Server}; | ||
|
||
struct TowerLspBackend { | ||
server: Arc<RwLock<DjangoLanguageServer>>, | ||
} | ||
|
||
#[tower_lsp::async_trait] | ||
impl LanguageServer for TowerLspBackend { | ||
async fn initialize(&self, params: InitializeParams) -> LspResult<InitializeResult> { | ||
match self | ||
.server | ||
.write() | ||
.await | ||
.handle_request(LspRequest::Initialize(params)) | ||
.map_err(|_| tower_lsp::jsonrpc::Error::internal_error())? | ||
{ | ||
LspResponse::Initialize(result) => Ok(result), | ||
_ => Err(tower_lsp::jsonrpc::Error::internal_error()), | ||
} | ||
} | ||
|
||
async fn initialized(&self, params: InitializedParams) { | ||
if let Err(e) = self | ||
.server | ||
.write() | ||
.await | ||
.handle_notification(LspNotification::Initialized(params)) | ||
{ | ||
eprintln!("Error handling initialized: {}", e); | ||
} | ||
} | ||
|
||
async fn shutdown(&self) -> LspResult<()> { | ||
self.server | ||
.write() | ||
.await | ||
.handle_notification(LspNotification::Shutdown) | ||
.map_err(|_| tower_lsp::jsonrpc::Error::internal_error()) | ||
} | ||
|
||
async fn did_open(&self, params: DidOpenTextDocumentParams) { | ||
if let Err(e) = self | ||
.server | ||
.write() | ||
.await | ||
.handle_notification(LspNotification::DidOpenTextDocument(params)) | ||
{ | ||
eprintln!("Error handling document open: {}", e); | ||
} | ||
} | ||
|
||
async fn did_change(&self, params: DidChangeTextDocumentParams) { | ||
if let Err(e) = self | ||
.server | ||
.write() | ||
.await | ||
.handle_notification(LspNotification::DidChangeTextDocument(params)) | ||
{ | ||
eprintln!("Error handling document change: {}", e); | ||
} | ||
} | ||
|
||
async fn did_close(&self, params: DidCloseTextDocumentParams) { | ||
if let Err(e) = self | ||
.server | ||
.write() | ||
.await | ||
.handle_notification(LspNotification::DidCloseTextDocument(params)) | ||
{ | ||
eprintln!("Error handling document close: {}", e); | ||
} | ||
} | ||
|
||
async fn completion(&self, params: CompletionParams) -> LspResult<Option<CompletionResponse>> { | ||
match self | ||
.server | ||
.write() | ||
.await | ||
.handle_request(LspRequest::Completion(params)) | ||
.map_err(|_| tower_lsp::jsonrpc::Error::internal_error())? | ||
{ | ||
LspResponse::Completion(result) => Ok(result), | ||
_ => Err(tower_lsp::jsonrpc::Error::internal_error()), | ||
} | ||
} | ||
} | ||
|
||
pub async fn serve() -> Result<()> { | ||
let stdin = tokio::io::stdin(); | ||
let stdout = tokio::io::stdout(); | ||
|
||
let (service, socket) = LspService::build(|client| { | ||
let notifier = Box::new(TowerLspNotifier::new(client.clone())); | ||
let server = DjangoLanguageServer::new(notifier); | ||
TowerLspBackend { | ||
server: Arc::new(RwLock::new(server)), | ||
} | ||
}) | ||
.finish(); | ||
let (service, socket) = tower_lsp::LspService::build(DjangoLanguageServer::new).finish(); | ||
|
||
Server::new(stdin, stdout, socket).serve(service).await; | ||
tower_lsp::Server::new(stdin, stdout, socket) | ||
.serve(service) | ||
.await; | ||
|
||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.