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
3 changes: 3 additions & 0 deletions lua/csgithub/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ M.search = function(args)

local query = require("csgithub.query")
local q = query.construct_query(merged_args)
if q == nil then
return nil
end
local url = query.construct_url(q)

return url
Expand Down
21 changes: 16 additions & 5 deletions lua/csgithub/query.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
local M = {}

--- useful for visual line mode when extra whitespace is
--- included in search query
--- @param s string
local function trim_string(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end

M.construct_query_path = function(args)
local ext = vim.fn.expand("%:e")

Expand Down Expand Up @@ -27,14 +34,14 @@ end
M.construct_query_text = function()
local utils = require("csgithub.utils")
local text = ""
if vim.fn.mode() == "v" then
-- visual mode
text = utils.get_visual_selection()
local mode = vim.api.nvim_get_mode().mode
if mode == "v" or mode == "V" then
-- visual mode, visual line mode
text = trim_string(utils.get_visual_selection())
else
-- normal mode
text = vim.fn.expand("<cword>")
end

return text
end

Expand All @@ -43,6 +50,10 @@ end
M.construct_query = function(args)
local query_parts = {}

local query_text = M.construct_query_text()
if query_text == "" then
return nil
end
-- path:
if args.includeFilename or args.includeExtension then
local path = M.construct_query_path(args)
Expand All @@ -51,7 +62,7 @@ M.construct_query = function(args)
end

-- text
table.insert(query_parts, M.construct_query_text())
table.insert(query_parts, query_text)

return table.concat(query_parts, " ")
end
Expand Down