Skip to content

Commit 259555d

Browse files
Added support for non-beta search users (#1)
* add support for non-beta search users Without this change, users who haven't opted into the beta-search are met with a syntax error when launching their browser. I added an additional flag to modify what goes into the query. Tested this by trying every combination locally and it worked as expected. * format * set default betaSearch value to true --------- Co-authored-by: nbe <[email protected]>
1 parent 572a3d7 commit 259555d

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ https://user-images.githubusercontent.com/33713262/226383032-113b4db8-27a3-4b8f-
2323
local url = csgithub.search({
2424
includeFilename = false,
2525
includeExtension = true,
26+
betaSearch = true, -- set to false if you haven't opted in to GitHub Code Search (beta)
2627
})
2728

2829
csgithub.open(url)

lua/csgithub/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ M.search = function(args)
66
local default_args = {
77
includeFilename = false,
88
includeExtension = true,
9+
betaSearch = true,
910
}
1011

1112
local merged_args = vim.tbl_extend("force", default_args, args or {})

lua/csgithub/query.lua

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@ local M = {}
33
M.construct_query_path = function(args)
44
local ext = vim.fn.expand("%:e")
55

6-
if args.includeExtension and not args.includeFilename then
6+
local onlyExtension = args.includeExtension and not args.includeFilename
7+
8+
if onlyExtension and args.betaSearch then
79
return "*." .. ext
10+
elseif onlyExtension then
11+
return "." .. ext
812
else
913
return vim.fn.expand("%:t")
1014
end
1115
end
1216

17+
M.construct_search_field = function(args)
18+
if not args.betaSearch and args.includeFilename then
19+
return "filename:"
20+
elseif not args.betaSearch and args.includeExtension then
21+
return "extension:"
22+
else
23+
return "path:"
24+
end
25+
end
26+
1327
M.construct_query_text = function()
1428
local utils = require("csgithub.utils")
1529
local text = ""
@@ -32,7 +46,8 @@ M.construct_query = function(args)
3246
-- path:
3347
if args.includeFilename or args.includeExtension then
3448
local path = M.construct_query_path(args)
35-
table.insert(query_parts, "path:" .. path)
49+
local search_field = M.construct_search_field(args)
50+
table.insert(query_parts, search_field .. path)
3651
end
3752

3853
-- text

0 commit comments

Comments
 (0)