Skip to content
Merged
Prev Previous commit
Next Next commit
finish
  • Loading branch information
psteinroe committed Apr 10, 2025
commit 773e54281e83703ae7b7de82892bb792ad9041de
2 changes: 1 addition & 1 deletion crates/pgt_completions/src/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct CompletionParams<'a> {
pub position: TextSize,
pub schema: &'a pgt_schema_cache::SchemaCache,
pub text: String,
pub tree: Option<&'a tree_sitter::Tree>,
pub tree: &'a tree_sitter::Tree,
}

pub fn complete(params: CompletionParams) -> Vec<CompletionItem> {
Expand Down
27 changes: 10 additions & 17 deletions crates/pgt_completions/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl TryFrom<String> for ClauseType {

pub(crate) struct CompletionContext<'a> {
pub ts_node: Option<tree_sitter::Node<'a>>,
pub tree: Option<&'a tree_sitter::Tree>,
pub tree: &'a tree_sitter::Tree,
pub text: &'a str,
pub schema_cache: &'a SchemaCache,
pub position: usize,
Expand Down Expand Up @@ -85,10 +85,7 @@ impl<'a> CompletionContext<'a> {
}

fn gather_info_from_ts_queries(&mut self) {
let tree = match self.tree.as_ref() {
None => return,
Some(t) => t,
};
let tree = self.tree;

let stmt_range = self.wrapping_statement_range.as_ref();
let sql = self.text;
Expand Down Expand Up @@ -126,11 +123,7 @@ impl<'a> CompletionContext<'a> {
}

fn gather_tree_context(&mut self) {
if self.tree.is_none() {
return;
}

let mut cursor = self.tree.as_ref().unwrap().root_node().walk();
let mut cursor = self.tree.root_node().walk();

/*
* The head node of any treesitter tree is always the "PROGRAM" node.
Expand Down Expand Up @@ -262,7 +255,7 @@ mod tests {
let params = crate::CompletionParams {
position: (position as u32).into(),
text,
tree: Some(&tree),
tree: &tree,
schema: &pgt_schema_cache::SchemaCache::default(),
};

Expand Down Expand Up @@ -294,7 +287,7 @@ mod tests {
let params = crate::CompletionParams {
position: (position as u32).into(),
text,
tree: Some(&tree),
tree: &tree,
schema: &pgt_schema_cache::SchemaCache::default(),
};

Expand Down Expand Up @@ -328,7 +321,7 @@ mod tests {
let params = crate::CompletionParams {
position: (position as u32).into(),
text,
tree: Some(&tree),
tree: &tree,
schema: &pgt_schema_cache::SchemaCache::default(),
};

Expand All @@ -353,7 +346,7 @@ mod tests {
let params = crate::CompletionParams {
position: (position as u32).into(),
text,
tree: Some(&tree),
tree: &tree,
schema: &pgt_schema_cache::SchemaCache::default(),
};

Expand Down Expand Up @@ -381,7 +374,7 @@ mod tests {
let params = crate::CompletionParams {
position: (position as u32).into(),
text,
tree: Some(&tree),
tree: &tree,
schema: &pgt_schema_cache::SchemaCache::default(),
};

Expand All @@ -407,7 +400,7 @@ mod tests {
let params = crate::CompletionParams {
position: (position as u32).into(),
text,
tree: Some(&tree),
tree: &tree,
schema: &pgt_schema_cache::SchemaCache::default(),
};

Expand All @@ -432,7 +425,7 @@ mod tests {
let params = crate::CompletionParams {
position: (position as u32).into(),
text,
tree: Some(&tree),
tree: &tree,
schema: &pgt_schema_cache::SchemaCache::default(),
};

Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_completions/src/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) fn get_test_params<'a>(
CompletionParams {
position: (position as u32).into(),
schema: schema_cache,
tree: Some(tree),
tree,
text,
}
}
20 changes: 9 additions & 11 deletions crates/pgt_typecheck/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,22 @@ impl Advices for TypecheckAdvices {

pub(crate) fn create_type_error(
pg_err: &PgDatabaseError,
ts: Option<&tree_sitter::Tree>,
ts: &tree_sitter::Tree,
) -> TypecheckDiagnostic {
let position = pg_err.position().and_then(|pos| match pos {
sqlx::postgres::PgErrorPosition::Original(pos) => Some(pos - 1),
_ => None,
});

let range = position.and_then(|pos| {
ts.and_then(|tree| {
tree.root_node()
.named_descendant_for_byte_range(pos, pos)
.map(|node| {
TextRange::new(
node.start_byte().try_into().unwrap(),
node.end_byte().try_into().unwrap(),
)
})
})
ts.root_node()
.named_descendant_for_byte_range(pos, pos)
.map(|node| {
TextRange::new(
node.start_byte().try_into().unwrap(),
node.end_byte().try_into().unwrap(),
)
})
});

let severity = match pg_err.severity() {
Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_typecheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct TypecheckParams<'a> {
pub conn: &'a PgPool,
pub sql: &'a str,
pub ast: &'a pgt_query_ext::NodeEnum,
pub tree: Option<&'a tree_sitter::Tree>,
pub tree: &'a tree_sitter::Tree,
}

#[derive(Debug, Clone)]
Expand Down
Loading