Skip to content

Commit 3fee1b0

Browse files
it works
1 parent b4c3e1f commit 3fee1b0

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

crates/pg_lsp/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
use std::{fs::File, path::PathBuf, str::FromStr, sync::Mutex};
1+
use std::{fs::File, path::PathBuf, str::FromStr};
22

33
use pg_lsp::server::LspServer;
44
use tower_lsp::{LspService, Server};
5+
use tracing_subscriber::fmt::format::FmtSpan;
56

67
#[tokio::main]
78
async fn main() -> anyhow::Result<()> {
89
let path = PathBuf::from_str("pglsp.log").expect("Opened the log file.");
910
let file = File::create(path).expect("Could not open the file.");
1011

1112
let subscriber = tracing_subscriber::FmtSubscriber::builder()
13+
.with_span_events(FmtSpan::ENTER)
14+
.with_span_events(FmtSpan::CLOSE)
1215
.with_ansi(false)
13-
.with_writer(Mutex::new(file))
16+
.with_writer(file)
1417
.finish();
1518

1619
tracing::subscriber::set_global_default(subscriber)?;

crates/pg_lsp/src/server.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl LspServer {
3939
/// When the client sends a didChangeConfiguration notification, we need to parse the received JSON.
4040
#[tracing::instrument(
4141
name = "Parsing config from client",
42-
skip(self),
42+
skip(self, value),
4343
fields(options = %value)
4444
)]
4545
async fn parse_config_from_client(
@@ -104,7 +104,7 @@ impl LspServer {
104104

105105
#[tracing::instrument(
106106
name="Publishing diagnostics",
107-
skip(self),
107+
skip(self, uri),
108108
fields(%uri)
109109
)]
110110
async fn publish_diagnostics(&self, mut uri: Url) {
@@ -138,7 +138,7 @@ impl LspServer {
138138

139139
#[tracing::instrument(
140140
name="Publishing diagnostics via Debouncer",
141-
skip(self),
141+
skip(self, uri),
142142
fields(%uri)
143143
)]
144144
async fn publish_diagnostics_debounced(&self, mut uri: Url) {
@@ -290,8 +290,8 @@ impl LanguageServer for LspServer {
290290
}
291291

292292
#[tracing::instrument(
293-
name= "textDocument/didOpen",
294-
skip(self),
293+
name = "textDocument/didOpen",
294+
skip(self, params),
295295
fields(
296296
uri = %params.text_document.uri
297297
)
@@ -318,7 +318,7 @@ impl LanguageServer for LspServer {
318318

319319
#[tracing::instrument(
320320
name= "textDocument/didSave",
321-
skip(self),
321+
skip(self, params),
322322
fields(
323323
uri = %params.text_document.uri
324324
)
@@ -333,13 +333,16 @@ impl LanguageServer for LspServer {
333333
let changed_urls = self.session.recompute_and_get_changed_files().await;
334334
for url in changed_urls {
335335
let url = Url::from_file_path(url.as_path()).expect("Expected absolute File Path");
336+
337+
tracing::info!("publishing diagnostics: {}", url);
338+
336339
self.publish_diagnostics(url).await;
337340
}
338341
}
339342

340343
#[tracing::instrument(
341344
name= "textDocument/didChange",
342-
skip(self),
345+
skip(self, params),
343346
fields(
344347
uri = %params.text_document.uri
345348
)
@@ -348,12 +351,14 @@ impl LanguageServer for LspServer {
348351
let mut uri = params.text_document.uri;
349352
normalize_uri(&mut uri);
350353

354+
tracing::info!("{}", uri);
355+
351356
self.publish_diagnostics_debounced(uri).await;
352357
}
353358

354359
#[tracing::instrument(
355360
name= "textDocument/didClose",
356-
skip(self),
361+
skip(self, params),
357362
fields(
358363
uri = %params.text_document.uri
359364
)
@@ -368,7 +373,7 @@ impl LanguageServer for LspServer {
368373

369374
#[tracing::instrument(
370375
name= "textDocument/codeAction",
371-
skip(self),
376+
skip(self, params),
372377
fields(
373378
uri = %params.text_document.uri
374379
)
@@ -393,7 +398,7 @@ impl LanguageServer for LspServer {
393398

394399
#[tracing::instrument(
395400
name= "inlayHint/resolve",
396-
skip(self),
401+
skip(self, params),
397402
fields(
398403
uri = %params.text_document.uri
399404
)
@@ -412,7 +417,7 @@ impl LanguageServer for LspServer {
412417

413418
#[tracing::instrument(
414419
name= "textDocument/completion",
415-
skip(self),
420+
skip(self, params),
416421
fields(
417422
uri = %params.text_document_position.text_document.uri
418423
)
@@ -434,7 +439,7 @@ impl LanguageServer for LspServer {
434439

435440
#[tracing::instrument(
436441
name= "textDocument/hover",
437-
skip(self),
442+
skip(self, params),
438443
fields(
439444
uri = %params.text_document_position_params.text_document.uri
440445
)

crates/pg_lsp/src/session.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl Session {
9292
// trying to collect diagnostics.
9393
let doc = ide.documents.get(&path);
9494
if doc.is_none() {
95+
tracing::info!("Doc not found, path: {:?}", &path);
9596
return vec![];
9697
}
9798

@@ -118,11 +119,6 @@ impl Session {
118119
{
119120
let ide = self.ide.read().await;
120121

121-
let doc = ide.documents.get(&path);
122-
if doc.is_none() {
123-
return HashSet::new();
124-
}
125-
126122
ide.apply_change(
127123
path,
128124
DocumentChange::new(version, vec![Change { range: None, text }]),

0 commit comments

Comments
 (0)