mirror of
https://github.com/LhKipp/nvim-nu
synced 2024-09-16 14:24:01 +02:00
Implement showing help via lsp hover not via keywordprg (Credit: SirZenith)
This commit is contained in:
parent
6d33e23d47
commit
c3c92bb3f2
4 changed files with 45 additions and 13 deletions
11
README.md
11
README.md
|
@ -20,7 +20,7 @@
|
|||
- Neovim version >= 0.5
|
||||
- A [nu](https://github.com/nushell/nushell/releases) binary in your path
|
||||
- [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter/blob/master/README.md#quickstart) installed
|
||||
- [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) if nu-command names shall be suggested
|
||||
- Optionally [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) to enable lsp features like hover (aka help) or command completion
|
||||
|
||||
# Installation
|
||||
|
||||
|
@ -50,3 +50,12 @@ require'nu'.setup{
|
|||
all_cmd_names = [[nu -c 'help commands | get name | str join "\n"']]
|
||||
}
|
||||
```
|
||||
|
||||
To enable hover (aka help) `vim.lsp.buf.hover` must be mapped. You can do so for example in your `ftplugin/nu.lua`
|
||||
```lua
|
||||
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = true })
|
||||
```
|
||||
|
||||
## Known issues (PR's welcome)
|
||||
|
||||
* Calling `vim.lsp.buf.hover` on a subcommand does not show the help for the subcommand
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require 'nu'._init() -- lazy initialise
|
||||
|
||||
vim.opt_local.commentstring = "#%s"
|
||||
vim.opt_local.keywordprg = ":ShowDocumentation"
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
local null_ls = require("null-ls")
|
||||
local null_ls_methods = require("null-ls.methods")
|
||||
local null_ls_helpers = require("null-ls.helpers")
|
||||
local log = require("nu.log")
|
||||
local vim = vim
|
||||
|
||||
|
@ -114,6 +116,38 @@ local nu_lsp = {
|
|||
},
|
||||
}
|
||||
|
||||
null_ls.register(nu_lsp)
|
||||
local nu_hover = null_ls_helpers.make_builtin {
|
||||
name = "nu_hover",
|
||||
factory = null_ls_helpers.generator_factory,
|
||||
generator_opts = {
|
||||
command = "nu",
|
||||
format = "raw",
|
||||
args = function(params)
|
||||
local cword = vim.fn.expand("<cword>")
|
||||
local nu_cmd =
|
||||
'if (help commands | where name == "' ..
|
||||
cword ..
|
||||
'" | length ) > 0 {help ' ..
|
||||
cword .. ' | str replace -a `\\u001B\\[[0-9;]*m` ``} else {man ' .. cword .. '}'
|
||||
log.trace("Executing", nu_cmd)
|
||||
return { "-c", nu_cmd }
|
||||
end,
|
||||
on_output = function(params, done)
|
||||
if params.err ~= nil then
|
||||
done({ params.err })
|
||||
else
|
||||
done({ params.output })
|
||||
end
|
||||
end
|
||||
},
|
||||
filetypes = { "nu" },
|
||||
method = null_ls_methods.internal.HOVER,
|
||||
meta = {
|
||||
url = "help",
|
||||
description = "nushell help output"
|
||||
}
|
||||
}
|
||||
|
||||
null_ls.register({ nu_hover, nu_lsp })
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,11 +1 @@
|
|||
function! s:ShowDocumentation(word)
|
||||
let nu_help = system('nu -c "help '. a:word .'"')
|
||||
if v:shell_error == 0
|
||||
echo nu_help
|
||||
else
|
||||
execute '!man '. a:word
|
||||
endif
|
||||
endfunction
|
||||
command! -nargs=1 ShowDocumentation :call s:ShowDocumentation(<f-args>)
|
||||
|
||||
lua require('nu.tree_sitter_config')
|
||||
|
|
Loading…
Reference in a new issue