Skip to content
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

Open
madskjeldgaard opened this issue Mar 16, 2020 · 11 comments
Open

[FR] Add solution to be able to search through documentation #59

madskjeldgaard opened this issue Mar 16, 2020 · 11 comments
Labels
enhancement New feature or request feature request
Milestone

Comments

@madskjeldgaard
Copy link
Contributor

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.

@madskjeldgaard madskjeldgaard added the bug Something isn't working label Mar 16, 2020
@davidgranstrom davidgranstrom added enhancement New feature or request and removed bug Something isn't working labels Mar 16, 2020
@davidgranstrom
Copy link
Owner

@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 fzf. (That applies for the current implementation as well..). I'm hoping to look into this once #58 is completed!

@madskjeldgaard
Copy link
Contributor Author

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 :)

@salkin-mada
Copy link
Contributor

fzf integration sounds very promising i would say

@madskjeldgaard
Copy link
Contributor Author

Using fzf for this would still be awesome.
Maybe something like running SCDoc.renderAll in SC first, and then (from within vim in a fzf buffer and using the scnvim help browser instead of w3m):

cd /home/$USER/.local/share/SuperCollider/Help && w3m $(fd .html | fzf)

@davidgranstrom
Copy link
Owner

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.

@madskjeldgaard
Copy link
Contributor Author

I messed around with this a bit today. For those on Linux with fzf vim installed, you can run this command:

:call fzf#run(fzf#wrap({'source':'fd .txt ~/.local/share/SuperCollider/Help -t f'}))

fzf schelp

@madskjeldgaard
Copy link
Contributor Author

The above only works for classes though, FYI

@madskjeldgaard
Copy link
Contributor Author

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 scnvim_fuzzy_command.

It requires nvim 0.5 to run.

Load this using the lua command like so: lua require('scnvim_fuzzy.lua').init() to register the commands :SCNvimFuzzyHelp and :SCNvimFuzzyDefinitions.

This can be done in your init.vim automatically:

autocmd filetype supercollider,scnvim,scdoc,supercollider.help lua require'scnvim_fuzzy'.init()

scnvim_fuzzy.lua:

--
-- 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

@madskjeldgaard
Copy link
Contributor Author

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!

@vitreo12
Copy link

Thanks for this snippet, @madskjeldgaard ! It's super useful, similar to ScIDE's Ctrl + I.

One quick thing,given the scnvim_fuzzy.lua file name, the two lines:

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

@madskjeldgaard
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature request
Projects
None yet
Development

No branches or pull requests

4 participants