clink-completions icon indicating copy to clipboard operation
clink-completions copied to clipboard

Better display of yarn run completions

Open jods4 opened this issue 7 years ago • 1 comments

Following #74, I tested formatted completions: /.bin executables are displayed plain, package.json scripts are prefixed with a *. yarn run 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

jods4 avatar Dec 19 '16 17:12 jods4

Looks nice ;) Though i personally prefer an option without space between * and a suggestion. @jods4, could you send a PR with this?

vladimir-kotikov avatar Dec 20 '16 06:12 vladimir-kotikov