Skip to content

Commit 12a079e

Browse files
diagnostics
1 parent 5e4e89e commit 12a079e

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

crates/pg_lsp/src/b_server.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::client::client_flags::ClientFlags;
99
use crate::server::options::ClientConfigurationOptions;
1010
use crate::utils::file_path;
1111
use crate::utils::normalize_uri;
12+
use crate::utils::to_proto;
1213
use crate::workspace_handler::WorkspaceHandler;
1314

1415
struct Server {
@@ -87,28 +88,33 @@ impl Server {
8788
}
8889
}
8990

90-
async fn publish_diagnostics(&self, mut uri: Url) -> anyhow::Result<()> {
91+
async fn publish_diagnostics(&self, mut uri: Url) {
9192
normalize_uri(&mut uri);
9293

9394
let diagnostics = self
9495
.workspace_handler
9596
.get_diagnostics(file_path(&uri))
9697
.await;
9798

99+
let diagnostics: Vec<Diagnostic> = diagnostics
100+
.into_iter()
101+
.map(|(d, r)| to_proto::diagnostic(d, r))
102+
.collect();
103+
98104
self.client
99105
.send_notification::<ShowMessage>(ShowMessageParams {
100106
typ: MessageType::INFO,
101107
message: format!("diagnostics {}", diagnostics.len()),
102-
})
103-
.await;
108+
});
104109

105110
let params = PublishDiagnosticsParams {
106111
uri,
107112
diagnostics,
108113
version: None,
109114
};
110115

111-
Ok(())
116+
self.client
117+
.send_notification::<notification::PublishDiagnostics>(params);
112118
}
113119
}
114120

crates/pg_lsp/src/utils/line_index_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use line_index::{LineCol, LineColUtf16, LineIndex};
2-
use lsp_types::{Position, Range};
32
use text_size::{TextRange, TextSize};
3+
use tower_lsp::lsp_types::{Position, Range};
44

55
pub trait LineIndexExt {
66
fn offset_lsp(&self, line_col: Position) -> Option<TextSize>;

crates/pg_lsp/src/utils/to_proto.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use pg_base_db::Document;
21
use pg_diagnostics::Diagnostic;
2+
use tower_lsp::lsp_types;
33

4-
use super::line_index_ext::LineIndexExt;
5-
6-
pub fn diagnostic(document: &Document, diagnostic: &Diagnostic) -> lsp_types::Diagnostic {
4+
pub fn diagnostic(diagnostic: Diagnostic, range: lsp_types::Range) -> lsp_types::Diagnostic {
75
let severity = match diagnostic.severity {
86
pg_diagnostics::Severity::Error => lsp_types::DiagnosticSeverity::ERROR,
97
pg_diagnostics::Severity::Warning => lsp_types::DiagnosticSeverity::WARNING,
@@ -12,14 +10,9 @@ pub fn diagnostic(document: &Document, diagnostic: &Diagnostic) -> lsp_types::Di
1210
pg_diagnostics::Severity::Fatal => lsp_types::DiagnosticSeverity::ERROR,
1311
};
1412

15-
let range = document
16-
.line_index
17-
.line_col_lsp_range(diagnostic.range)
18-
.unwrap();
19-
2013
lsp_types::Diagnostic {
2114
severity: Some(severity),
22-
source: Some(diagnostic.source.clone()),
23-
..lsp_types::Diagnostic::new_simple(range, diagnostic.message.clone())
15+
source: Some(diagnostic.source),
16+
..lsp_types::Diagnostic::new_simple(range, diagnostic.message)
2417
}
2518
}

crates/pg_lsp/src/workspace_handler.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use std::sync::Arc;
22

3-
use lsp_types::Range;
43
use pg_base_db::PgLspPath;
54
use pg_diagnostics::Diagnostic;
65
use pg_workspace::Workspace;
7-
use text_size::TextRange;
86
use tokio::sync::RwLock;
7+
use tower_lsp::lsp_types::Range;
98

109
use crate::{db_connection::DbConnection, utils::line_index_ext::LineIndexExt};
1110

@@ -82,7 +81,12 @@ impl WorkspaceHandler {
8281
.diagnostics(&path)
8382
.into_iter()
8483
.map(|d| {
85-
let range = doc.as_ref().unwrap().line_index.line_col_lsp_range(d.range).unwrap();
84+
let range = doc
85+
.as_ref()
86+
.unwrap()
87+
.line_index
88+
.line_col_lsp_range(d.range)
89+
.unwrap();
8690
(d, range)
8791
})
8892
.collect()

0 commit comments

Comments
 (0)