Skip to content

Commit f848798

Browse files
remove extra server layer in front of tower-lsp's server (#49)
1 parent 9a2c0e5 commit f848798

File tree

5 files changed

+149
-323
lines changed

5 files changed

+149
-323
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Install dependencies and build
3939
run: |
4040
uv sync --frozen
41-
maturin build
41+
uv run maturin build
4242
4343
- name: Run tests
4444
run: cargo test --verbose

crates/djls-server/src/lib.rs

Lines changed: 5 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,19 @@
11
mod documents;
2-
mod notifier;
32
mod server;
43
mod tasks;
54

6-
use crate::notifier::TowerLspNotifier;
7-
use crate::server::{DjangoLanguageServer, LspNotification, LspRequest};
5+
use crate::server::DjangoLanguageServer;
86
use anyhow::Result;
9-
use server::LspResponse;
10-
use std::sync::Arc;
11-
use tokio::sync::RwLock;
12-
use tower_lsp::jsonrpc::Result as LspResult;
13-
use tower_lsp::lsp_types::*;
14-
use tower_lsp::{LanguageServer, LspService, Server};
15-
16-
struct TowerLspBackend {
17-
server: Arc<RwLock<DjangoLanguageServer>>,
18-
}
19-
20-
#[tower_lsp::async_trait]
21-
impl LanguageServer for TowerLspBackend {
22-
async fn initialize(&self, params: InitializeParams) -> LspResult<InitializeResult> {
23-
match self
24-
.server
25-
.write()
26-
.await
27-
.handle_request(LspRequest::Initialize(params))
28-
.map_err(|_| tower_lsp::jsonrpc::Error::internal_error())?
29-
{
30-
LspResponse::Initialize(result) => Ok(result),
31-
_ => Err(tower_lsp::jsonrpc::Error::internal_error()),
32-
}
33-
}
34-
35-
async fn initialized(&self, params: InitializedParams) {
36-
if let Err(e) = self
37-
.server
38-
.write()
39-
.await
40-
.handle_notification(LspNotification::Initialized(params))
41-
{
42-
eprintln!("Error handling initialized: {}", e);
43-
}
44-
}
45-
46-
async fn shutdown(&self) -> LspResult<()> {
47-
self.server
48-
.write()
49-
.await
50-
.handle_notification(LspNotification::Shutdown)
51-
.map_err(|_| tower_lsp::jsonrpc::Error::internal_error())
52-
}
53-
54-
async fn did_open(&self, params: DidOpenTextDocumentParams) {
55-
if let Err(e) = self
56-
.server
57-
.write()
58-
.await
59-
.handle_notification(LspNotification::DidOpenTextDocument(params))
60-
{
61-
eprintln!("Error handling document open: {}", e);
62-
}
63-
}
64-
65-
async fn did_change(&self, params: DidChangeTextDocumentParams) {
66-
if let Err(e) = self
67-
.server
68-
.write()
69-
.await
70-
.handle_notification(LspNotification::DidChangeTextDocument(params))
71-
{
72-
eprintln!("Error handling document change: {}", e);
73-
}
74-
}
75-
76-
async fn did_close(&self, params: DidCloseTextDocumentParams) {
77-
if let Err(e) = self
78-
.server
79-
.write()
80-
.await
81-
.handle_notification(LspNotification::DidCloseTextDocument(params))
82-
{
83-
eprintln!("Error handling document close: {}", e);
84-
}
85-
}
86-
87-
async fn completion(&self, params: CompletionParams) -> LspResult<Option<CompletionResponse>> {
88-
match self
89-
.server
90-
.write()
91-
.await
92-
.handle_request(LspRequest::Completion(params))
93-
.map_err(|_| tower_lsp::jsonrpc::Error::internal_error())?
94-
{
95-
LspResponse::Completion(result) => Ok(result),
96-
_ => Err(tower_lsp::jsonrpc::Error::internal_error()),
97-
}
98-
}
99-
}
1007

1018
pub async fn serve() -> Result<()> {
1029
let stdin = tokio::io::stdin();
10310
let stdout = tokio::io::stdout();
10411

105-
let (service, socket) = LspService::build(|client| {
106-
let notifier = Box::new(TowerLspNotifier::new(client.clone()));
107-
let server = DjangoLanguageServer::new(notifier);
108-
TowerLspBackend {
109-
server: Arc::new(RwLock::new(server)),
110-
}
111-
})
112-
.finish();
12+
let (service, socket) = tower_lsp::LspService::build(DjangoLanguageServer::new).finish();
11313

114-
Server::new(stdin, stdout, socket).serve(service).await;
14+
tower_lsp::Server::new(stdin, stdout, socket)
15+
.serve(service)
16+
.await;
11517

11618
Ok(())
11719
}

crates/djls-server/src/notifier.rs

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)