Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ https://user-images.githubusercontent.com/33713262/226383032-113b4db8-27a3-4b8f-
local url = csgithub.search({
includeFilename = false,
includeExtension = true,
betaSearch = true, -- set to false if you haven't opted in to GitHub Code Search (beta)
})

csgithub.open(url)
Expand Down
1 change: 1 addition & 0 deletions lua/csgithub/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ M.search = function(args)
local default_args = {
includeFilename = false,
includeExtension = true,
betaSearch = true,
}

local merged_args = vim.tbl_extend("force", default_args, args or {})
Expand Down
19 changes: 17 additions & 2 deletions lua/csgithub/query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@ local M = {}
M.construct_query_path = function(args)
local ext = vim.fn.expand("%:e")

if args.includeExtension and not args.includeFilename then
local onlyExtension = args.includeExtension and not args.includeFilename

if onlyExtension and args.betaSearch then
return "*." .. ext
elseif onlyExtension then
return "." .. ext
else
return vim.fn.expand("%:t")
end
end

M.construct_search_field = function(args)
if not args.betaSearch and args.includeFilename then
return "filename:"
elseif not args.betaSearch and args.includeExtension then
return "extension:"
else
return "path:"
end
end

M.construct_query_text = function()
local utils = require("csgithub.utils")
local text = ""
Expand All @@ -32,7 +46,8 @@ M.construct_query = function(args)
-- path:
if args.includeFilename or args.includeExtension then
local path = M.construct_query_path(args)
table.insert(query_parts, "path:" .. path)
local search_field = M.construct_search_field(args)
table.insert(query_parts, search_field .. path)
end

-- text
Expand Down