Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions crates/squawk_ide/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn bind_create_table(b: &mut Binder, create_table: ast::CreateTable) {
let table_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Table,
ptr: name_ptr,
schema,
schema: Some(schema),
params: None,
});

Expand All @@ -141,7 +141,7 @@ fn bind_create_foreign_table(b: &mut Binder, create_foreign_table: ast::CreateFo
let table_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Table,
ptr: name_ptr,
schema,
schema: Some(schema),
params: None,
});

Expand All @@ -164,7 +164,7 @@ fn bind_create_index(b: &mut Binder, create_index: ast::CreateIndex) {
let index_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Index,
ptr: name_ptr,
schema,
schema: Some(schema),
params: None,
});

Expand Down Expand Up @@ -192,7 +192,7 @@ fn bind_create_function(b: &mut Binder, create_function: ast::CreateFunction) {
let function_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Function,
ptr: name_ptr,
schema,
schema: Some(schema),
params,
});

Expand Down Expand Up @@ -220,7 +220,7 @@ fn bind_create_aggregate(b: &mut Binder, create_aggregate: ast::CreateAggregate)
let aggregate_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Aggregate,
ptr: name_ptr,
schema,
schema: Some(schema),
params,
});

Expand Down Expand Up @@ -248,7 +248,7 @@ fn bind_create_procedure(b: &mut Binder, create_procedure: ast::CreateProcedure)
let procedure_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Procedure,
ptr: name_ptr,
schema,
schema: Some(schema),
params,
});

Expand Down Expand Up @@ -276,7 +276,7 @@ fn bind_create_schema(b: &mut Binder, create_schema: ast::CreateSchema) {
let schema_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Schema,
ptr: name_ptr,
schema: Schema(schema_name.clone()),
schema: Some(Schema(schema_name.clone())),
params: None,
});

Expand All @@ -302,7 +302,7 @@ fn bind_create_type(b: &mut Binder, create_type: ast::CreateType) {
let type_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Type,
ptr: name_ptr,
schema,
schema: Some(schema),
params: None,
});

Expand All @@ -329,7 +329,7 @@ fn bind_create_view(b: &mut Binder, create_view: ast::CreateView) {
let view_id = b.symbols.alloc(Symbol {
kind: SymbolKind::View,
ptr: name_ptr,
schema,
schema: Some(schema),
params: None,
});

Expand All @@ -355,7 +355,7 @@ fn bind_create_materialized_view(b: &mut Binder, create_view: ast::CreateMateria
let view_id = b.symbols.alloc(Symbol {
kind: SymbolKind::View,
ptr: name_ptr,
schema,
schema: Some(schema),
params: None,
});

Expand Down Expand Up @@ -383,7 +383,7 @@ fn bind_create_sequence(b: &mut Binder, create_sequence: ast::CreateSequence) {
let sequence_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Sequence,
ptr: name_ptr,
schema,
schema: Some(schema),
params: None,
});

Expand All @@ -402,9 +402,7 @@ fn bind_create_tablespace(b: &mut Binder, create_tablespace: ast::CreateTablespa
let tablespace_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Tablespace,
ptr: name_ptr,
// TODO: tablespaces don't actually have schemas so we should think
// about this more
schema: Schema::new("pg_tablespace"),
schema: None,
params: None,
});

Expand All @@ -423,7 +421,7 @@ fn bind_create_database(b: &mut Binder, create_database: ast::CreateDatabase) {
let database_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Database,
ptr: name_ptr,
schema: Schema::new("pg_database"),
schema: None,
params: None,
});

Expand All @@ -442,7 +440,7 @@ fn bind_create_server(b: &mut Binder, create_server: ast::CreateServer) {
let server_id = b.symbols.alloc(Symbol {
kind: SymbolKind::Server,
ptr: name_ptr,
schema: Schema::new("pg_foreign_server"),
schema: None,
params: None,
});

Expand Down
16 changes: 8 additions & 8 deletions crates/squawk_ide/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,15 @@ fn resolve_for_kind(
if let Some(schema) = schema {
let symbol_id = symbols.iter().copied().find(|id| {
let symbol = &binder.symbols[*id];
symbol.kind == kind && &symbol.schema == schema
symbol.kind == kind && symbol.schema.as_ref() == Some(schema)
})?;
return Some(binder.symbols[symbol_id].ptr);
} else {
let search_path = binder.search_path_at(position);
for search_schema in search_path {
if let Some(symbol_id) = symbols.iter().copied().find(|id| {
let symbol = &binder.symbols[*id];
symbol.kind == kind && &symbol.schema == search_schema
symbol.kind == kind && symbol.schema.as_ref() == Some(search_schema)
}) {
return Some(binder.symbols[symbol_id].ptr);
}
Expand Down Expand Up @@ -505,7 +505,7 @@ fn resolve_for_kind_with_params(
(_, None) => true,
_ => false,
};
symbol.kind == kind && &symbol.schema == schema && params_match
symbol.kind == kind && symbol.schema.as_ref() == Some(schema) && params_match
})?;
return Some(binder.symbols[symbol_id].ptr);
} else {
Expand All @@ -519,7 +519,7 @@ fn resolve_for_kind_with_params(
(_, None) => true,
_ => false,
};
symbol.kind == kind && &symbol.schema == search_schema && params_match
symbol.kind == kind && symbol.schema.as_ref() == Some(search_schema) && params_match
}) {
return Some(binder.symbols[symbol_id].ptr);
}
Expand Down Expand Up @@ -2153,20 +2153,20 @@ fn resolve_symbol_info(
let schema_normalized = Schema::new(schema_name);
let symbol_id = symbols.iter().copied().find(|id| {
let symbol = &binder.symbols[*id];
symbol.kind == kind && symbol.schema == schema_normalized
symbol.kind == kind && symbol.schema.as_ref() == Some(&schema_normalized)
})?;
let symbol = &binder.symbols[symbol_id];
return Some((symbol.schema.clone(), name_str));
return Some((symbol.schema.clone()?, name_str));
} else {
let position = path.syntax().text_range().start();
let search_path = binder.search_path_at(position);
for search_schema in search_path {
if let Some(symbol_id) = symbols.iter().copied().find(|id| {
let symbol = &binder.symbols[*id];
symbol.kind == kind && &symbol.schema == search_schema
symbol.kind == kind && symbol.schema.as_ref() == Some(search_schema)
}) {
let symbol = &binder.symbols[symbol_id];
return Some((symbol.schema.clone(), name_str));
return Some((symbol.schema.clone()?, name_str));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_ide/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub(crate) enum SymbolKind {
pub(crate) struct Symbol {
pub(crate) kind: SymbolKind,
pub(crate) ptr: SyntaxNodePtr,
pub(crate) schema: Schema,
pub(crate) schema: Option<Schema>,
pub(crate) params: Option<Vec<Name>>,
}

Expand Down
Loading