mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-13 13:56:25 +00:00
feat: add basic diagnostic support for TODO comments
This commit is contained in:
parent
00b8849189
commit
1d1f4f6c0f
3 changed files with 44 additions and 5 deletions
28
crates/djls-server/src/diagnostics.rs
Normal file
28
crates/djls-server/src/diagnostics.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use tower_lsp::lsp_types::*;
|
||||
use crate::documents::TextDocument;
|
||||
|
||||
pub struct Diagnostics;
|
||||
|
||||
impl Diagnostics {
|
||||
pub fn generate_for_document(document: &TextDocument) -> Vec<Diagnostic> {
|
||||
let mut diagnostics = Vec::new();
|
||||
|
||||
// TODO: Add actual diagnostic logic here
|
||||
// For now, let's just add a placeholder diagnostic
|
||||
if document.get_text().contains("TODO") {
|
||||
diagnostics.push(Diagnostic {
|
||||
range: Range {
|
||||
start: Position { line: 0, character: 0 },
|
||||
end: Position { line: 0, character: 5 },
|
||||
},
|
||||
severity: Some(DiagnosticSeverity::INFORMATION),
|
||||
code: Some(NumberOrString::String("django.todo".to_string())),
|
||||
source: Some("Django LSP".to_string()),
|
||||
message: "Found TODO comment".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
diagnostics
|
||||
}
|
||||
}
|
|
@ -2,10 +2,12 @@ use anyhow::{anyhow, Result};
|
|||
use djls_project::TemplateTags;
|
||||
use std::collections::HashMap;
|
||||
use tower_lsp::lsp_types::{
|
||||
CompletionItem, CompletionItemKind, CompletionResponse, DidChangeTextDocumentParams,
|
||||
DidCloseTextDocumentParams, DidOpenTextDocumentParams, Documentation, InsertTextFormat,
|
||||
MarkupContent, MarkupKind, Position, Range,
|
||||
CompletionItem, CompletionItemKind, CompletionResponse, Diagnostic, DiagnosticSeverity,
|
||||
DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams,
|
||||
Documentation, InsertTextFormat, MarkupContent, MarkupKind, NumberOrString, Position, Range, Url,
|
||||
};
|
||||
use tower_lsp::Client;
|
||||
use crate::diagnostics::Diagnostics;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Store {
|
||||
|
|
|
@ -81,6 +81,14 @@ impl LanguageServer for DjangoLanguageServer {
|
|||
save: Some(SaveOptions::default().into()),
|
||||
},
|
||||
)),
|
||||
diagnostic_provider: Some(DiagnosticServerCapabilities::Options(DiagnosticOptions {
|
||||
identifier: Some("django".to_string()),
|
||||
inter_file_dependencies: false,
|
||||
workspace_diagnostics: false,
|
||||
work_done_progress_options: WorkDoneProgressOptions {
|
||||
work_done_progress: Some(true),
|
||||
},
|
||||
})),
|
||||
..Default::default()
|
||||
},
|
||||
server_info: Some(ServerInfo {
|
||||
|
@ -102,7 +110,7 @@ impl LanguageServer for DjangoLanguageServer {
|
|||
}
|
||||
|
||||
async fn did_open(&self, params: DidOpenTextDocumentParams) {
|
||||
if let Err(e) = self.documents.write().await.handle_did_open(params.clone()) {
|
||||
if let Err(e) = self.documents.write().await.handle_did_open(params.clone(), &self.client).await {
|
||||
eprintln!("Error handling document open: {}", e);
|
||||
return;
|
||||
}
|
||||
|
@ -120,7 +128,8 @@ impl LanguageServer for DjangoLanguageServer {
|
|||
.documents
|
||||
.write()
|
||||
.await
|
||||
.handle_did_change(params.clone())
|
||||
.handle_did_change(params.clone(), &self.client)
|
||||
.await
|
||||
{
|
||||
eprintln!("Error handling document change: {}", e);
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue