Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

feat: ability to search in installed apidocs #66

Open
wants to merge 2 commits into
base: master
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 10 additions & 0 deletions lua/nvim-devdocs/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 = "?" })
Expand Down
6 changes: 5 additions & 1 deletion lua/nvim-devdocs/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down