mirror of
https://github.com/tiyn/action-hints.nvim.git
synced 2025-11-13 13:59:45 +01:00
Initial commit
This commit is contained in:
44
README.md
Normal file
44
README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Statusline Action Hints
|
||||
|
||||
A Neovim plugin to show statusline information about the word under the cursor.
|
||||
|
||||
Available statusline hints:
|
||||
* go-to-definition is available
|
||||
* reference list available
|
||||
* number of references
|
||||
|
||||
## Installation
|
||||
|
||||
### Lazy
|
||||
|
||||
``` lua
|
||||
{
|
||||
"roobert/statusline-action-hints.nvim",
|
||||
config = function()
|
||||
require("statusline-action-hints").setup()
|
||||
end,
|
||||
}
|
||||
```
|
||||
|
||||
### Packer
|
||||
|
||||
``` lua
|
||||
use({
|
||||
"roobert/statusline-action-hints.nvim",
|
||||
config = function()
|
||||
require("statusline-action-hints").setup()
|
||||
end,
|
||||
})
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
As a lualine statusline component:
|
||||
|
||||
``` lua
|
||||
require('lualine').setup {
|
||||
sections = {
|
||||
lualine_x = { require("statusline-action-hints").statusline }
|
||||
}
|
||||
}
|
||||
```
|
||||
86
lua/statusline-action-hints/init.lua
Normal file
86
lua/statusline-action-hints/init.lua
Normal file
@@ -0,0 +1,86 @@
|
||||
M = {}
|
||||
|
||||
M.references_available = false
|
||||
M.reference_count = 0
|
||||
M.definition_available = false
|
||||
|
||||
local function references()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
|
||||
local params = {
|
||||
textDocument = { uri = bufname },
|
||||
position = { line = cursor[1] - 1, character = cursor[2] },
|
||||
context = { includeDeclaration = true },
|
||||
}
|
||||
|
||||
vim.lsp.buf_request(bufnr, "textDocument/references", params, function(err, result, _, _)
|
||||
if err then
|
||||
error(tostring(err))
|
||||
end
|
||||
|
||||
if not result then
|
||||
M.references_available = false
|
||||
M.reference_count = 0
|
||||
return false
|
||||
end
|
||||
|
||||
if vim.tbl_count(result) > 0 then
|
||||
M.references_available = true
|
||||
M.reference_count = vim.tbl_count(result) - 1
|
||||
return true
|
||||
end
|
||||
|
||||
M.references_available = false
|
||||
M.reference_count = 0
|
||||
return false
|
||||
end)
|
||||
end
|
||||
|
||||
local function definition()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
|
||||
local params = {
|
||||
textDocument = { uri = bufname },
|
||||
position = { line = cursor[1] - 1, character = cursor[2] },
|
||||
}
|
||||
|
||||
vim.lsp.buf_request(bufnr, "textDocument/definition", params, function(err, result, _, _)
|
||||
if err then
|
||||
error(tostring(err))
|
||||
end
|
||||
|
||||
if not result then
|
||||
M.definition_available = false
|
||||
return false
|
||||
end
|
||||
|
||||
if vim.tbl_count(result) > 0 then
|
||||
M.definition_available = true
|
||||
return true
|
||||
end
|
||||
|
||||
M.definition_available = false
|
||||
return false
|
||||
end)
|
||||
end
|
||||
|
||||
M.statusline = function()
|
||||
references()
|
||||
definition()
|
||||
|
||||
local definition_status = ""
|
||||
|
||||
if M.definition_available then
|
||||
definition_status = "gd"
|
||||
end
|
||||
|
||||
return string.format("%s refs:%s", definition_status, M.reference_count)
|
||||
end
|
||||
|
||||
M.setup = function() end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user