Skip to content

Commit 4739602

Browse files
Improve friendly-snippets detection
The current friendly-snippets detection only works if the rtp has an explicit entry for the friendly-snippets path. The runtimepaths can also be declared using globs such as "/home/user.local/share/nvim/site/pack/*/start/*", in which case, this detection doesn't work to find the friendly snippets path.
1 parent 5c978b3 commit 4739602

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lua/snippets/utils/init.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,14 @@ end
324324

325325
function utils.load_friendly_snippets()
326326
local search_paths = Snippets.config.get_option("search_paths", {})
327-
for _, path in ipairs(vim.api.nvim_list_runtime_paths()) do
328-
if string.match(path, "friendly.snippets") then
329-
table.insert(search_paths, path)
327+
local friendly_path = "friendly.snippets/snippets"
328+
-- Get all snippet files in the rtp
329+
for _, path in ipairs(vim.api.nvim_get_runtime_file("snippets/*.json", true)) do
330+
-- Check if it is a friendly-snippets path
331+
local pos = string.find(path, friendly_path)
332+
if pos then
333+
table.insert(search_paths, string.sub(path, 1, pos + #friendly_path - 1))
334+
break
330335
end
331336
end
332337
Snippets.config.set_option("search_paths", search_paths)

0 commit comments

Comments
 (0)