-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FR] Add solution to be able to search through documentation #59
Comments
@madskjeldgaard Yes, I agree. It would also be nice to let the end user decide on how to present the search results. For instance, piping the results to a utility such as |
That's a great idea. Maybe most of the work has already done in using fzf for example, unless you want to stay dependency-less :) |
fzf integration sounds very promising i would say |
Using fzf for this would still be awesome.
|
I did some work towards better introspection for sclang classes here: 5159f7e although its not complete, I think something like this would be of great help to build different tools such as fuzzy finding for sclang classes/methods. It would not be necessary to generate all docs, since they could be rendered on the fly when accessing the associated help file. |
The above only works for classes though, FYI |
I have now made a solution for fuzzy finding of definitions and classes. The former opens the definition in a buffer and the latter in a scnvim help window. Works with both skim and fzf, which ma be set in the global varialble It requires nvim 0.5 to run. Load this using the lua command like so: This can be done in your init.vim automatically: autocmd filetype supercollider,scnvim,scdoc,supercollider.help lua require'scnvim_fuzzy'.init()
--
-- Extra functions for SuperCollider / scnvim
-- by Mads Kjeldgaard , 2020
-- for Nvim => v0.5
local M = {}
-- Init function
-- Run this to register commands that interface with the functions here
function M.init()
-- Use fuzzy finding (fzf / skim) to search for help and find definitions
vim.cmd("command! SCNvimFuzzyHelp lua require('scnvim_extra').scnvim_fuzzy_help()")
vim.cmd("command! SCNvimFuzzyDefinitions lua require('scnvim_extra').scnvim_fuzzy_definition()")
-- Set command to use: fzf or skim
vim.g.scnvim_fuzzy_command = vim.g.scnvim_fuzzy_command or "skim"
end
local function fzf(sources, sinkfunc, custom_options)
local cmd = vim.g.scnvim_fuzzy_command;
local fzf_run = vim.fn[cmd .. "#run"]
local fzf_wrap = vim.fn[cmd .. "#wrap"]
local wrapped = fzf_wrap("test", {
source = sources,
options = custom_options or {},
-- don't set `sink` or `sink*` here
})
wrapped["sink*"] = nil -- this line is required if you want to use `sink` only
wrapped.sink = sinkfunc
fzf_run(wrapped)
end
-- Unpack csv file with tags into lua table
local function scnvim_help_table()
local root = vim.g.scnvim_root_dir
local classes = root .. "/scnvim-data/tags"
local tagsfile = io.open(classes)
local help = {}
for line in tagsfile:lines() do
local tagname, tagpath, _, _= line:match("%s*(.-)\t%s*(.-)\t%s*(.-)\t%s*(.-)")
help[tostring(tagname)] = tagpath
-- print(tagname)
end
return help
end
function M.scnvim_fuzzy_definition()
local help = scnvim_help_table()
local help_keys = {};
for k,_ in pairs(help) do
table.insert(help_keys, k)
end
fzf(help_keys, function(class_name)
local key = tostring(class_name)
local lookup_path = help[key]
vim.cmd("spl " .. lookup_path)
end)
end
M.open_help = vim.fn["scnvim#help#open_help_for"]
function M.scnvim_fuzzy_help()
local help = scnvim_help_table()
local help_keys = {};
for k,_ in pairs(help) do
table.insert(help_keys, tostring(k))
end
fzf(help_keys, function(class_name)
M.open_help(tostring(class_name))
end)
end
return M
|
The above has a small (weird) bug: it posts a warning about broken links in help files whenever you trigger it, but apart from that it works fine. @davidgranstrom the above could either go in the wiki or a PR or stay here. It's up to you! |
Thanks for this snippet, @madskjeldgaard ! It's super useful, similar to ScIDE's Ctrl + I. One quick thing,given the vim.cmd("command! SCNvimFuzzyHelp lua require('scnvim_extra').scnvim_fuzzy_help()")
vim.cmd("command! SCNvimFuzzyDefinitions lua require('scnvim_extra').scnvim_fuzzy_definition()") should be vim.cmd("command! SCNvimFuzzyHelp lua require('scnvim_fuzzy').scnvim_fuzzy_help()")
vim.cmd("command! SCNvimFuzzyDefinitions lua require('scnvim_fuzzy').scnvim_fuzzy_definition()") for it to work |
I've solved this for myself for the time being by adding commands that call the QT help doc browser (ala scvim classic) to allow searching through non class documentation. I've added them here if anyone's interested: https://github.com/madskjeldgaard/supercollider-h4x-nvim |
A feature request:
Add solution to be able to search through documentation. This is especially useful when searching for help files that are not for classes but things like references, guides or tutorials. An example could be the help file "nodeproxy roles".
As of now, I don't think there's a way to do this but I could be wrong.
The text was updated successfully, but these errors were encountered: