clink-completions
clink-completions copied to clipboard
Better display of yarn run completions
Following #74, I tested formatted completions: /.bin
executables are displayed plain, package.json
scripts are prefixed with a *
.
The result is better than nothing, although color would be 10x better 😭
To achieve this, I modified the scripts
function as follows:
local function scripts_display_filter(scripts)
return function(matches)
for i, m in ipairs(matches) do
local prefix = scripts[m] ~= nil and '* ' or ' '
matches[i] = prefix..m
end
return matches
end
end
-- Reads package.json in current directory and extracts all "script" commands defined
local function scripts(token)
-- Read package.json first
local package_json = io.open('package.json')
-- If there is no such file, then close handle and return
if package_json == nil then return {} end
-- Read the whole file contents
local package_contents = package_json:read("*a")
package_json:close()
local scripts = w(JSON:decode(package_contents).scripts)
clink.match_display_filter = scripts_display_filter(scripts)
return scripts:keys()
end
Looks nice ;) Though i personally prefer an option without space between *
and a suggestion. @jods4, could you send a PR with this?