Skip to content

Commit 91ff8b2

Browse files
committed
progress
1 parent 8616270 commit 91ff8b2

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

crates/pgt_fs/src/fs.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ pub trait FileSystem: Send + Sync + RefUnwindSafe {
8989
// Iterate all possible file names
9090
for file_name in file_names {
9191
let file_path = curret_search_dir.join(file_name);
92-
println!(
93-
"Checking for file: {:?} in directory: {:?}",
94-
file_path,
95-
curret_search_dir.display()
96-
);
9792
match self.read_file_from_path(&file_path) {
9893
Ok(content) => {
9994
if is_searching_in_parent_dir {

crates/pgt_fs/src/fs/memory.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ impl FileSystem for MemoryFileSystem {
234234
_specifier: &str,
235235
_path: &Path,
236236
) -> Result<Resolution, ResolveError> {
237+
// not needed for the memory file system
237238
todo!()
238239
}
239240
}

crates/pgt_workspace/src/settings.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,16 @@ impl WorkspaceSettings {
5151

5252
pub fn get_current_project_path(&self) -> Option<&PgTPath> {
5353
trace!("Current key {:?}", self.current_project);
54-
let data = self.data.get(self.current_project);
55-
if let Some(data) = data {
56-
Some(&data.path)
57-
} else {
58-
None
59-
}
54+
self.data
55+
.get(self.current_project)
56+
.as_ref()
57+
.map(|d| &d.path)
6058
}
6159

6260
pub fn get_current_project_data_mut(&mut self) -> &mut ProjectData {
6361
self.data
6462
.get_mut(self.current_project)
65-
.expect("You must have at least one workspace.")
63+
.expect("Current project not configured")
6664
}
6765

6866
/// Retrieves the settings of the current workspace folder

crates/pgt_workspace/src/workspace/server.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub(super) struct WorkspaceServer {
6868
settings: RwLock<WorkspaceSettings>,
6969

7070
/// Stores the schema cache for this workspace
71-
/// TODO: store this per connection
7271
schema_cache: SchemaCacheManager,
7372

7473
parsed_documents: DashMap<PgTPath, ParsedDocument>,
@@ -133,7 +132,7 @@ impl WorkspaceServer {
133132
workspace_mut.set_current_project(project_key);
134133
}
135134

136-
/// Checks whether, if the current path belongs to the current project.
135+
/// Checks whether the current path belongs to the current project.
137136
///
138137
/// If there's a match, and the match **isn't** the current project, it returns the new key.
139138
fn path_belongs_to_current_workspace(&self, path: &PgTPath) -> Option<ProjectKey> {
@@ -213,6 +212,10 @@ impl Workspace for WorkspaceServer {
213212

214213
let is_new_path = match (current_project_path.as_deref(), params.path.as_ref()) {
215214
(Some(current_project_path), Some(params_path)) => current_project_path != params_path,
215+
(Some(_), None) => {
216+
// If the current project is set, but no path is provided, we assume it's a new project
217+
true
218+
}
216219
_ => true,
217220
};
218221

@@ -410,9 +413,19 @@ impl Workspace for WorkspaceServer {
410413
params: PullDiagnosticsParams,
411414
) -> Result<PullDiagnosticsResult, WorkspaceError> {
412415
let settings = self.workspaces();
413-
// TODO: not sure how we should handle this
414-
// maybe fallback to default settings? or return an error?
415-
let settings = settings.settings().expect("Settings should be initialized");
416+
417+
let settings = match settings.settings() {
418+
Some(settings) => settings,
419+
None => {
420+
// return an empty result if no settings are available
421+
// we might want to return an error here in the future
422+
return Ok(PullDiagnosticsResult {
423+
diagnostics: Vec::new(),
424+
errors: 0,
425+
skipped_diagnostics: 0,
426+
});
427+
}
428+
};
416429

417430
// create analyser for this run
418431
// first, collect enabled and disabled rules from the workspace settings

crates/pgt_workspace/src/workspace/server/schema_cache_manager.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,21 @@ impl SchemaCacheManager {
2727
return Ok(Arc::clone(&*cache));
2828
}
2929

30-
let schema_cache = Arc::new(run_async(async move { SchemaCache::load(&pool).await })??);
31-
32-
self.schemas.insert(key, Arc::clone(&schema_cache));
33-
34-
Ok(schema_cache)
30+
let schema_cache = self
31+
.schemas
32+
.entry(key)
33+
.or_try_insert_with::<WorkspaceError>(|| {
34+
// This closure will only be called once per key if multiple threads
35+
// try to access the same key simultaneously
36+
let pool_clone = pool.clone();
37+
let schema_cache =
38+
Arc::new(run_async(
39+
async move { SchemaCache::load(&pool_clone).await },
40+
)??);
41+
42+
Ok(schema_cache)
43+
})?;
44+
45+
Ok(Arc::clone(&schema_cache))
3546
}
3647
}

0 commit comments

Comments
 (0)