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

Commit 803faeb

Browse files
Feature: Open Devdocs by buffers filetype (#12)
* Open_current_filetype. Made the function and CMD mapping for the function * Open_current_file: Added a float option aswell * Reverted previous implementation. Misunderstood what float option did * Also removed the cmd for float I added * Added documentation to README for DevdocsOpenCurrentFile * fix: filetypes and cmds Moved filetypes to another file and fixed wrong filetypes, also bring :DevdocsOpenFloat back * README: OpenCurrentFile argument description I'm not sure how to best describe the argument change you made to the function, so I just did the same thing as done above (0 or 1 args) * update: changed cmd Made the name shorter and use two different cmd --------- Co-authored-by: Luckas <[email protected]>
1 parent 2f4cdae commit 803faeb

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Available commands:
9191
- `DevdocsUninstall`: Uninstall documentation, 0-n args.
9292
- `DevdocsOpen`: Open documentation in a normal buffer, 0 or 1 arg.
9393
- `DevdocsOpenFloat`: Open documentation in a floating window, 0 or 1 arg.
94+
- `DevdocsOpenCurrent`: Open documentation for the current filetype in a normal buffer.
95+
- `DevdocsOpenCurrentFloat`: Open documentation for the current filetype in a floating window.
9496
- `DevdocsUpdate`: Update documentation, 0-n args.
9597
- `DevdocsUpdateAll`: Update all documentations.
9698

lua/nvim-devdocs/filetypes.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local M = {
2+
["sh"] = "bash",
3+
["lua"] = "lua-5.4",
4+
["vue"] = "vue-3",
5+
["dart"] = "dart-2",
6+
["ruby"] = "ruby-3.2",
7+
["twig"] = "twig-3",
8+
["less"] = "less-4",
9+
["javascriptreact"] = "react",
10+
["typescriptreact"] = "react",
11+
}
12+
13+
return M

lua/nvim-devdocs/init.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local pickers = require("nvim-devdocs.pickers")
66
local operations = require("nvim-devdocs.operations")
77
local config = require("nvim-devdocs.config")
88
local completion = require("nvim-devdocs.completion")
9+
local filetypes = require("nvim-devdocs.filetypes")
910

1011
M.fetch_registery = function() operations.fetch() end
1112

@@ -43,6 +44,12 @@ M.open_doc_float = function(args)
4344
end
4445
end
4546

47+
M.open_doc_current_file = function(float)
48+
local filetype = vim.bo.filetype
49+
local alias = filetypes[filetype] or filetype
50+
pickers.open_picker(alias, float)
51+
end
52+
4653
M.update = function(args)
4754
if vim.tbl_isempty(args.fargs) then
4855
pickers.update_picker()
@@ -75,6 +82,8 @@ M.setup = function(opts)
7582
cmd("DevdocsUninstall", M.uninstall_doc, { nargs = "*", complete = completion.get_installed })
7683
cmd("DevdocsOpen", M.open_doc, { nargs = "?", complete = completion.get_installed })
7784
cmd("DevdocsOpenFloat", M.open_doc_float, { nargs = "?", complete = completion.get_installed })
85+
cmd("DevdocsOpenCurrent", function() M.open_doc_current_file() end, {})
86+
cmd("DevdocsOpenCurrentFloat", function() M.open_doc_current_file(true) end, {})
7887
cmd("DevdocsUpdate", M.update, { nargs = "*", complete = completion.get_updatable })
7988
cmd("DevdocsUpdateAll", M.update_all, {})
8089
end

0 commit comments

Comments
 (0)