From 5b45752e28c1f6d5d85795b69d69562b9c184282 Mon Sep 17 00:00:00 2001 From: bkellam Date: Wed, 2 Apr 2025 23:28:00 -0700 Subject: [PATCH 1/2] Add reposet token type to zoekt parser --- .vscode/launch.json | 14 ++++++++++++++ query/parse.go | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index 6c254f63b..a42bf33e5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -22,6 +22,20 @@ "cwd": "${workspaceFolder}", "args": ["-index", "${input:indexPath}"] }, + { + "name": "Webserver (rpc)", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "cmd/zoekt-webserver", + "cwd": "${workspaceFolder}", + "args": ["-index", "${input:indexPath}", "-rpc"], + // Set a long watchdog tick to help with debugging + "env": { + "ZOEKT_WATCHDOG_TICK": "24h", + "SRC_LOG_LEVEL": "debug" + } + }, { "name": "Attach to Process (from list)", "type": "go", diff --git a/query/parse.go b/query/parse.go index d8762f191..3eb911f66 100644 --- a/query/parse.go +++ b/query/parse.go @@ -19,6 +19,7 @@ import ( "fmt" "log" "regexp/syntax" + "strings" "github.com/grafana/regexp" "github.com/sourcegraph/zoekt/internal/languages" @@ -239,6 +240,22 @@ func parseExpr(in []byte) (Q, int, error) { } // Later we will lift this into a root, like we do for caseQ expr = &Type{Type: t, Child: nil} + case tokRepoSet: + if text == "" { + return nil, 0, fmt.Errorf("the reposet: atom must have an argument") + } + + // Split the text by commas to get individual repo names + repos := strings.Split(text, ",") + set := make(map[string]bool) + for _, repo := range repos { + repo = strings.TrimSpace(repo) + if repo != "" { + set[repo] = true + } + } + + expr = &RepoSet{Set: set} } return expr, len(in) - len(b), nil @@ -392,6 +409,7 @@ const ( tokArchived = 15 tokPublic = 16 tokFork = 17 + tokRepoSet = 18 ) var tokNames = map[int]string{ @@ -412,6 +430,7 @@ var tokNames = map[int]string{ tokLang: "Language", tokSym: "Symbol", tokType: "Type", + tokRepoSet: "RepoSet", } var prefixes = map[string]int{ @@ -432,6 +451,7 @@ var prefixes = map[string]int{ "sym:": tokSym, "t:": tokType, "type:": tokType, + "reposet:": tokRepoSet, } var reservedWords = map[string]int{ From 9a96ce58808ce6bde5cec47e8325a62e07cae0a7 Mon Sep 17 00:00:00 2001 From: bkellam Date: Wed, 23 Apr 2025 14:07:53 -0700 Subject: [PATCH 2/2] remove the 'reposet atom must have an argument' constraint to handle when a search context is empty. --- query/parse.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/query/parse.go b/query/parse.go index 3eb911f66..a9ffd23e8 100644 --- a/query/parse.go +++ b/query/parse.go @@ -241,10 +241,6 @@ func parseExpr(in []byte) (Q, int, error) { // Later we will lift this into a root, like we do for caseQ expr = &Type{Type: t, Child: nil} case tokRepoSet: - if text == "" { - return nil, 0, fmt.Errorf("the reposet: atom must have an argument") - } - // Split the text by commas to get individual repo names repos := strings.Split(text, ",") set := make(map[string]bool)