Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SearchResults Provider #205

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ using multiple then you must provide an array table for `provider`.
-- source provider function
local diagnostic = require('galaxyline.provider_diagnostic')
local vcs = require('galaxyline.provider_vcs')
local search = require('galaxyline.provider_search')
local fileinfo = require('galaxyline.provider_fileinfo')
local extension = require('galaxyline.provider_extensions')
local colors = require('galaxyline.colors')
local buffer = require('galaxyline.provider_buffer')
local whitespace = require('galaxyline.provider_whitespace')
local lspclient = require('galaxyline.provider_lsp')

-- provider
-- provider
BufferIcon = buffer.get_buffer_type_icon,
BufferNumber = buffer.get_buffer_number,
FileTypeName = buffer.get_buffer_filetype,
Expand All @@ -99,6 +100,8 @@ GitBranch = vcs.get_git_branch,
DiffAdd = vcs.diff_add, -- support vim-gitgutter vim-signify gitsigns
DiffModified = vcs.diff_modified, -- support vim-gitgutter vim-signify gitsigns
DiffRemove = vcs.diff_remove, -- support vim-gitgutter vim-signify gitsigns
-- Search Provider
SearchResults = search.get_search_results,
-- File Provider
LineColumn = fileinfo.line_column,
FileFormat = fileinfo.get_file_format,
Expand Down Expand Up @@ -133,7 +136,7 @@ local condition = require('galaxyline.condition')
condition.buffer_not_empty -- if buffer not empty return true else false
condition.hide_in_width -- if winwidth(0)/ 2 > 40 true else false
-- find git root, you can use this to check if the project is a git workspace
condition.check_git_workspace()
condition.check_git_workspace()

-- built-in theme
local colors = require('galaxyline.theme').default
Expand Down
2 changes: 2 additions & 0 deletions lua/galaxyline/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ async_load_providers = uv.new_async(vim.schedule_wrap(function ()
local vcs = require('galaxyline.provider_vcs')
local fileinfo = require('galaxyline.provider_fileinfo')
local buffer = require('galaxyline.provider_buffer')
local search = require('galaxyline.provider_search')
local extension = require('galaxyline.provider_extensions')
local whitespace =require('galaxyline.provider_whitespace')
local lspclient = require('galaxyline.provider_lsp')
Expand All @@ -27,6 +28,7 @@ async_load_providers = uv.new_async(vim.schedule_wrap(function ()
ScrollBar = extension.scrollbar_instance,
VistaPlugin = extension.vista_nearest,
WhiteSpace = whitespace.get_item,
SearchResults = search.get_search_results,
GetLspClient = lspclient.get_lsp_client,
}
local diagnostic = require('galaxyline.provider_diagnostic')
Expand Down
14 changes: 14 additions & 0 deletions lua/galaxyline/provider_search.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local vim = vim
local M = {}

function M.get_search_results()
local search_term = vim.fn.getreg('/')
local search_count = vim.fn.searchcount({recompute = 1, maxcount = -1})
local active = vim.v.hlsearch == 1 and search_count.total > 0

if active then
return '/' .. search_term .. '[' .. search_count.current .. '/' .. search_count.total .. ']'
end
end

return M