add initial autocomplete for installed templatetags (#46)

This commit is contained in:
Josh Thomas 2024-12-23 19:36:54 -06:00 committed by GitHub
parent 5eb8a775e4
commit c16635b1c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 359 additions and 58 deletions

View file

@ -6,6 +6,7 @@ mod tasks;
use crate::notifier::TowerLspNotifier;
use crate::server::{DjangoLanguageServer, LspNotification, LspRequest};
use anyhow::Result;
use server::LspResponse;
use std::sync::Arc;
use tokio::sync::RwLock;
use tower_lsp::jsonrpc::Result as LspResult;
@ -19,11 +20,16 @@ struct TowerLspBackend {
#[tower_lsp::async_trait]
impl LanguageServer for TowerLspBackend {
async fn initialize(&self, params: InitializeParams) -> LspResult<InitializeResult> {
self.server
.read()
match self
.server
.write()
.await
.handle_request(LspRequest::Initialize(params))
.map_err(|_| tower_lsp::jsonrpc::Error::internal_error())
.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) {
@ -77,6 +83,19 @@ impl LanguageServer for TowerLspBackend {
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<()> {