Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

query parsing: Simplify parser and extract analysis function#50554

Merged
fkling merged 4 commits into
mainfrom
fkling/refactor-query-parser
Apr 17, 2023
Merged

query parsing: Simplify parser and extract analysis function#50554
fkling merged 4 commits into
mainfrom
fkling/refactor-query-parser

Conversation

@fkling

@fkling fkling commented Apr 12, 2023

Copy link
Copy Markdown
Contributor

NOTE: Ignore white space changes for review

This commit aims to extract the "relevant tokens" logic to make it usable in other contexts. To be able to produce a valid token sequence from the parse tree with more confidence I'm changing the structure of the parse tree:

  • Operators have a left and a right operand instead of, theoretically, have an unlimited number of operands. In practice the nodes array has always at most two entries, but the current structure doesn't make that clear. Rather than implicitly relying on this fact when processing operator nodes I'm encoding this explicitly into the tree.
  • The parse function now returns a single node, not a list of nodes. In practice we've always only processed the first node anyways. Now it is clearer that the function only returns a single node.

Test plan

  • New unit tests
  • Enter query into search input and verify that the correct suggestion queries are sent.

App preview:

Check out the client app preview documentation to learn more.

@fkling fkling requested review from a team and camdencheek April 12, 2023 13:38
@cla-bot cla-bot Bot added the cla-signed label Apr 12, 2023
@sourcegraph-bot

sourcegraph-bot commented Apr 12, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff cfe99fb...f4b0a70.

Notify File(s)
@limitedmage client/web/src/search/input/suggestions.ts

@camdencheek camdencheek Apr 14, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was quoted removed from the Pattern interface?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quoted and negated have always been set to false so they didn't seem to offer any value.

@camdencheek

Copy link
Copy Markdown
Member

sorry for the slow review! LGTM

fkling added 3 commits April 17, 2023 12:04
This commit aims to extract the "relevant tokens" logic to make it
usable in other contexts. To be able to produce a valid token sequence
from the parse tree with more confidence I'm changing the structure of
the parse tree to

- reuse existing pattern and filter tokens as leaves
- make operators have a `left` and a `right` side instead of,
  theoretically, have an unlimited number of operands. In practice the
  `nodes` array has always at most two entries, but the current
  structure doesn't make that clear. Rather than implicitly relying on
  this fact when processing operator nodes I'm encoding this explicitly
  into the tree.
@fkling fkling force-pushed the fkling/refactor-query-parser branch from 643739d to a99f681 Compare April 17, 2023 10:04
@sg-e2e-regression-test-bob

sg-e2e-regression-test-bob commented Apr 17, 2023

Copy link
Copy Markdown

Bundle size report 📦

Initial size Total size Async size Modules
0.00% (0.00 kb) 0.00% (+0.37 kb) 0.00% (+0.37 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits f4b0a70 and cfe99fb or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

@fkling fkling merged commit fe84e50 into main Apr 17, 2023
@fkling fkling deleted the fkling/refactor-query-parser branch April 17, 2023 11:54
fkling added a commit that referenced this pull request Apr 17, 2023
At the moment symbol suggestions will always insert 'type:symbol',
which can produce incorrect queries if the current query already
contains a 'type:' filter.

This PR builds on top of #50554 and only inserts a 'type:' filter if the
relevant branch of the query doesn't already contain one.
fkling added a commit that referenced this pull request Apr 17, 2023
At the moment symbol suggestions will always insert 'type:symbol', which
can produce incorrect queries if the current query already contains a
'type:' filter. This PR builds on top of #50554 and only inserts a
'type:' filter if the relevant branch of the query doesn't already
contain one.



https://user-images.githubusercontent.com/179026/231516689-6c1b0a73-d25a-41cc-b032-e7a3d081ef5a.mp4



## Test plan

- Enter a query into the search input that triggers symbols suggestions
and select a symbol suggestions -> the suggestion is inserted with
`type:symbol`
- Like above but also include e.g. `type:diff` in the query -> only the
symbol name (not `type:symbol`) is inserted into the input

## App preview:

- [Web](https://sg-web-fkling-search-input-symbol.onrender.com/search)

Check out the [client app preview
documentation](https://docs.sourcegraph.com/dev/how-to/client_pr_previews)
to learn more.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants