Skip to content

Commit 50aa8a0

Browse files
authored
ide: create property graph table & column goto def (#1075)
1 parent 057d5cf commit 50aa8a0

13 files changed

Lines changed: 739 additions & 286 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub(crate) enum NameRefClass {
4040
Procedure,
4141
ProcedureCall,
4242
PropertyGraph,
43+
PropertyGraphColumn,
4344
QualifiedColumn,
4445
Role,
4546
Routine,
@@ -321,6 +322,14 @@ pub(crate) fn classify_name_ref(node: &SyntaxNode) -> Option<NameRefClass> {
321322
return Some(NameRefClass::PropertyGraph);
322323
}
323324

325+
if let Some(parent) = node.parent()
326+
&& let Some(expr_as_name) = ast::ExprAsName::cast(parent)
327+
&& let Some(expr_as_name_list) = ast::ExprAsNameList::cast(expr_as_name.syntax().parent()?)
328+
&& ast::Properties::cast(expr_as_name_list.syntax().parent()?).is_some()
329+
{
330+
return Some(NameRefClass::PropertyGraphColumn);
331+
}
332+
324333
// Check for function/procedure reference in CREATE OPERATOR / CREATE AGGREGATE
325334
// before the type check
326335
for ancestor in node.ancestors() {
@@ -372,6 +381,14 @@ pub(crate) fn classify_name_ref(node: &SyntaxNode) -> Option<NameRefClass> {
372381
if ast::Notify::can_cast(ancestor.kind()) || ast::Unlisten::can_cast(ancestor.kind()) {
373382
return Some(NameRefClass::Channel);
374383
}
384+
if in_column_list
385+
&& (ast::VertexTableDef::can_cast(ancestor.kind())
386+
|| ast::EdgeTableDef::can_cast(ancestor.kind())
387+
|| ast::SourceVertexTable::can_cast(ancestor.kind())
388+
|| ast::DestVertexTable::can_cast(ancestor.kind()))
389+
{
390+
return Some(NameRefClass::PropertyGraphColumn);
391+
}
375392
if ast::DropTable::can_cast(ancestor.kind())
376393
|| ast::DropForeignTable::can_cast(ancestor.kind())
377394
|| ast::Truncate::can_cast(ancestor.kind())

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ const DELIMITED_LIST_KINDS: &[SyntaxKind] = &[
7474
SyntaxKind::VARIANT_LIST,
7575
SyntaxKind::XML_TABLE_COLUMN_LIST,
7676
SyntaxKind::PATH_PATTERN_LIST,
77-
SyntaxKind::PROPERTIES_LIST,
7877
];
7978

8079
pub fn extend_selection(root: &SyntaxNode, range: TextRange) -> TextRange {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
161161
| SyntaxKind::XML_NAMESPACE_LIST
162162
| SyntaxKind::XML_TABLE_COLUMN_LIST
163163
| SyntaxKind::LABEL_AND_PROPERTIES_LIST
164-
| SyntaxKind::PATH_PATTERN_LIST
165-
| SyntaxKind::PROPERTIES_LIST => Some(FoldKind::List),
164+
| SyntaxKind::PATH_PATTERN_LIST => Some(FoldKind::List),
166165
_ => None,
167166
}
168167
}

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

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ impl From<NameRefClass> for LocationKind {
190190
NameRefClass::Policy => LocationKind::Policy,
191191
NameRefClass::PreparedStatement => LocationKind::PreparedStatement,
192192
NameRefClass::PropertyGraph => LocationKind::PropertyGraph,
193+
NameRefClass::PropertyGraphColumn => LocationKind::Column,
193194
NameRefClass::Role => LocationKind::Role,
194195
NameRefClass::Schema => LocationKind::Schema,
195196
NameRefClass::Sequence => LocationKind::Sequence,
@@ -9383,6 +9384,317 @@ create property graph g
93839384
");
93849385
}
93859386

9387+
#[test]
9388+
fn goto_create_property_graph_sources_table() {
9389+
assert_snapshot!(goto("
9390+
create table v1 (
9391+
id int8 primary key,
9392+
name text
9393+
);
9394+
9395+
create table v2 (
9396+
id int8 primary key,
9397+
name text
9398+
);
9399+
9400+
create table v3 (
9401+
id int8 primary key,
9402+
name text
9403+
);
9404+
9405+
create table e1 (
9406+
id int8 primary key,
9407+
source_id int8 references v1,
9408+
destination_id int8 references v2
9409+
);
9410+
9411+
create table e2 (
9412+
id int8 primary key,
9413+
source_id int8 references v1,
9414+
destination_id int8 references v3
9415+
);
9416+
9417+
create property graph g1
9418+
vertex tables (v1, v2, v3)
9419+
edge tables (
9420+
e1 source v1$0 destination v2,
9421+
e2 source v1 destination v3);
9422+
"), @"
9423+
β•­β–Έ
9424+
2 β”‚ create table v1 (
9425+
β”‚ ── 2. destination
9426+
‑
9427+
32 β”‚ e1 source v1 destination v2,
9428+
β•°β•΄ ─ 1. source
9429+
"
9430+
);
9431+
9432+
assert_snapshot!(goto("
9433+
create table v1 (
9434+
id int8 primary key,
9435+
name text
9436+
);
9437+
9438+
create table v2 (
9439+
id int8 primary key,
9440+
name text
9441+
);
9442+
9443+
create table v3 (
9444+
id int8 primary key,
9445+
name text
9446+
);
9447+
9448+
create table e1 (
9449+
id int8 primary key,
9450+
source_id int8 references v1,
9451+
destination_id int8 references v2
9452+
);
9453+
9454+
create table e2 (
9455+
id int8 primary key,
9456+
source_id int8 references v1,
9457+
destination_id int8 references v3
9458+
);
9459+
9460+
create property graph g1
9461+
vertex tables (v1, v2, v3)
9462+
edge tables (
9463+
e1 source v1 destination v2,
9464+
e2 source v1 destination v3$0);
9465+
"), @"
9466+
β•­β–Έ
9467+
12 β”‚ create table v3 (
9468+
β”‚ ── 2. destination
9469+
‑
9470+
33 β”‚ e2 source v1 destination v3);
9471+
β•°β•΄ ─ 1. source
9472+
"
9473+
);
9474+
}
9475+
9476+
#[test]
9477+
fn goto_create_property_graph_references_table() {
9478+
assert_snapshot!(goto("
9479+
create table v1 (id int8 primary key);
9480+
create table v2 (id int8 primary key);
9481+
create table e1 (
9482+
id int8 primary key,
9483+
source_id int8 references v1,
9484+
destination_id int8 references v2
9485+
);
9486+
9487+
create property graph g1
9488+
vertex tables (v1, v2)
9489+
edge tables (
9490+
e1
9491+
source key (source_id) references v1$0 (id)
9492+
destination key (destination_id) references v2 (id)
9493+
);
9494+
"), @"
9495+
β•­β–Έ
9496+
2 β”‚ create table v1 (id int8 primary key);
9497+
β”‚ ── 2. destination
9498+
‑
9499+
14 β”‚ source key (source_id) references v1 (id)
9500+
β•°β•΄ ─ 1. source
9501+
"
9502+
);
9503+
}
9504+
9505+
#[test]
9506+
fn goto_create_property_graph_vertex_key_column() {
9507+
assert_snapshot!(goto("
9508+
create table v1 (
9509+
id int8 primary key,
9510+
name text
9511+
);
9512+
9513+
create property graph g1
9514+
vertex tables (v1 key (id$0));
9515+
"), @"
9516+
β•­β–Έ
9517+
3 β”‚ id int8 primary key,
9518+
β”‚ ── 2. destination
9519+
‑
9520+
8 β”‚ vertex tables (v1 key (id));
9521+
β•°β•΄ ─ 1. source
9522+
");
9523+
}
9524+
9525+
#[test]
9526+
fn goto_create_property_graph_edge_source_key_column() {
9527+
assert_snapshot!(goto("
9528+
create table v1 (id int8 primary key);
9529+
create table v2 (id int8 primary key);
9530+
create table e1 (
9531+
id int8 primary key,
9532+
source_id int8 references v1,
9533+
destination_id int8 references v2
9534+
);
9535+
9536+
create property graph g1
9537+
vertex tables (v1, v2)
9538+
edge tables (
9539+
e1 key (id)
9540+
source key (source_id$0) references v1 (id)
9541+
destination key (destination_id) references v2 (id));
9542+
"), @"
9543+
β•­β–Έ
9544+
6 β”‚ source_id int8 references v1,
9545+
β”‚ ───────── 2. destination
9546+
‑
9547+
14 β”‚ source key (source_id) references v1 (id)
9548+
β•°β•΄ ─ 1. source
9549+
");
9550+
}
9551+
9552+
#[test]
9553+
fn goto_create_property_graph_edge_source_references_column() {
9554+
assert_snapshot!(goto("
9555+
create table v1 (id int8 primary key);
9556+
create table v2 (id int8 primary key);
9557+
create table e1 (
9558+
id int8 primary key,
9559+
source_id int8 references v1,
9560+
destination_id int8 references v2
9561+
);
9562+
9563+
create property graph g1
9564+
vertex tables (v1, v2)
9565+
edge tables (
9566+
e1 key (id)
9567+
source key (source_id) references v1 (id$0)
9568+
destination key (destination_id) references v2 (id));
9569+
"), @"
9570+
β•­β–Έ
9571+
2 β”‚ create table v1 (id int8 primary key);
9572+
β”‚ ── 2. destination
9573+
‑
9574+
14 β”‚ source key (source_id) references v1 (id)
9575+
β•°β•΄ ─ 1. source
9576+
");
9577+
}
9578+
9579+
#[test]
9580+
fn goto_create_property_graph_edge_destination_key_column() {
9581+
assert_snapshot!(goto("
9582+
create table v1 (id int8 primary key);
9583+
create table v2 (id int8 primary key);
9584+
create table e1 (
9585+
id int8 primary key,
9586+
source_id int8 references v1,
9587+
destination_id int8 references v2
9588+
);
9589+
9590+
create property graph g1
9591+
vertex tables (v1, v2)
9592+
edge tables (
9593+
e1 key (id)
9594+
source key (source_id) references v1 (id)
9595+
destination key (destination_id$0) references v2 (id));
9596+
"), @"
9597+
β•­β–Έ
9598+
7 β”‚ destination_id int8 references v2
9599+
β”‚ ────────────── 2. destination
9600+
‑
9601+
15 β”‚ destination key (destination_id) references v2 (id));
9602+
β•°β•΄ ─ 1. source
9603+
");
9604+
}
9605+
9606+
#[test]
9607+
fn goto_create_property_graph_edge_destination_references_column() {
9608+
assert_snapshot!(goto("
9609+
create table v1 (id int8 primary key);
9610+
create table v2 (id int8 primary key);
9611+
create table e1 (
9612+
id int8 primary key,
9613+
source_id int8 references v1,
9614+
destination_id int8 references v2
9615+
);
9616+
9617+
create property graph g1
9618+
vertex tables (v1, v2)
9619+
edge tables (
9620+
e1 key (id)
9621+
source key (source_id) references v1 (id)
9622+
destination key (destination_id) references v2 (id$0));
9623+
"), @"
9624+
β•­β–Έ
9625+
3 β”‚ create table v2 (id int8 primary key);
9626+
β”‚ ── 2. destination
9627+
‑
9628+
15 β”‚ destination key (destination_id) references v2 (id));
9629+
β•°β•΄ ─ 1. source
9630+
");
9631+
}
9632+
9633+
#[test]
9634+
fn goto_create_property_graph_vertex_properties_column() {
9635+
assert_snapshot!(goto("
9636+
create table v1 (
9637+
id int8 primary key,
9638+
name text
9639+
);
9640+
9641+
create property graph g1
9642+
vertex tables (v1 properties (id$0, name));
9643+
"), @"
9644+
β•­β–Έ
9645+
3 β”‚ id int8 primary key,
9646+
β”‚ ── 2. destination
9647+
‑
9648+
8 β”‚ vertex tables (v1 properties (id, name));
9649+
β•°β•΄ ─ 1. source
9650+
");
9651+
9652+
assert_snapshot!(goto("
9653+
create table v1 (
9654+
id int8 primary key,
9655+
name text
9656+
);
9657+
9658+
create property graph g1
9659+
vertex tables (v1 properties (id, nam$0e));
9660+
"), @"
9661+
β•­β–Έ
9662+
4 β”‚ name text
9663+
β”‚ ──── 2. destination
9664+
‑
9665+
8 β”‚ vertex tables (v1 properties (id, name));
9666+
β•°β•΄ ─ 1. source
9667+
");
9668+
}
9669+
9670+
#[test]
9671+
fn goto_create_property_graph_edge_properties_column() {
9672+
assert_snapshot!(goto("
9673+
create table v1 (id int8 primary key);
9674+
create table v2 (id int8 primary key);
9675+
create table e1 (
9676+
id int8 primary key,
9677+
source_id int8 references v1,
9678+
destination_id int8 references v2
9679+
);
9680+
9681+
create property graph g1
9682+
vertex tables (v1, v2)
9683+
edge tables (
9684+
e1
9685+
source v1
9686+
destination v2
9687+
properties (id, source_id$0, destination_id));
9688+
"), @"
9689+
β•­β–Έ
9690+
6 β”‚ source_id int8 references v1,
9691+
β”‚ ───────── 2. destination
9692+
‑
9693+
16 β”‚ properties (id, source_id, destination_id));
9694+
β•°β•΄ ─ 1. source
9695+
");
9696+
}
9697+
93869698
#[test]
93879699
fn goto_drop_property_graph() {
93889700
assert_snapshot!(goto("

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ fn hover_name_ref(
290290
NameRefClass::Channel => hover_channel(root, name_ref, binder),
291291
NameRefClass::Window => hover_window(root, name_ref, binder),
292292
NameRefClass::PropertyGraph => hover_property_graph(root, name_ref, binder),
293+
NameRefClass::PropertyGraphColumn => hover_column(root, name_ref, binder),
293294
}
294295
}
295296

0 commit comments

Comments
Β (0)