neo4j / cypher-language-support

Neo4j's Cypher Language support

Home Page:https://neo4j.github.io/cypher-language-support/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve the coverage of the syntax colouring

ncordon opened this issue · comments

Right now we only support a small subset of AST nodes in the syntax colouring: OPTIONAL, MATCH, RETURN, CALL, string literals.

We should improve this coverage to all the possible keywords at least, all possible literals, etc

Examples of big queries we can use in the tests, courtesy of our @angrykoala from our graphql team

MATCH (this:`Person`)

CALL {
    WITH this
    CALL {
        WITH *
        MATCH (this)-[this0:LIKES]->(this_likes:`Person`)
        CALL {
            WITH this_likes
            CALL {
                WITH *
                MATCH (this_likes)-[this1:LIKES]->(this_likes_likes:`Person`)
                WITH this_likes_likes  { __resolveType: "Person",  .name } AS this_likes_likes
                RETURN this_likes_likes AS this_likes_likes
                UNION
                WITH *
                MATCH (this_likes)-[this2:LIKES]->(this_likes_likes:`Movie`)
                WITH this_likes_likes  { __resolveType: "Movie",  .title } AS this_likes_likes
                RETURN this_likes_likes AS this_likes_likes
            }
            WITH this_likes_likes
            RETURN collect(this_likes_likes) AS this_likes_likes
        }
        WITH this_likes  { __resolveType: "Person",  .name, likes: this_likes_likes } AS this_likes
        RETURN this_likes AS this_likes
        UNION
        WITH *
        MATCH (this)-[this3:LIKES]->(this_likes:`Movie`)
        WITH this_likes { __resolveType: "Movie" } AS this_likes
        RETURN this_likes AS this_likes
    }
    WITH this_likes
    RETURN collect(this_likes) AS this_likes
}
RETURN this { .name, likes: this_likes } AS this
MATCH (this:`Person`)
WHERE (this.name STARTS WITH $param0 AND EXISTS {
    MATCH (this)-[:ACTED_IN]->(this0:`Movie`)
    WHERE (this0.title CONTAINS $param1 AND EXISTS {
        MATCH (this1:`Person`)-[:ACTED_IN]->(this0)
        WHERE (this1.name CONTAINS $param2 AND EXISTS {
            MATCH (this1)-[:ACTED_IN]->(this2:`Movie`)
            WHERE (NOT (this2.title = $param3) AND EXISTS {
                MATCH (this3:`Person`)-[:ACTED_IN]->(this2)
                WHERE (this3.name CONTAINS $param4 AND NOT (EXISTS {
                    MATCH (this3)-[:ACTED_IN]->(this4:`Movie`)
                    WHERE this4.title = $param5
                }))
            })
        })
    })
})


RETURN this { .name } AS this
WITH [] AS meta
MATCH (this:`CDnscZpeMovie`)
WHERE this.id = $param0


WITH this { .* } AS oldProps, this, meta
CALL {
	WITH *
	SET this.name = $this_update_name
	WITH this, meta
	CALL {
	WITH this
	CALL apoc.util.validate(this.length IS NULL, 'Cannot %s %s to Nan', ["_INCREMENT", $this_update_length_INCREMENT])
	CALL apoc.util.validate(this.length + $this_update_length_INCREMENT > 2^31-1, 'Overflow: Value returned from operator %s is larger than %s bit', ["_INCREMENT", "32"])
	CALL apoc.util.validate((this.length + $this_update_length_INCREMENT) % 1 <> 0, 'Type Mismatch: Value returned from operator %s does not match: %s', ["_INCREMENT", "Int"])
	SET this.length = this.length + $this_update_length_INCREMENT
	RETURN this as this_length__INCREMENT
	}
	WITH this, meta
CALL {
	WITH this, meta
	MATCH (this)<-[this_acted_in0_relationship:ACTED_IN]-(this_actors0:gkKSKJAEActor)
	WHERE this_actors0.name = $updateCDnscZpeMovies_args_update_actors0_where_gkKSKJAEActorparam0
	
	
	WITH this_actors0 { .* } AS oldProps, this, meta, this_actors0
	CALL {
		WITH *
		SET this_actors0.name = $this_update_actors0_name
		RETURN meta as update_meta
	}
	WITH *, update_meta as meta
	WITH this, this_actors0, meta + { event: "update", id: id(this_actors0), properties: { old: oldProps, new: this_actors0 { .* } }, timestamp: timestamp(), typename: "gkKSKJAEActor" } AS meta
	
	RETURN collect(meta) as update_meta
}
WITH this, REDUCE(m=meta, n IN update_meta | m + n) AS meta
	RETURN meta as update_meta
}
WITH *, update_meta as meta
WITH this, meta + { event: "update", id: id(this), properties: { old: oldProps, new: this { .* } }, timestamp: timestamp(), typename: "CDnscZpeMovie" } AS meta

WITH *
CALL {
    WITH this
    MATCH (this_actors:`gkKSKJAEActor`)-[update_this0:ACTED_IN]->(this)
    WITH this_actors { .name } AS this_actors
    RETURN collect(this_actors) AS this_actors
}
WITH *
UNWIND (CASE meta WHEN [] then [null] else meta end) AS m
RETURN collect(DISTINCT this { .id, .name, .length, actors: this_actors })
WITH [] AS meta
MATCH (this:`ZGTAXkHBMovie`)
WHERE this.id = $param0


WITH this { .* } AS oldProps, this, meta
CALL {
	WITH *
	SET this.name = $this_update_name
	WITH this, meta
OPTIONAL MATCH (this)<-[this_actors0_delete0_relationship:ACTED_IN]-(this_actors0_delete0:PHBtYviKActor)
WHERE this_actors0_delete0.name = $updateZgtaXkHbMovies_args_update_actors0_delete0_where_PHBtYviKActorparam0
WITH this, meta, this_actors0_delete0, this_actors0_delete0_relationship
OPTIONAL MATCH (this_actors0_delete0)-[this_actors0_delete0_movies0_relationship:ACTED_IN]->(this_actors0_delete0_movies0:ZGTAXkHBMovie)
WHERE this_actors0_delete0_movies0.name = $updateZgtaXkHbMovies_args_update_actors0_delete0_delete_movies0_where_ZGTAXkHBMovieparam0
WITH this, meta, this_actors0_delete0, this_actors0_delete0_relationship, collect(DISTINCT this_actors0_delete0_movies0) AS this_actors0_delete0_movies0_to_delete, this_actors0_delete0_movies0_relationship
WITH this, this_actors0_delete0, this_actors0_delete0_relationship, this_actors0_delete0_movies0_to_delete, REDUCE(m=meta, n IN this_actors0_delete0_movies0_to_delete | m + { event: "delete", id: id(n), properties: { old: n { .* }, new: null }, timestamp: timestamp(), typename: "ZGTAXkHBMovie" } + { event: "delete_relationship", timestamp: timestamp(), id_from: id(this_actors0_delete0), id_to: id(n), id: id(this_actors0_delete0_movies0_relationship), relationshipName: "ACTED_IN", fromTypename: "PHBtYviKActor", toTypename: "ZGTAXkHBMovie", properties: { from: this_actors0_delete0 { .* }, to: n { .* }, relationship: this_actors0_delete0_movies0_relationship { .* } } }) AS meta
CALL {
	WITH this_actors0_delete0_movies0_to_delete
	UNWIND this_actors0_delete0_movies0_to_delete AS x
	DETACH DELETE x
	RETURN count(*) AS _
}
WITH this, this_actors0_delete0, this_actors0_delete0_relationship, collect(distinct meta) AS update_meta
WITH this, this_actors0_delete0, this_actors0_delete0_relationship, REDUCE(m=[], n IN update_meta | m + n) AS meta
WITH this, meta, collect(DISTINCT this_actors0_delete0) AS this_actors0_delete0_to_delete, this_actors0_delete0_relationship
WITH this, this_actors0_delete0_to_delete, REDUCE(m=meta, n IN this_actors0_delete0_to_delete | m + { event: "delete", id: id(n), properties: { old: n { .* }, new: null }, timestamp: timestamp(), typename: "PHBtYviKActor" } + { event: "delete_relationship", timestamp: timestamp(), id_from: id(n), id_to: id(this), id: id(this_actors0_delete0_relationship), relationshipName: "ACTED_IN", fromTypename: "PHBtYviKActor", toTypename: "ZGTAXkHBMovie", properties: { from: n { .* }, to: this { .* }, relationship: this_actors0_delete0_relationship { .* } } }) AS meta
CALL {
	WITH this_actors0_delete0_to_delete
	UNWIND this_actors0_delete0_to_delete AS x
	DETACH DELETE x
	RETURN count(*) AS _
}
WITH this, collect(distinct meta) AS update_meta
WITH this, REDUCE(m=[], n IN update_meta | m + n) AS meta
WITH this, meta
CREATE (this_actors0_create0_node:PHBtYviKActor)
SET this_actors0_create0_node.name = $this_actors0_create0_node_name
CREATE (this_actors0_create0_node_movies0_node:ZGTAXkHBMovie)
SET this_actors0_create0_node_movies0_node.id = $this_actors0_create0_node_movies0_node_id
SET this_actors0_create0_node_movies0_node.name = $this_actors0_create0_node_movies0_node_name
WITH meta + { event: "create", id: id(this_actors0_create0_node_movies0_node), properties: { old: null, new: this_actors0_create0_node_movies0_node { .* } }, timestamp: timestamp(), typename: "ZGTAXkHBMovie" } AS meta, this, this_actors0_create0_node, this_actors0_create0_node_movies0_node
MERGE (this_actors0_create0_node)-[this_actors0_create0_node_movies0_relationship:ACTED_IN]->(this_actors0_create0_node_movies0_node)
WITH meta + { event: "create_relationship", timestamp: timestamp(), id_from: id(this_actors0_create0_node), id_to: id(this_actors0_create0_node_movies0_node), id: id(this_actors0_create0_node_movies0_relationship), relationshipName: "ACTED_IN", fromTypename: "PHBtYviKActor", toTypename: "ZGTAXkHBMovie", properties: { from: this_actors0_create0_node { .* }, to: this_actors0_create0_node_movies0_node { .* }, relationship: this_actors0_create0_node_movies0_relationship { .* } } } AS meta, this, this_actors0_create0_node, this_actors0_create0_node_movies0_node
WITH meta + { event: "create", id: id(this_actors0_create0_node), properties: { old: null, new: this_actors0_create0_node { .* } }, timestamp: timestamp(), typename: "PHBtYviKActor" } AS meta, this, this_actors0_create0_node
MERGE (this)<-[this_actors0_create0_relationship:ACTED_IN]-(this_actors0_create0_node)
WITH meta + { event: "create_relationship", timestamp: timestamp(), id_from: id(this_actors0_create0_node), id_to: id(this), id: id(this_actors0_create0_relationship), relationshipName: "ACTED_IN", fromTypename: "PHBtYviKActor", toTypename: "ZGTAXkHBMovie", properties: { from: this_actors0_create0_node { .* }, to: this { .* }, relationship: this_actors0_create0_relationship { .* } } } AS meta, this, this_actors0_create0_node
	RETURN meta as update_meta
}
WITH *, update_meta as meta
WITH this, meta + { event: "update", id: id(this), properties: { old: oldProps, new: this { .* } }, timestamp: timestamp(), typename: "ZGTAXkHBMovie" } AS meta

WITH *
CALL {
    WITH this
    MATCH (this_actors:`PHBtYviKActor`)-[update_this0:ACTED_IN]->(this)
    WITH this_actors { .name } AS this_actors
    RETURN collect(this_actors) AS this_actors
}
WITH *
UNWIND (CASE meta WHEN [] then [null] else meta end) AS m
RETURN collect(DISTINCT this { .id, actors: this_actors }) AS data, collect(DISTINCT m) as meta

Moved to Trello!