66import { DbSchema } from '../dbSchema.js' ;
77import { ParsedStatement } from '../cypherLanguageService.js' ;
88import { isLabelLeaf , LabelOrCondition , SymbolsInfo } from '../types.js' ;
9- import { findParent } from '../helpers.js' ;
9+ import { findParent , getDirection } from '../helpers.js' ;
1010import {
1111 NodePatternContext ,
1212 PatternElementContext ,
@@ -44,7 +44,7 @@ export function getShortPathCompletions(
4444
4545 const { toRels : nodesToRelsSet , fromRels : nodesFromRelsSet } =
4646 getNodesFromRelsSet ( dbSchema ) ;
47- const assumedDirection = lastNode . leftArrow ( ) ? 'outgoing ' : 'incoming ' ;
47+ const assumedDirection = lastNode . leftArrow ( ) ? 'left ' : 'right ' ;
4848
4949 let cnfTree : LabelOrCondition ;
5050 try {
@@ -65,7 +65,7 @@ export function getShortPathCompletions(
6565 cnfTree ,
6666 ) ;
6767
68- if ( assumedDirection === 'outgoing ' ) {
68+ if ( assumedDirection === 'left ' ) {
6969 for ( const outLabel of outLabels ) {
7070 snippetCompletions . push ( {
7171 label : '-(:' + outLabel + ')' ,
@@ -260,12 +260,7 @@ export function completeNodeLabel(
260260 return allLabelCompletions ( dbSchema ) ;
261261 }
262262
263- const direction =
264- lastValidElement . leftArrow ( ) && ! lastValidElement . rightArrow ( )
265- ? 'outgoing'
266- : ! lastValidElement . leftArrow ( ) && lastValidElement . rightArrow ( )
267- ? 'incoming'
268- : 'bidirectional' ;
263+ const direction = getDirection ( lastValidElement ) ;
269264
270265 // limitation: not checking node label repetition
271266 const { toRels : nodesToRelsSet , fromRels : nodesFromRelsSet } =
@@ -288,9 +283,9 @@ export function completeNodeLabel(
288283 cnfTree ,
289284 ) ;
290285 const allNodes =
291- direction === 'outgoing '
286+ direction === 'left '
292287 ? outLabels
293- : direction === 'incoming '
288+ : direction === 'right '
294289 ? inLabels
295290 : inLabels . union ( outLabels ) ;
296291 return labelsToCompletions ( Array . from ( allNodes ) ) ;
@@ -334,14 +329,9 @@ export function completeRelationshipType(
334329 parsingResult . stopNode ,
335330 ( x ) => x instanceof RelationshipPatternContext ,
336331 ) ;
337- let direction = 'bidirectional ' ;
332+ let direction = 'undirected ' ;
338333 if ( thisCtx instanceof RelationshipPatternContext ) {
339- direction =
340- thisCtx . leftArrow ( ) && ! thisCtx . rightArrow ( )
341- ? 'outgoing'
342- : ! thisCtx . leftArrow ( ) && thisCtx . rightArrow ( )
343- ? 'incoming'
344- : 'bidirectional' ;
334+ direction = getDirection ( thisCtx ) ;
345335 }
346336
347337 // limitation: bailing out on quantifiers
@@ -381,9 +371,9 @@ export function completeRelationshipType(
381371 cnfTree ,
382372 ) ;
383373 const allRels =
384- direction === 'outgoing '
374+ direction === 'left '
385375 ? outLabels
386- : direction === 'incoming '
376+ : direction === 'right '
387377 ? inLabels
388378 : inLabels . union ( outLabels ) ;
389379 return reltypesToCompletions ( Array . from ( allRels ) ) ;
0 commit comments