diff options
| author | fdschmidt93 <39233597+fdschmidt93@users.noreply.github.com> | 2022-04-22 23:40:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-22 23:40:39 +0200 |
| commit | 8b02088743c07c2f82aec2772fbd2b3774195448 (patch) | |
| tree | e06cdbbec119f3de0ddc028d2b2c2a73d500f167 /lua/telescope/actions/utils.lua | |
| parent | d743d70292956f55f4a71f291281287d206f29f2 (diff) | |
fix(which_key): get full path & handle table assignment of funcrefs (#1875)
Diffstat (limited to 'lua/telescope/actions/utils.lua')
| -rw-r--r-- | lua/telescope/actions/utils.lua | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lua/telescope/actions/utils.lua b/lua/telescope/actions/utils.lua index 202ee73..9684414 100644 --- a/lua/telescope/actions/utils.lua +++ b/lua/telescope/actions/utils.lua @@ -108,7 +108,13 @@ function utils._get_anon_function_name(func_ref) local Path = require "plenary.path" local info = debug.getinfo(func_ref) local fname - for i, line in ipairs(Path:new(info.short_src):readlines()) do + -- if fn defined in string (ie loadstring) source is string + -- if fn defined in file, source is file name prefixed with a `@ยด + local path = Path:new((info.source:gsub("@", ""))) + if not path:exists() then + return "<anonymous>" + end + for i, line in ipairs(path:readlines()) do if i == info.linedefined then fname = line break @@ -119,11 +125,15 @@ function utils._get_anon_function_name(func_ref) if (fname:match "=" == nil) and (fname:match "function %S+%(" == nil) then return "<anonymous>" else - -- (1) remove function - -- (2) whitespace and equal - -- (3) anything in parenthesis incl. parentheses themselves - -- (4) remove TABLE. prefix if available - local patterns = { { "function", "" }, { "local", "" }, { "[%s=]", "" }, { "%((.+)%)", "" }, { "(.+)%.", "" } } + local patterns = { + { "function", "" }, -- remove function + { "local", "" }, -- remove local + { "[%s=]", "" }, -- remove whitespace and = + { [=[%[["']]=], "" }, -- remove left-hand bracket of table assignment + { [=[["']%]]=], "" }, -- remove right-ahnd bracket of table assignment + { "%((.+)%)", "" }, -- remove function arguments + { "(.+)%.", "" }, -- remove TABLE. prefix if available + } for _, tbl in ipairs(patterns) do fname = (fname:gsub(tbl[1], tbl[2])) -- make sure only string is returned end |
