mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-11 04:46:38 +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> {
|
pub fn generate_for_document(document: &TextDocument) -> Vec<Diagnostic> {
|
||||||
let mut diagnostics = Vec::new();
|
let mut diagnostics = Vec::new();
|
||||||
|
|
||||||
// TODO: Add actual diagnostic logic here
|
// Simple example: Check for TODO comments
|
||||||
// For now, let's just add a placeholder diagnostic
|
for (line_num, line) in document.get_text().lines().enumerate() {
|
||||||
if document.get_text().contains("TODO") {
|
if let Some(col) = line.find("TODO") {
|
||||||
diagnostics.push(Diagnostic {
|
diagnostics.push(Diagnostic {
|
||||||
range: Range {
|
range: Range {
|
||||||
start: Position { line: 0, character: 0 },
|
start: Position {
|
||||||
end: Position { line: 0, character: 5 },
|
line: line_num as u32,
|
||||||
},
|
character: col as u32
|
||||||
severity: Some(DiagnosticSeverity::INFORMATION),
|
},
|
||||||
code: Some(NumberOrString::String("django.todo".to_string())),
|
end: Position {
|
||||||
source: Some("Django LSP".to_string()),
|
line: line_num as u32,
|
||||||
message: "Found TODO comment".to_string(),
|
character: (col + 4) as u32
|
||||||
..Default::default()
|
},
|
||||||
});
|
},
|
||||||
|
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
|
diagnostics
|
||||||
|
|
|
@ -7,7 +7,7 @@ use tower_lsp::lsp_types::{
|
||||||
Documentation, InsertTextFormat, MarkupContent, MarkupKind, NumberOrString, Position, Range, Url,
|
Documentation, InsertTextFormat, MarkupContent, MarkupKind, NumberOrString, Position, Range, Url,
|
||||||
};
|
};
|
||||||
use tower_lsp::Client;
|
use tower_lsp::Client;
|
||||||
use crate::diagnostics::Diagnostics;
|
use super::diagnostics::Diagnostics;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
|
@ -32,7 +32,7 @@ impl Store {
|
||||||
);
|
);
|
||||||
|
|
||||||
self.add_document(document);
|
self.add_document(document);
|
||||||
self.publish_diagnostics(¶ms.text_document.uri, client);
|
self.publish_diagnostics(params.text_document.uri.as_str(), client);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,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(), &self.client).await {
|
if let Err(e) = self.documents.write().await.handle_did_open(params.clone(), &self.client) {
|
||||||
eprintln!("Error handling document open: {}", e);
|
eprintln!("Error handling document open: {}", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,6 @@ impl LanguageServer for DjangoLanguageServer {
|
||||||
.write()
|
.write()
|
||||||
.await
|
.await
|
||||||
.handle_did_change(params.clone(), &self.client)
|
.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