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
44 changes: 1 addition & 43 deletions crates/squawk_ide/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use crate::db::{File, bind, parse};
use crate::infer::{Type, infer_type_from_expr, infer_type_from_ty};
use crate::resolve::{
ResolvedTableName, extract_table_schema_from_path, find_from_item_in_from_clause,
qualified_star_table_name, resolve_cte_table, resolve_table_name, resolve_table_name_ptr,
resolve_view_name_ptr, table_and_schema_from_from_item, table_ptr_from_from_item,
qualified_star_table_name, resolve_cte_table, resolve_table_name, table_ptr_from_from_item,
};
use crate::symbols::{Name, SymbolKind};
use salsa::Database as Db;
Expand Down Expand Up @@ -83,47 +82,6 @@ fn columns_from_create_table_impl(
}
}

pub(crate) fn tables_from_item(
db: &dyn Db,
file: File,
from_item: &ast::FromItem,
results: &mut Vec<SyntaxNodePtr>,
) {
if let Some(alias) = from_item.alias()
&& alias.column_list().is_some()
{
results.push(SyntaxNodePtr::new(alias.syntax()));
return;
}

if let Some(paren_select) = from_item.paren_select() {
results.push(SyntaxNodePtr::new(paren_select.syntax()));
return;
}

let Some((table_name, schema)) = table_and_schema_from_from_item(from_item) else {
return;
};

let position = from_item.syntax().text_range().start();
if let Some(table_name_ptr) = resolve_table_name_ptr(db, file, &table_name, &schema, position) {
results.push(table_name_ptr);
return;
}

if let Some(view_name_ptr) = resolve_view_name_ptr(db, file, &table_name, &schema, position) {
results.push(view_name_ptr);
return;
}

if schema.is_none()
&& let Some(name_ref) = from_item.name_ref()
&& let Some(cte_ptr) = resolve_cte_table(&name_ref, &table_name)
{
results.push(cte_ptr);
}
}

pub(crate) fn table_columns(
db: &dyn Db,
file: File,
Expand Down
47 changes: 22 additions & 25 deletions crates/squawk_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn goto_definition(db: &dyn Db, file: File, offset: TextSize) -> SmallVec<[L
if let Some(case_expr) = ast::CaseExpr::cast(parent)
&& let Some(case_token) = case_expr.case_token()
{
return smallvec![Location::current(
return smallvec![Location::new(
file,
case_token.text_range(),
LocationKind::CaseExpr
Expand All @@ -42,50 +42,33 @@ pub fn goto_definition(db: &dyn Db, file: File, offset: TextSize) -> SmallVec<[L
if ast::Commit::can_cast(parent.kind())
&& let Some(begin_range) = find_preceding_begin(db, file, offset)
{
return smallvec![Location::current(
file,
begin_range,
LocationKind::CommitBegin
)];
return smallvec![Location::new(file, begin_range, LocationKind::CommitBegin)];
}

// goto def on ROLLBACK -> BEGIN/START TRANSACTION
if ast::Rollback::can_cast(parent.kind())
&& let Some(begin_range) = find_preceding_begin(db, file, offset)
{
return smallvec![Location::current(
file,
begin_range,
LocationKind::CommitBegin
)];
return smallvec![Location::new(file, begin_range, LocationKind::CommitBegin)];
}

// goto def on BEGIN/START TRANSACTION -> COMMIT or ROLLBACK
if ast::Begin::can_cast(parent.kind())
&& let Some(end_range) = find_following_commit_or_rollback(db, file, offset)
{
return smallvec![Location::current(file, end_range, LocationKind::CommitEnd)];
return smallvec![Location::new(file, end_range, LocationKind::CommitEnd)];
}

if let Some(name) = ast::Name::cast(parent.clone())
&& let Some(kind) = LocationKind::from_node(name.syntax())
&& let Some(location) = Location::from_node(file, name.syntax())
{
return smallvec![Location::current(file, name.syntax().text_range(), kind)];
return smallvec![location];
}

if let Some(name_ref) = ast::NameRef::cast(parent.clone()) {
for definition_file in [file, builtins_file(db)] {
if let Some((ptrs, kind)) = resolve::resolve_name_ref(db, definition_file, &name_ref) {
let ranges = ptrs
.iter()
.map(|ptr| ptr.text_range())
.map(|range| Location {
file: definition_file,
range,
kind,
})
.collect();
return ranges;
if let Some(locations) = resolve::resolve_name_ref(db, definition_file, &name_ref) {
return locations;
}
}
}
Expand Down Expand Up @@ -5786,6 +5769,20 @@ select t$0 from t;
");
}

#[test]
fn goto_select_view_name_from_view() {
assert_snapshot!(goto("
create view boop as select 1 a;
select boop$0 from boop;
"), @"
╭▸
2 │ create view boop as select 1 a;
│ ──── 2. destination
3 │ select boop from boop;
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_schema() {
assert_snapshot!(goto("
Expand Down
Loading
Loading