Skip to content

Commit 4fb70bf

Browse files
authored
ide: cleanup return types in resolve_name_ref to use Location (#1089)
1 parent d9acd00 commit 4fb70bf

6 files changed

Lines changed: 937 additions & 896 deletions

File tree

β€Žcrates/squawk_ide/src/collect.rsβ€Ž

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use crate::db::{File, bind, parse};
55
use crate::infer::{Type, infer_type_from_expr, infer_type_from_ty};
66
use crate::resolve::{
77
ResolvedTableName, extract_table_schema_from_path, find_from_item_in_from_clause,
8-
qualified_star_table_name, resolve_cte_table, resolve_table_name, resolve_table_name_ptr,
9-
resolve_view_name_ptr, table_and_schema_from_from_item, table_ptr_from_from_item,
8+
qualified_star_table_name, resolve_cte_table, resolve_table_name, table_ptr_from_from_item,
109
};
1110
use crate::symbols::{Name, SymbolKind};
1211
use salsa::Database as Db;
@@ -83,47 +82,6 @@ fn columns_from_create_table_impl(
8382
}
8483
}
8584

86-
pub(crate) fn tables_from_item(
87-
db: &dyn Db,
88-
file: File,
89-
from_item: &ast::FromItem,
90-
results: &mut Vec<SyntaxNodePtr>,
91-
) {
92-
if let Some(alias) = from_item.alias()
93-
&& alias.column_list().is_some()
94-
{
95-
results.push(SyntaxNodePtr::new(alias.syntax()));
96-
return;
97-
}
98-
99-
if let Some(paren_select) = from_item.paren_select() {
100-
results.push(SyntaxNodePtr::new(paren_select.syntax()));
101-
return;
102-
}
103-
104-
let Some((table_name, schema)) = table_and_schema_from_from_item(from_item) else {
105-
return;
106-
};
107-
108-
let position = from_item.syntax().text_range().start();
109-
if let Some(table_name_ptr) = resolve_table_name_ptr(db, file, &table_name, &schema, position) {
110-
results.push(table_name_ptr);
111-
return;
112-
}
113-
114-
if let Some(view_name_ptr) = resolve_view_name_ptr(db, file, &table_name, &schema, position) {
115-
results.push(view_name_ptr);
116-
return;
117-
}
118-
119-
if schema.is_none()
120-
&& let Some(name_ref) = from_item.name_ref()
121-
&& let Some(cte_ptr) = resolve_cte_table(&name_ref, &table_name)
122-
{
123-
results.push(cte_ptr);
124-
}
125-
}
126-
12785
pub(crate) fn table_columns(
12886
db: &dyn Db,
12987
file: File,

β€Žcrates/squawk_ide/src/goto_definition.rsβ€Ž

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn goto_definition(db: &dyn Db, file: File, offset: TextSize) -> SmallVec<[L
2929
if let Some(case_expr) = ast::CaseExpr::cast(parent)
3030
&& let Some(case_token) = case_expr.case_token()
3131
{
32-
return smallvec![Location::current(
32+
return smallvec![Location::new(
3333
file,
3434
case_token.text_range(),
3535
LocationKind::CaseExpr
@@ -42,50 +42,33 @@ pub fn goto_definition(db: &dyn Db, file: File, offset: TextSize) -> SmallVec<[L
4242
if ast::Commit::can_cast(parent.kind())
4343
&& let Some(begin_range) = find_preceding_begin(db, file, offset)
4444
{
45-
return smallvec![Location::current(
46-
file,
47-
begin_range,
48-
LocationKind::CommitBegin
49-
)];
45+
return smallvec![Location::new(file, begin_range, LocationKind::CommitBegin)];
5046
}
5147

5248
// goto def on ROLLBACK -> BEGIN/START TRANSACTION
5349
if ast::Rollback::can_cast(parent.kind())
5450
&& let Some(begin_range) = find_preceding_begin(db, file, offset)
5551
{
56-
return smallvec![Location::current(
57-
file,
58-
begin_range,
59-
LocationKind::CommitBegin
60-
)];
52+
return smallvec![Location::new(file, begin_range, LocationKind::CommitBegin)];
6153
}
6254

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

7062
if let Some(name) = ast::Name::cast(parent.clone())
71-
&& let Some(kind) = LocationKind::from_node(name.syntax())
63+
&& let Some(location) = Location::from_node(file, name.syntax())
7264
{
73-
return smallvec![Location::current(file, name.syntax().text_range(), kind)];
65+
return smallvec![location];
7466
}
7567

7668
if let Some(name_ref) = ast::NameRef::cast(parent.clone()) {
7769
for definition_file in [file, builtins_file(db)] {
78-
if let Some((ptrs, kind)) = resolve::resolve_name_ref(db, definition_file, &name_ref) {
79-
let ranges = ptrs
80-
.iter()
81-
.map(|ptr| ptr.text_range())
82-
.map(|range| Location {
83-
file: definition_file,
84-
range,
85-
kind,
86-
})
87-
.collect();
88-
return ranges;
70+
if let Some(locations) = resolve::resolve_name_ref(db, definition_file, &name_ref) {
71+
return locations;
8972
}
9073
}
9174
}
@@ -5786,6 +5769,20 @@ select t$0 from t;
57865769
");
57875770
}
57885771

5772+
#[test]
5773+
fn goto_select_view_name_from_view() {
5774+
assert_snapshot!(goto("
5775+
create view boop as select 1 a;
5776+
select boop$0 from boop;
5777+
"), @"
5778+
β•­β–Έ
5779+
2 β”‚ create view boop as select 1 a;
5780+
β”‚ ──── 2. destination
5781+
3 β”‚ select boop from boop;
5782+
β•°β•΄ ─ 1. source
5783+
");
5784+
}
5785+
57895786
#[test]
57905787
fn goto_drop_schema() {
57915788
assert_snapshot!(goto("

0 commit comments

Comments
Β (0)