Skip to content

Commit 218d6b7

Browse files
authored
Merge pull request #146 from supabase-community/refactor/pglsp
refactor: move PgLspPath into pg_fs crate
2 parents b930638 + 7f4c516 commit 218d6b7

File tree

15 files changed

+122
-10
lines changed

15 files changed

+122
-10
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ rust-version = "1.71"
1414
line_index = { path = "./lib/line_index", version = "0.0.0" }
1515
tree_sitter_sql = { path = "./lib/tree_sitter_sql", version = "0.0.0" }
1616
tree-sitter = "0.20.10"
17+
tracing = "0.1.40"
1718

1819
# postgres specific crates
1920
pg_lexer = { path = "./crates/pg_lexer", version = "0.0.0" }
21+
pg_fs = { path = "./crates/pg_fs", version = "0.0.0" }
2022
pg_diagnostics = { path = "./crates/pg_diagnostics", version = "0.0.0" }
2123
pg_lexer_codegen = { path = "./crates/pg_lexer_codegen", version = "0.0.0" }
2224
pg_statement_splitter = { path = "./crates/pg_statement_splitter", version = "0.0.0" }

crates/pg_base_db/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ text-size = "1.1.1"
88
line_index.workspace = true
99

1010
pg_statement_splitter.workspace = true
11+
pg_fs.workspace = true
1112

1213
[dev-dependencies]
1314

crates/pg_base_db/src/change.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ impl DocumentChange {
291291
mod tests {
292292
use text_size::{TextRange, TextSize};
293293

294-
use crate::{change::Change, document::StatementRef, Document, DocumentChange, PgLspPath};
294+
use crate::{change::Change, document::StatementRef, Document, DocumentChange};
295+
use pg_fs::PgLspPath;
295296

296297
#[test]
297298
fn test_document_apply_changes() {

crates/pg_base_db/src/document.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{hash::Hash, hash::Hasher, ops::RangeBounds};
33
use line_index::LineIndex;
44
use text_size::{TextRange, TextSize};
55

6-
use crate::PgLspPath;
6+
use pg_fs::PgLspPath;
77

88
extern crate test;
99

@@ -163,8 +163,9 @@ impl Document {
163163
mod tests {
164164

165165
use text_size::{TextRange, TextSize};
166+
use pg_fs::PgLspPath;
166167

167-
use crate::{Document, PgLspPath};
168+
use crate::{Document};
168169

169170
#[test]
170171
fn test_statements_at_range() {

crates/pg_base_db/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
mod change;
1717
mod document;
18-
mod path;
1918

2019
pub use change::{Change, ChangedStatement, DocumentChange, StatementChange};
2120
pub use document::{Document, StatementRef};
22-
pub use path::PgLspPath;

crates/pg_fs/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "pg_fs"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
directories = "5.0.1"
8+
tracing = { workspace = true }
9+
10+
[dev-dependencies]
11+
12+
[lib]
13+
doctest = false
14+
15+
[features]

crates/pg_fs/src/dir.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use directories::ProjectDirs;
2+
use std::{env, fs, path::PathBuf};
3+
use tracing::warn;
4+
5+
pub fn ensure_cache_dir() -> PathBuf {
6+
if let Some(proj_dirs) = ProjectDirs::from("dev", "supabase-community", "pglsp") {
7+
// Linux: /home/alice/.cache/biome
8+
// Win: C:\Users\Alice\AppData\Local\biomejs\biome\cache
9+
// Mac: /Users/Alice/Library/Caches/dev.biomejs.biome
10+
let cache_dir = proj_dirs.cache_dir().to_path_buf();
11+
if let Err(err) = fs::create_dir_all(&cache_dir) {
12+
let temp_dir = env::temp_dir();
13+
warn!("Failed to create local cache directory {cache_dir:?} due to error: {err}, fallback to {temp_dir:?}");
14+
temp_dir
15+
} else {
16+
cache_dir
17+
}
18+
} else {
19+
env::temp_dir()
20+
}
21+
}

crates/pg_fs/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! # pg_fs
2+
3+
mod dir;
4+
mod path;
5+
6+
pub use dir::ensure_cache_dir;
7+
pub use path::PgLspPath;
8+

crates/pg_base_db/src/path.rs renamed to crates/pg_fs/src/path.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{ops::Deref, path::PathBuf};
22

3-
#[derive(Debug, Clone, Eq, Hash, PartialEq)]
3+
#[derive(Debug, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
44
pub struct PgLspPath {
55
path: PathBuf,
66
}
@@ -20,3 +20,4 @@ impl PgLspPath {
2020
}
2121
}
2222
}
23+

crates/pg_lsp/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ text-size = "1.1.1"
2525
line_index.workspace = true
2626

2727
pg_hover.workspace = true
28+
pg_fs.workspace = true
2829
pg_completions.workspace = true
2930
pg_inlay_hints.workspace = true
3031
pg_commands.workspace = true

crates/pg_lsp/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub mod to_proto;
55
use std::path::PathBuf;
66

77
use lsp_types;
8-
use pg_base_db::PgLspPath;
8+
use pg_fs::PgLspPath;
99

1010
/// Convert a `lsp_types::Url` to a `PgLspPath`.
1111
pub(crate) fn file_path(url: &lsp_types::Url) -> PgLspPath {

crates/pg_lsp/src/utils/line_index_ext.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ impl LineIndexExt for LineIndex {
5454

5555
#[cfg(test)]
5656
mod tests {
57-
use pg_base_db::{Document, PgLspPath};
57+
use pg_base_db::Document;
58+
use pg_fs::PgLspPath;
5859
use text_size::{TextRange, TextSize};
5960

6061
use crate::utils::line_index_ext::LineIndexExt;

crates/pg_workspace/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ async-std = "1.12.0"
1010
sqlx = { version = "0.7.3", features = [ "runtime-async-std", "tls-rustls", "postgres", "json" ] }
1111

1212
pg_base_db.workspace = true
13+
pg_fs.workspace = true
1314
pg_diagnostics.workspace = true
1415
pg_query_ext.workspace = true
1516
pg_lint.workspace = true

crates/pg_workspace/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use std::sync::{RwLock, RwLockWriteGuard};
77

88
use dashmap::{DashMap, DashSet};
99
use lint::Linter;
10-
use pg_base_db::{Document, DocumentChange, PgLspPath, StatementRef};
10+
use pg_base_db::{Document, DocumentChange, StatementRef};
11+
use pg_fs::PgLspPath;
1112
use pg_query::PgQueryParser;
1213
use pg_schema_cache::SchemaCache;
1314
use sqlx::PgPool;
@@ -184,7 +185,8 @@ mod tests {
184185
use pg_diagnostics::Diagnostic;
185186
use text_size::{TextRange, TextSize};
186187

187-
use crate::{PgLspPath, Workspace};
188+
use crate::Workspace;
189+
use pg_fs::PgLspPath;
188190

189191
#[test]
190192
fn test_apply_change() {

0 commit comments

Comments
 (0)