Skip to content

Commit 9ef30ae

Browse files
committed
temp clear push diagnostic result for pull_diagnostic
1 parent 7c685e1 commit 9ef30ae

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

crates/emmylua_ls/src/context/file_diagnostic.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{collections::HashMap, sync::Arc, time::Duration};
22

33
use emmylua_code_analysis::{EmmyLuaAnalysis, FileId, Profile};
44
use log::{debug, info};
5+
use lsp_types::{Diagnostic, Uri};
56
use tokio::sync::{Mutex, RwLock};
67
use tokio_util::sync::CancellationToken;
78

@@ -85,7 +86,7 @@ impl FileDiagnostic {
8586
}
8687

8788
/// 清除指定文件的诊断信息
88-
pub async fn clear_file_diagnostics(&self, uri: lsp_types::Uri) {
89+
pub fn clear_file_diagnostics(&self, uri: lsp_types::Uri) {
8990
let diagnostic_param = lsp_types::PublishDiagnosticsParams {
9091
uri,
9192
diagnostics: vec![],
@@ -128,6 +129,22 @@ impl FileDiagnostic {
128129
}
129130
tokens.clear();
130131
}
132+
133+
pub async fn pull_file_diagnostics(
134+
&self,
135+
uri: Uri,
136+
cancel_token: CancellationToken,
137+
) -> Vec<Diagnostic> {
138+
let analysis = self.analysis.read().await;
139+
let Some(file_id) = analysis.get_file_id(&uri) else {
140+
return vec![];
141+
};
142+
143+
self.clear_file_diagnostics(uri);
144+
145+
let diagnostics = analysis.diagnose_file(file_id, cancel_token);
146+
diagnostics.unwrap_or_default()
147+
}
131148
}
132149

133150
async fn workspace_diagnostic(

crates/emmylua_ls/src/handlers/document_diagnostic/mod.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ pub async fn on_pull_document_diagnostic(
1515
token: CancellationToken,
1616
) -> DocumentDiagnosticReportResult {
1717
let uri = params.text_document.uri;
18-
let analysis = context.analysis().read().await;
19-
let Some(file_id) = analysis.get_file_id(&uri) else {
20-
return default_diagnostic_report();
21-
};
22-
23-
let analysis = context.analysis().read().await;
24-
let diagnostics = analysis.diagnose_file(file_id, token).unwrap_or_default();
18+
let diagnostics = context
19+
.file_diagnostic()
20+
.pull_file_diagnostics(uri, token)
21+
.await;
2522

2623
DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport {
2724
related_documents: None,
@@ -33,17 +30,6 @@ pub async fn on_pull_document_diagnostic(
3330
.into()
3431
}
3532

36-
fn default_diagnostic_report() -> DocumentDiagnosticReportResult {
37-
DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport {
38-
related_documents: None,
39-
full_document_diagnostic_report: FullDocumentDiagnosticReport {
40-
result_id: None,
41-
items: vec![],
42-
},
43-
})
44-
.into()
45-
}
46-
4733
pub struct DocumentDiagnosticCapabilities;
4834

4935
impl RegisterCapabilities for DocumentDiagnosticCapabilities {

crates/emmylua_ls/src/handlers/text_document/text_document_handler.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ pub async fn on_did_close_document(
121121

122122
context
123123
.file_diagnostic()
124-
.clear_file_diagnostics(uri.clone())
125-
.await;
124+
.clear_file_diagnostics(uri.clone());
126125

127126
return Some(());
128127
}
@@ -142,8 +141,7 @@ pub async fn on_did_close_document(
142141
// 发送空诊断消息以清除客户端显示的诊断
143142
context
144143
.file_diagnostic()
145-
.clear_file_diagnostics(uri.clone())
146-
.await;
144+
.clear_file_diagnostics(uri.clone());
147145
}
148146

149147
Some(())

crates/emmylua_ls/src/handlers/text_document/watched_file_handler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ pub async fn on_did_change_watched_files(
2323
// 发送空诊断消息以清除客户端显示的诊断
2424
context
2525
.file_diagnostic()
26-
.clear_file_diagnostics(file_event.uri)
27-
.await;
26+
.clear_file_diagnostics(file_event.uri);
2827
continue;
2928
}
3029

0 commit comments

Comments
 (0)