mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-08 11:20:37 +00:00
fix: Resolve compilation errors and improve diagnostics handling
This commit is contained in:
parent
8f448508d0
commit
085627fe32
3 changed files with 24 additions and 18 deletions
|
@ -7,20 +7,27 @@ 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()
|
||||
});
|
||||
// Simple example: Check for TODO comments
|
||||
for (line_num, line) in document.get_text().lines().enumerate() {
|
||||
if let Some(col) = line.find("TODO") {
|
||||
diagnostics.push(Diagnostic {
|
||||
range: Range {
|
||||
start: Position {
|
||||
line: line_num as u32,
|
||||
character: col as u32
|
||||
},
|
||||
end: Position {
|
||||
line: line_num as u32,
|
||||
character: (col + 4) as u32
|
||||
},
|
||||
},
|
||||
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
|
||||
|
|
|
@ -7,7 +7,7 @@ use tower_lsp::lsp_types::{
|
|||
Documentation, InsertTextFormat, MarkupContent, MarkupKind, NumberOrString, Position, Range, Url,
|
||||
};
|
||||
use tower_lsp::Client;
|
||||
use crate::diagnostics::Diagnostics;
|
||||
use super::diagnostics::Diagnostics;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Store {
|
||||
|
@ -32,7 +32,7 @@ impl Store {
|
|||
);
|
||||
|
||||
self.add_document(document);
|
||||
self.publish_diagnostics(¶ms.text_document.uri, client);
|
||||
self.publish_diagnostics(params.text_document.uri.as_str(), client);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -110,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(), &self.client).await {
|
||||
if let Err(e) = self.documents.write().await.handle_did_open(params.clone(), &self.client) {
|
||||
eprintln!("Error handling document open: {}", e);
|
||||
return;
|
||||
}
|
||||
|
@ -129,7 +129,6 @@ impl LanguageServer for DjangoLanguageServer {
|
|||
.write()
|
||||
.await
|
||||
.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