Initial commit

This commit is contained in:
Rob Wilson
2023-02-07 23:14:34 +00:00
commit 9becf19959
2 changed files with 130 additions and 0 deletions

44
README.md Normal file
View 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 }
}
}
```

View 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