sentry icon indicating copy to clipboard operation
sentry copied to clipboard

feat(search-syntax): Add option to flatten paren groups

Open malwilley opened this issue 9 months ago • 2 comments

Ref https://github.com/getsentry/sentry/issues/70953

For the new search component, parens will need to be parsed as separate tokens and the parser cannot error out when faced with mismatched parens. Therefore the parser should be updated to allow for this.

I've added a new token type, PAREN, which may be returned as part of the parse result. When there are mismatched parentheses, this is now matched which allows the parser to return a successful result. A new config option has been added, flattenParenGroups (name could be workshopped), which causes the PAREN token to take precedence over LOGIC_GROUP and thus return parens separately from the contents when enabled. When disabled (the default), logic groups are still returned as you would expect.

Previous behavior:

  • Unmatched parens will throw an error and return nothing from the parser
  • Matched parens are parsed as a LOGIC_GROUP with boolean operators, free text, and filters inside the token.inner array.

New behavior (with the default flattenParenGroups=false):

  • Unmatched parens will not throw an error. The parser will return a normal result, with the unmatched parens parsed as a PAREN token.
  • Matched parens will return a LOGIC_GROUP as normal.

New behavior (with the new flattenParenGroups=true):

  • Unmatched parens will not throw an error. The parser will return a normal result, with the unmatched parens parsed as a PAREN token.
  • Matched parens will not return a LOGIC_GROUP

You can see now that syntax highlighting is no longer broken when adding a mismatched paren:

CleanShot 2024-05-15 at 09 47 04 CleanShot 2024-05-15 at 09 47 18

malwilley avatar May 15 '24 16:05 malwilley

Bundle Report

Changes will increase total bundle size by 17.57kB :arrow_up:

Bundle name Size Change
app-webpack-bundle-array-push 27.67MB 17.57kB :arrow_up:

codecov[bot] avatar May 15 '24 16:05 codecov[bot]

@evanpurkhiser I found a fixed a couple other edge cases I found if you want to take another look!

malwilley avatar May 17 '24 18:05 malwilley