Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search: allow queries to contain \n (special case of multiline search) #4138

Closed
ijt opened this issue May 20, 2019 · 2 comments

Comments

@ijt
Copy link
Contributor

commented May 20, 2019

This is a subset of the functionality proposed in #35, but easier to implement in a performant way.

@ijt ijt added the search label May 20, 2019

@ijt ijt added this to the 3.5 milestone May 20, 2019

@slimsag

This comment has been minimized.

Copy link
Member

commented May 20, 2019

The idea here is that queries today have a structure like the following EBNF grammar (explanation):

LineMatch = Regexp | QuotedStringLiteral ;
Query     = [ SearchFilters ] , LineMatch , [ SearchFilters ] ;

This is to say that you can specify search filters on either side of your regexp or "quoted string literal" search, and we'll find any lines in files that contain that LineMatch, up to the newline.

After this change, you would be able to specify any number of newlines and LineMatch to search across multiple consecutive lines:

LineMatch = Regexp | QuotedStringLiteral ;
Query     = { [ SearchFilters ] , LineMatch , [ SearchFilters ] , NewlineMatch } ;

Example:

package main

func main() {
    fmt.Println("foobar")
}
  • Query package .*\n\n"func main() {" would match lines 1 (package .*\n), 2 (\n), and 3 ("func main() {") above.
  • Query func .*\(\)\s\{\n.*\n} would match lines 3 (func .*\(\)\s{\n), 4 (.*\n), and 5 (}).

In other words, this allows searching over multiple consecutive lines.

What it doesn't allow (which is harder to do, and what #35 would allow for) us full-blown multi line search where you could write: package main.*} and match the entire file above (.* matching multiple lines).

@slimsag

This comment has been minimized.

Copy link
Member

commented May 23, 2019

There are some further examples in the third item of sourcegraph/infrastructure#1475 (comment) which may be more understandable than the above specifics at a high level.

Also, as mentioned in sourcegraph/infrastructure#1475 (comment) for the $CUSTOMER in question this would be intrinsically dependent on also having #4135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.