Skip to content

Commit

Permalink
feat: add SearchResults provider, see glepnir#205
Browse files Browse the repository at this point in the history
  • Loading branch information
NTBBloodbath committed Sep 17, 2021
1 parent 8377f81 commit 2129bcf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,23 @@ using multiple then you must provide an array table for `provider`.
```lua
---- source provider functions
-- Code diagnostics
local diagnostic = require("galaxyline.provider_diagnostic")
local diagnostic = require("galaxyline.providers.diagnostic")
-- Version control
local vcs = require("galaxyline.provider_vcs")
local vcs = require("galaxyline.providers.vcs")
-- Core files information
local fileinfo = require("galaxyline.provider_fileinfo")
-- File extension
local extension = require("galaxyline.provider_extensions")
local fileinfo = require("galaxyline.providers.fileinfo")
-- Extensions, aka plugins
local extension = require("galaxyline.providers.extensions")
-- Neovim highlighting
local colors = require("galaxyline.colors")
local colors = require("galaxyline.highlighting")
-- Buffer information, e.g. corresponding icon
local buffer = require("galaxyline.provider_buffer")
local buffer = require("galaxyline.providers.buffer")
-- Search results
local search = require("galaxyline.providers.search")
-- Spacing
local whitespace = require("galaxyline.provider_whitespace")
local whitespace = require("galaxyline.providers.whitespace")
-- Active language server information
local lspclient = require("galaxyline.provider_lsp")
local lspclient = require("galaxyline.providers.lsp")


---- Providers
Expand All @@ -100,6 +102,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 All @@ -123,9 +127,9 @@ GetLspClient = lspclient.get_lsp_client

---- Public libs
-- Get file icon color
require("galaxyline.provider_fileinfo").get_file_icon_color
require("galaxyline.providers.fileinfo").get_file_icon_color
-- Custom file icon with color
local my_icons = require("galaxyline.provider_fileinfo").define_file_icon()
local my_icons = require("galaxyline.providers.fileinfo").define_file_icon()
my_icons['your file type here'] = { color code, icon}
-- If your filetype does is not defined in neovim you can use file extensions
my_icons['your file ext in here'] = { color code, icon}
Expand Down
2 changes: 2 additions & 0 deletions lua/galaxyline/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local function load_providers()
local vcs = require("galaxyline.providers.vcs")
local fileinfo = require("galaxyline.providers.fileinfo")
local buffer = require("galaxyline.providers.buffer")
local search = require("galaxyline.providers.search")
local extension = require("galaxyline.providers.extensions")
local whitespace = require("galaxyline.providers.whitespace")
local lspclient = require("galaxyline.providers.lsp")
Expand All @@ -26,6 +27,7 @@ local function load_providers()
VistaPlugin = extension.vista_nearest,
WhiteSpace = whitespace.get_item,
GetLspClient = lspclient.get_lsp_client,
SearchResults = search.get_search_results,
}

local diagnostic = require("galaxyline.providers.diagnostic")
Expand Down
16 changes: 16 additions & 0 deletions lua/galaxyline/providers/search.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local search = {}

function search.get_results()
local search_term = vim.fn.getreg("/")
local search_count = vim.fn.searchcount({
recompute = 1,
maxcount = -1,
})

local active_result = vim.v.hlsearch == 1 and search_count.total > 0
if active_result then
return string.format("/%s [%d/%d]", search_term, search_count.current, search_count.total)
end
end

return search

0 comments on commit 2129bcf

Please sign in to comment.