mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-14 14:25:36 +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 djls_project::TemplateTags;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use tower_lsp::lsp_types::{
|
use tower_lsp::lsp_types::{
|
||||||
CompletionItem, CompletionItemKind, CompletionResponse, DidChangeTextDocumentParams,
|
CompletionItem, CompletionItemKind, CompletionResponse, Diagnostic, DiagnosticSeverity,
|
||||||
DidCloseTextDocumentParams, DidOpenTextDocumentParams, Documentation, InsertTextFormat,
|
DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams,
|
||||||
MarkupContent, MarkupKind, Position, Range,
|
Documentation, InsertTextFormat, MarkupContent, MarkupKind, NumberOrString, Position, Range, Url,
|
||||||
};
|
};
|
||||||
|
use tower_lsp::Client;
|
||||||
|
use crate::diagnostics::Diagnostics;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
|
|
|
@ -81,6 +81,14 @@ impl LanguageServer for DjangoLanguageServer {
|
||||||
save: Some(SaveOptions::default().into()),
|
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()
|
..Default::default()
|
||||||
},
|
},
|
||||||
server_info: Some(ServerInfo {
|
server_info: Some(ServerInfo {
|
||||||
|
@ -102,7 +110,7 @@ impl LanguageServer for DjangoLanguageServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn did_open(&self, params: DidOpenTextDocumentParams) {
|
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);
|
eprintln!("Error handling document open: {}", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +128,8 @@ impl LanguageServer for DjangoLanguageServer {
|
||||||
.documents
|
.documents
|
||||||
.write()
|
.write()
|
||||||
.await
|
.await
|
||||||
.handle_did_change(params.clone())
|
.handle_did_change(params.clone(), &self.client)
|
||||||
|
.await
|
||||||
{
|
{
|
||||||
eprintln!("Error handling document change: {}", e);
|
eprintln!("Error handling document change: {}", e);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue