Skip to content

Commit fbe503e

Browse files
committed
fixes from review
1 parent c9cc2e0 commit fbe503e

File tree

3 files changed

+45
-72
lines changed

3 files changed

+45
-72
lines changed

crates/pg_typecheck/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub async fn check_sql(params: TypecheckParams<'_>) -> Option<TypecheckDiagnosti
4444

4545
let res = params.conn.prepare(params.sql).await;
4646

47-
// If there's no error, return an empty vector
4847
match res {
4948
Ok(_) => None,
5049
Err(sqlx::Error::Database(err)) => {

crates/pg_workspace_new/src/workspace/server.rs

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ mod change;
3535
mod document;
3636
mod pg_query;
3737
mod tree_sitter;
38-
mod typecheck;
3938

4039
/// Simple helper to manage the db connection and the associated connection string
4140
#[derive(Default)]
@@ -342,50 +341,52 @@ impl Workspace for WorkspaceServer {
342341
let mut diagnostics: Vec<SDiagnostic> = vec![];
343342

344343
// run diagnostics for each statement in parallel if its mostly i/o work
345-
if let Some(pool) = self.connection.read().unwrap().get_pool() {
346-
let typecheck_params: Vec<_> = doc
347-
.iter_statements_with_text_and_range()
348-
.map(|(stmt, range, text)| {
349-
let ast = self.pg_query.get_ast(&stmt);
350-
let tree = self.tree_sitter.get_parse_tree(&stmt);
351-
(text.to_string(), ast, tree, *range)
352-
})
353-
.collect();
354-
355-
let pool_clone = pool.clone();
356-
let path_clone = params.path.clone();
357-
let async_results = run_async(async move {
358-
stream::iter(typecheck_params)
359-
.map(|(text, ast, tree, range)| {
360-
let pool = pool_clone.clone();
361-
let path = path_clone.clone();
362-
async move {
363-
if let Some(ast) = ast {
364-
pg_typecheck::check_sql(TypecheckParams {
365-
conn: &pool,
366-
sql: &text,
367-
ast: &ast,
368-
tree: tree.as_deref(),
369-
})
370-
.await
371-
.map(|d| {
372-
let r = d.location().span.map(|span| span + range.start());
373-
374-
d.with_file_path(path.as_path().display().to_string())
375-
.with_file_span(r.unwrap_or(range))
376-
})
377-
} else {
378-
None
379-
}
380-
}
344+
if let Ok(connection) = self.connection.read() {
345+
if let Some(pool) = connection.get_pool() {
346+
let typecheck_params: Vec<_> = doc
347+
.iter_statements_with_text_and_range()
348+
.map(|(stmt, range, text)| {
349+
let ast = self.pg_query.get_ast(&stmt);
350+
let tree = self.tree_sitter.get_parse_tree(&stmt);
351+
(text.to_string(), ast, tree, *range)
381352
})
382-
.buffer_unordered(10)
383-
.collect::<Vec<_>>()
384-
.await
385-
})?;
386-
387-
for result in async_results.into_iter().flatten() {
388-
diagnostics.push(SDiagnostic::new(result));
353+
.collect();
354+
355+
let pool_clone = pool.clone();
356+
let path_clone = params.path.clone();
357+
let async_results = run_async(async move {
358+
stream::iter(typecheck_params)
359+
.map(|(text, ast, tree, range)| {
360+
let pool = pool_clone.clone();
361+
let path = path_clone.clone();
362+
async move {
363+
if let Some(ast) = ast {
364+
pg_typecheck::check_sql(TypecheckParams {
365+
conn: &pool,
366+
sql: &text,
367+
ast: &ast,
368+
tree: tree.as_deref(),
369+
})
370+
.await
371+
.map(|d| {
372+
let r = d.location().span.map(|span| span + range.start());
373+
374+
d.with_file_path(path.as_path().display().to_string())
375+
.with_file_span(r.unwrap_or(range))
376+
})
377+
} else {
378+
None
379+
}
380+
}
381+
})
382+
.buffer_unordered(10)
383+
.collect::<Vec<_>>()
384+
.await
385+
})?;
386+
387+
for result in async_results.into_iter().flatten() {
388+
diagnostics.push(SDiagnostic::new(result));
389+
}
389390
}
390391
}
391392

crates/pg_workspace_new/src/workspace/server/typecheck.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)