Skip to content

Commit b4c3e1f

Browse files
we got logging
1 parent 0a57982 commit b4c3e1f

File tree

12 files changed

+219
-71
lines changed

12 files changed

+219
-71
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ target/
1717
# File system
1818
.DS_Store
1919
desktop.ini
20+
21+
*.log

Cargo.lock

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pg_lsp/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pg_diagnostics.workspace = true
3535
tokio = { version = "1.40.0", features = ["io-std", "macros", "rt-multi-thread", "sync", "time"] }
3636
tokio-util = "0.7.12"
3737
tower-lsp = "0.20.0"
38+
tracing = "0.1.40"
39+
tracing-subscriber = "0.3.18"
3840

3941
[dev-dependencies]
4042

crates/pg_lsp/src/db_connection.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use std::sync::Arc;
2+
13
use pg_schema_cache::SchemaCache;
4+
use pg_workspace::Workspace;
25
use sqlx::{postgres::PgListener, PgPool};
3-
use tokio::task::JoinHandle;
6+
use tokio::{sync::RwLock, task::JoinHandle};
47

58
pub(crate) struct DbConnection {
69
pool: PgPool,
@@ -10,13 +13,10 @@ pub(crate) struct DbConnection {
1013
}
1114

1215
impl DbConnection {
13-
pub(crate) async fn new<F>(
16+
pub(crate) async fn new(
1417
connection_string: String,
15-
on_schema_update: F,
16-
) -> Result<Self, sqlx::Error>
17-
where
18-
F: Fn(SchemaCache) -> () + Send + 'static,
19-
{
18+
ide: Arc<RwLock<Workspace>>,
19+
) -> Result<Self, sqlx::Error> {
2020
let pool = PgPool::connect(&connection_string).await?;
2121

2222
let mut listener = PgListener::connect_with(&pool).await?;
@@ -36,7 +36,7 @@ impl DbConnection {
3636
Ok(not) => {
3737
if not.payload().to_string() == "reload schema" {
3838
let schema_cache = SchemaCache::load(&cloned_pool).await;
39-
on_schema_update(schema_cache);
39+
ide.write().await.set_schema_cache(schema_cache);
4040
};
4141
}
4242
Err(why) => {

crates/pg_lsp/src/debouncer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ impl SimpleTokioDebouncer {
6161
}
6262
}
6363

64+
#[tracing::instrument(name = "Adding task to debouncer", skip(self, block))]
6465
pub async fn debounce(&self, block: AsyncBlock) {
6566
if self
6667
.shutdown_flag
6768
.load(std::sync::atomic::Ordering::Relaxed)
6869
{
69-
println!(
70+
tracing::error!(
7071
"Trying to debounce tasks, but the Debouncer is in the process of shutting down."
7172
);
7273
return;
@@ -75,6 +76,7 @@ impl SimpleTokioDebouncer {
7576
self.tx.send(block).await.unwrap();
7677
}
7778

79+
#[tracing::instrument(name = "Shutting down debouncer", skip(self))]
7880
pub async fn shutdown(&self) {
7981
self.shutdown_flag
8082
.store(true, std::sync::atomic::Ordering::Relaxed);

crates/pg_lsp/src/main.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
use std::{fs::File, path::PathBuf, str::FromStr, sync::Mutex};
2+
13
use pg_lsp::server::LspServer;
24
use tower_lsp::{LspService, Server};
35

46
#[tokio::main]
5-
async fn main() {
7+
async fn main() -> anyhow::Result<()> {
8+
let path = PathBuf::from_str("pglsp.log").expect("Opened the log file.");
9+
let file = File::create(path).expect("Could not open the file.");
10+
11+
let subscriber = tracing_subscriber::FmtSubscriber::builder()
12+
.with_ansi(false)
13+
.with_writer(Mutex::new(file))
14+
.finish();
15+
16+
tracing::subscriber::set_global_default(subscriber)?;
17+
618
let stdin = tokio::io::stdin();
719
let stdout = tokio::io::stdout();
820

21+
tracing::info!("Starting server.");
22+
923
let (service, socket) = LspService::new(|client| LspServer::new(client));
1024

1125
Server::new(stdin, stdout, socket).serve(service).await;
26+
27+
Ok(())
1228
}

0 commit comments

Comments
 (0)