postgres-language-server
postgres-language-server copied to clipboard
Add `SiblingToken`s back to the parser
Sibling tokens are tokens that should end up at the same depth in the CST, such as ( and ). Right now, that is not the case. Take for example the following statement:
ALTER TABLE products ALTER COLUMN price TYPE numeric(10,2);
The brackets of numeric are not on the same level:
[email protected]
[email protected] "ALTER"
[email protected] " "
[email protected] "TABLE"
[email protected] " "
[email protected]
[email protected] "products"
[email protected] " "
[email protected]
[email protected] "ALTER"
[email protected] " "
[email protected] "COLUMN"
[email protected] " "
[email protected] "price"
[email protected] " "
[email protected] "TYPE"
[email protected] " "
[email protected]
[email protected]
[email protected] "numeric"
[email protected] "(" <-- this is deeper than
[email protected]
[email protected] "10"
[email protected] ","
[email protected]
[email protected] "2"
[email protected] ")" <-- this
[email protected] ";"
To fix this, we have to keep track the depth at which tokens are "opened". If the closing token is encountered, we apply it at the same depth as its sibling.
A SiblingToken struct already exists from past implementations. It should be reused.