diff --git a/README.md b/README.md index 13d9db5..fb27afd 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ Available commands: - `DevdocsOpenFloat`: Open documentation in a floating window, 0 or 1 arg. - `DevdocsOpenCurrent`: Open documentation for the current filetype in a normal buffer. - `DevdocsOpenCurrentFloat`: Open documentation for the current filetype in a floating window. +- `DevdocsGrep`: Search in the installed apidocs. - `DevdocsUpdate`: Update documentation, 0-n args. - `DevdocsUpdateAll`: Update all documentations. diff --git a/lua/nvim-devdocs/init.lua b/lua/nvim-devdocs/init.lua index 4178833..4b175c5 100644 --- a/lua/nvim-devdocs/init.lua +++ b/lua/nvim-devdocs/init.lua @@ -72,6 +72,15 @@ M.keywordprg = function(args) end end +M.grep = function(args) + if vim.tbl_isempty(args.fargs) then + pickers.open_picker_grep("") + else + local alias = args.fargs[1] + pickers.open_picker_grep(alias) + end +end + M.setup = function(opts) config.setup(opts) @@ -86,6 +95,7 @@ M.setup = function(opts) cmd("DevdocsUninstall", M.uninstall_doc, { nargs = "*", complete = completion.get_installed }) cmd("DevdocsOpen", M.open_doc, { nargs = "?", complete = completion.get_installed }) cmd("DevdocsOpenFloat", M.open_doc_float, { nargs = "?", complete = completion.get_installed }) + cmd("DevdocsGrep", M.grep, { nargs = "?", complete = completion.get_installed }) cmd("DevdocsOpenCurrent", function() M.open_doc_current_file() end, {}) cmd("DevdocsOpenCurrentFloat", function() M.open_doc_current_file(true) end, {}) cmd("DevdocsKeywordprg", M.keywordprg, { nargs = "?" }) diff --git a/lua/nvim-devdocs/pickers.lua b/lua/nvim-devdocs/pickers.lua index 177e557..01605d2 100644 --- a/lua/nvim-devdocs/pickers.lua +++ b/lua/nvim-devdocs/pickers.lua @@ -48,7 +48,7 @@ local metadata_previewer = previewers.new_buffer_previewer({ local doc_previewer = previewers.new_buffer_previewer({ title = "Preview", - keep_last_buf = true, + -- keep_last_buf = true, define_preview = function(self, entry) local bufnr = self.state.bufnr @@ -176,6 +176,10 @@ M.open_picker = function(entries, float) picker:find() end +M.open_picker_grep = function(subfolder) + require('telescope.builtin').live_grep({cwd=DOCS_DIR:joinpath(subfolder).filename}) +end + ---@param alias string ---@param float? boolean M.open_picker_alias = function(alias, float)