fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

fix/query: resolve type lifting after OR parsing (#1023)

The parser used to lift `type:` directives before converting `or` placeholders into real boolean nodes. That let parse-time `orOp` sentinels leak into `Type` children for unparenthesized queries and allowed malformed inputs like `type:repo or` to parse successfully until runtime.

Resolve operator placeholders before wrapping with `Type` so unparenthesized `or` inside a type scope produces a valid `Or` subtree and malformed `or` placement is rejected during parsing. The docs now clarify that `type:` applies to the whole expression in its current scope, including `or` clauses.

Amp-Thread-ID: https://ampcode.com/threads/T-019d0be7-4c9d-76fd-b556-103420d14be9
Co-authored-by: Amp <amp@ampcode.com>

author
Keegan Carruthers-Smith
co-author
Amp
committer
GitHub
date (Mar 23, 2026, 11:23 AM +0200) commit ed735fa5 parent cf273848
+13 -1
+5
doc/query_syntax.md
··· 111 111 - `filename` - Returns only matching filenames 112 112 - `repo` - Returns only repository names 113 113 114 + `type:` applies to the whole expression in its current scope, including `or` 115 + clauses. For example, `type:repo foo or bar` is equivalent to 116 + `type:repo (foo or bar)`. Use parentheses to scope `type:` to only one branch, 117 + for example `(type:repo foo) or bar`. 118 + 114 119 --- 115 120 116 121 ## Special Query Values
+5 -1
query/parse.go
··· 416 416 return q 417 417 }) 418 418 if typeT != 100 { 419 - qs = []Q{&Type{Type: typeT, Child: NewAnd(qs...)}} 419 + typedQ, err := parseOperators(qs) 420 + if err != nil { 421 + return nil, 0, err 422 + } 423 + qs = []Q{&Type{Type: typeT, Child: typedQ}} 420 424 } 421 425 422 426 if hasCaseScope {
+3
query/parse_test.go
··· 132 132 // type 133 133 {"type:repo abc", &Type{Type: TypeRepo, Child: &Substring{Pattern: "abc"}}}, 134 134 {"type:file abc def", &Type{Type: TypeFileName, Child: NewAnd(&Substring{Pattern: "abc"}, &Substring{Pattern: "def"})}}, 135 + {"type:repo foo or bar", &Type{Type: TypeRepo, Child: NewOr(&Substring{Pattern: "foo"}, &Substring{Pattern: "bar"})}}, 135 136 {"(type:repo abc) def", NewAnd(&Type{Type: TypeRepo, Child: &Substring{Pattern: "abc"}}, &Substring{Pattern: "def"})}, 136 137 137 138 // errors. ··· 144 145 {"abc or", nil}, 145 146 {"or abc", nil}, 146 147 {"def or or abc", nil}, 148 + {"type:repo or", nil}, 149 + {"or type:repo", nil}, 147 150 148 151 // unbalanced parentheses 149 152 {"(", nil},