epwalsh / epwalsh/obsidian.nvim
Note contents preview on link hover
- Dominant language
- Lua
- Stars
- 6.2k
- Forks
- 250
- PR merge metrics
- No merged PRs in 30d
Description
### 🚀 The feature, motivation and pitch
Add a command to get a Telescope preview of the first n lines of the file under the cursor.
### Alternatives
_No response_
### Additional context
I'm doing some source-diving now, but I would imagine obsidian.vim's `gf` / FollowLink internals could be leveraged to take the proper file path and pass it to Telescope to display a preview of the file.
This is a snippet of some GPT hogwash that _almost works_ much of the time, but I don't yet understand the internals of Telescope, obsidian.vim or Lua to open up a proper PR:
```Lua
local client = obsidian.get_client()
client:resolve_link_async(nil, function(result)
if result then
if result.path then
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local conf = require("telescope.config").values
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
pickers.new({}, {
prompt_title = "Preview: " .. result.name,
finder = finders.new_oneshot_job({"cat", tostring(result.path)}, {}),
sorter = conf.generic_sorter({}),
previewer = conf.file_previewer({}),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
vim.cmd("edit " .. tostring(result.path))
end)
return true
end,
}):find()
end
end
```
Contributor guide
Assessment
This issue has not been assessed yet.