Skip to content

Conversation

hc-nolan
Copy link
Contributor

@hc-nolan hc-nolan commented May 11, 2025

Originally discussed in #8.

Expanded the pattern matching expression so it is more precise: "^" .. source .. "~%d+(%.%d+)?$" - so "python" will match directories python, python~3, or python~3.13.


Added partial string matching for restrict_sources. Previously, the exact directory name had to be entered, e.g. python~3.13 rather than just python. With the new approach, if restrict_sources contains a value python, any directories starting with python will be considered valid. The motivation for this is demonstrated in the README example - we can now automatically restrict the sources for the language of the current file, and we won't have issues if the language docs have the version in their name:

keys = {
  {
    "<leader>aps",
	function()
	  local lang = vim.bo.filetype
	  require("apidocs").apidocs_search({ restrict_sources = { lang } })
	end,
	desc = "Apidocs: Search, restricted to current file language"			
  },
},

hc-nolan added 2 commits May 11, 2025 13:51
Modified all usages of restrict_sources to consider partial matches.
E.g., previously, `restrict_sources={"python"}` would fail to find
`python~3.13`, whereas now that will be considered a match.

Also added an example remap to the README that shows how this can be
used to search the docs for the current file's language automatically.
hc-nolan added 3 commits May 11, 2025 15:22
Note: does not currently function with `telescope.apidocs_open`, only
`telescope.apidocs_search`.
@hc-nolan
Copy link
Contributor Author

Incorporated your feedback

One thing to note is that I haven't been successful in getting this to work with Telescope's apidocs_open(), and I'm really not sure what the best way would be to go about making it work for that function.

@hc-nolan hc-nolan force-pushed the partial-matching branch from 2d32d79 to 7fc1c9d Compare May 11, 2025 21:00
@emmanueltouzery
Copy link
Owner

for telescope apidocs_open, the modifications in line 40 of lua/apidocs.lua ought to do it. "candidates" is what's fed into the telescope picker?

@hc-nolan
Copy link
Contributor Author

for telescope apidocs_open, the modifications in line 40 of lua/apidocs.lua ought to do it. "candidates" is what's fed into the telescope picker?

Oh yeah, you're right. I must have switched branches when I looked at Telescope because I remember it not working, but it is indeed working properly in partial-matching branch.

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

Successfully merging this pull request may close these issues.

2 participants