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
17 changes: 17 additions & 0 deletions crates/squawk_ide/src/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub(crate) enum NameRefClass {
Procedure,
ProcedureCall,
PropertyGraph,
PropertyGraphColumn,
QualifiedColumn,
Role,
Routine,
Expand Down Expand Up @@ -321,6 +322,14 @@ pub(crate) fn classify_name_ref(node: &SyntaxNode) -> Option<NameRefClass> {
return Some(NameRefClass::PropertyGraph);
}

if let Some(parent) = node.parent()
&& let Some(expr_as_name) = ast::ExprAsName::cast(parent)
&& let Some(expr_as_name_list) = ast::ExprAsNameList::cast(expr_as_name.syntax().parent()?)
&& ast::Properties::cast(expr_as_name_list.syntax().parent()?).is_some()
{
return Some(NameRefClass::PropertyGraphColumn);
}

// Check for function/procedure reference in CREATE OPERATOR / CREATE AGGREGATE
// before the type check
for ancestor in node.ancestors() {
Expand Down Expand Up @@ -372,6 +381,14 @@ pub(crate) fn classify_name_ref(node: &SyntaxNode) -> Option<NameRefClass> {
if ast::Notify::can_cast(ancestor.kind()) || ast::Unlisten::can_cast(ancestor.kind()) {
return Some(NameRefClass::Channel);
}
if in_column_list
&& (ast::VertexTableDef::can_cast(ancestor.kind())
|| ast::EdgeTableDef::can_cast(ancestor.kind())
|| ast::SourceVertexTable::can_cast(ancestor.kind())
|| ast::DestVertexTable::can_cast(ancestor.kind()))
{
return Some(NameRefClass::PropertyGraphColumn);
}
if ast::DropTable::can_cast(ancestor.kind())
|| ast::DropForeignTable::can_cast(ancestor.kind())
|| ast::Truncate::can_cast(ancestor.kind())
Expand Down
1 change: 0 additions & 1 deletion crates/squawk_ide/src/expand_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const DELIMITED_LIST_KINDS: &[SyntaxKind] = &[
SyntaxKind::VARIANT_LIST,
SyntaxKind::XML_TABLE_COLUMN_LIST,
SyntaxKind::PATH_PATTERN_LIST,
SyntaxKind::PROPERTIES_LIST,
];

pub fn extend_selection(root: &SyntaxNode, range: TextRange) -> TextRange {
Expand Down
3 changes: 1 addition & 2 deletions crates/squawk_ide/src/folding_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
| SyntaxKind::XML_NAMESPACE_LIST
| SyntaxKind::XML_TABLE_COLUMN_LIST
| SyntaxKind::LABEL_AND_PROPERTIES_LIST
| SyntaxKind::PATH_PATTERN_LIST
| SyntaxKind::PROPERTIES_LIST => Some(FoldKind::List),
| SyntaxKind::PATH_PATTERN_LIST => Some(FoldKind::List),
_ => None,
}
}
Expand Down
312 changes: 312 additions & 0 deletions crates/squawk_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ impl From<NameRefClass> for LocationKind {
NameRefClass::Policy => LocationKind::Policy,
NameRefClass::PreparedStatement => LocationKind::PreparedStatement,
NameRefClass::PropertyGraph => LocationKind::PropertyGraph,
NameRefClass::PropertyGraphColumn => LocationKind::Column,
NameRefClass::Role => LocationKind::Role,
NameRefClass::Schema => LocationKind::Schema,
NameRefClass::Sequence => LocationKind::Sequence,
Expand Down Expand Up @@ -9383,6 +9384,317 @@ create property graph g
");
}

#[test]
fn goto_create_property_graph_sources_table() {
assert_snapshot!(goto("
create table v1 (
id int8 primary key,
name text
);

create table v2 (
id int8 primary key,
name text
);

create table v3 (
id int8 primary key,
name text
);

create table e1 (
id int8 primary key,
source_id int8 references v1,
destination_id int8 references v2
);

create table e2 (
id int8 primary key,
source_id int8 references v1,
destination_id int8 references v3
);

create property graph g1
vertex tables (v1, v2, v3)
edge tables (
e1 source v1$0 destination v2,
e2 source v1 destination v3);
"), @"
╭▸
2 │ create table v1 (
│ ── 2. destination
32 │ e1 source v1 destination v2,
╰╴ ─ 1. source
"
);

assert_snapshot!(goto("
create table v1 (
id int8 primary key,
name text
);

create table v2 (
id int8 primary key,
name text
);

create table v3 (
id int8 primary key,
name text
);

create table e1 (
id int8 primary key,
source_id int8 references v1,
destination_id int8 references v2
);

create table e2 (
id int8 primary key,
source_id int8 references v1,
destination_id int8 references v3
);

create property graph g1
vertex tables (v1, v2, v3)
edge tables (
e1 source v1 destination v2,
e2 source v1 destination v3$0);
"), @"
╭▸
12 │ create table v3 (
│ ── 2. destination
33 │ e2 source v1 destination v3);
╰╴ ─ 1. source
"
);
}

#[test]
fn goto_create_property_graph_references_table() {
assert_snapshot!(goto("
create table v1 (id int8 primary key);
create table v2 (id int8 primary key);
create table e1 (
id int8 primary key,
source_id int8 references v1,
destination_id int8 references v2
);

create property graph g1
vertex tables (v1, v2)
edge tables (
e1
source key (source_id) references v1$0 (id)
destination key (destination_id) references v2 (id)
);
"), @"
╭▸
2 │ create table v1 (id int8 primary key);
│ ── 2. destination
14 │ source key (source_id) references v1 (id)
╰╴ ─ 1. source
"
);
}

#[test]
fn goto_create_property_graph_vertex_key_column() {
assert_snapshot!(goto("
create table v1 (
id int8 primary key,
name text
);

create property graph g1
vertex tables (v1 key (id$0));
"), @"
╭▸
3 │ id int8 primary key,
│ ── 2. destination
8 │ vertex tables (v1 key (id));
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_property_graph_edge_source_key_column() {
assert_snapshot!(goto("
create table v1 (id int8 primary key);
create table v2 (id int8 primary key);
create table e1 (
id int8 primary key,
source_id int8 references v1,
destination_id int8 references v2
);

create property graph g1
vertex tables (v1, v2)
edge tables (
e1 key (id)
source key (source_id$0) references v1 (id)
destination key (destination_id) references v2 (id));
"), @"
╭▸
6 │ source_id int8 references v1,
│ ───────── 2. destination
14 │ source key (source_id) references v1 (id)
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_property_graph_edge_source_references_column() {
assert_snapshot!(goto("
create table v1 (id int8 primary key);
create table v2 (id int8 primary key);
create table e1 (
id int8 primary key,
source_id int8 references v1,
destination_id int8 references v2
);

create property graph g1
vertex tables (v1, v2)
edge tables (
e1 key (id)
source key (source_id) references v1 (id$0)
destination key (destination_id) references v2 (id));
"), @"
╭▸
2 │ create table v1 (id int8 primary key);
│ ── 2. destination
14 │ source key (source_id) references v1 (id)
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_property_graph_edge_destination_key_column() {
assert_snapshot!(goto("
create table v1 (id int8 primary key);
create table v2 (id int8 primary key);
create table e1 (
id int8 primary key,
source_id int8 references v1,
destination_id int8 references v2
);

create property graph g1
vertex tables (v1, v2)
edge tables (
e1 key (id)
source key (source_id) references v1 (id)
destination key (destination_id$0) references v2 (id));
"), @"
╭▸
7 │ destination_id int8 references v2
│ ────────────── 2. destination
15 │ destination key (destination_id) references v2 (id));
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_property_graph_edge_destination_references_column() {
assert_snapshot!(goto("
create table v1 (id int8 primary key);
create table v2 (id int8 primary key);
create table e1 (
id int8 primary key,
source_id int8 references v1,
destination_id int8 references v2
);

create property graph g1
vertex tables (v1, v2)
edge tables (
e1 key (id)
source key (source_id) references v1 (id)
destination key (destination_id) references v2 (id$0));
"), @"
╭▸
3 │ create table v2 (id int8 primary key);
│ ── 2. destination
15 │ destination key (destination_id) references v2 (id));
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_property_graph_vertex_properties_column() {
assert_snapshot!(goto("
create table v1 (
id int8 primary key,
name text
);

create property graph g1
vertex tables (v1 properties (id$0, name));
"), @"
╭▸
3 │ id int8 primary key,
│ ── 2. destination
8 │ vertex tables (v1 properties (id, name));
╰╴ ─ 1. source
");

assert_snapshot!(goto("
create table v1 (
id int8 primary key,
name text
);

create property graph g1
vertex tables (v1 properties (id, nam$0e));
"), @"
╭▸
4 │ name text
│ ──── 2. destination
8 │ vertex tables (v1 properties (id, name));
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_property_graph_edge_properties_column() {
assert_snapshot!(goto("
create table v1 (id int8 primary key);
create table v2 (id int8 primary key);
create table e1 (
id int8 primary key,
source_id int8 references v1,
destination_id int8 references v2
);

create property graph g1
vertex tables (v1, v2)
edge tables (
e1
source v1
destination v2
properties (id, source_id$0, destination_id));
"), @"
╭▸
6 │ source_id int8 references v1,
│ ───────── 2. destination
16 │ properties (id, source_id, destination_id));
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_property_graph() {
assert_snapshot!(goto("
Expand Down
1 change: 1 addition & 0 deletions crates/squawk_ide/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ fn hover_name_ref(
NameRefClass::Channel => hover_channel(root, name_ref, binder),
NameRefClass::Window => hover_window(root, name_ref, binder),
NameRefClass::PropertyGraph => hover_property_graph(root, name_ref, binder),
NameRefClass::PropertyGraphColumn => hover_column(root, name_ref, binder),
}
}

Expand Down
Loading
Loading