Skip to content

Commit

Permalink
Cloud Foundry completion improvements.
Browse files Browse the repository at this point in the history
- Clean luacheck warnings.
- Directory names in completions are marked as directory completions so
  that a space isn't appended after them (and as a side effect match
  coloring is applied as well).
  • Loading branch information
chrisant996 committed Jul 4, 2024
1 parent f334fba commit 123baec
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions completions/cf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

local fullname = ...

local function get_completions(matchtype, word, word_index, line_state, match_builder, user_data)
local function get_completions(matchtype, word, word_index, line_state, match_builder, user_data) -- luacheck: no unused
-- Collect the command arguments.
local args = ""
for i = 1, line_state:getwordcount() do
Expand All @@ -13,12 +13,12 @@ local function get_completions(matchtype, word, word_index, line_state, match_bu
-- Skip first non-redir word; it's the program name.
args = " "
else
local word = line_state:getword(i)
if word:sub(-1) == "\\" then
local w = line_state:getword(i)
if w:sub(-1) == "\\" then
-- Compensate for \" command line parsing.
word = word.."\\"
w = w.."\\"
end
args = args..' "'..word..'"'
args = args..' "'..w..'"'
end
end
end
Expand All @@ -29,13 +29,18 @@ local function get_completions(matchtype, word, word_index, line_state, match_bu
if f then
-- Add completions to the match builder.
for line in f:lines() do
local match = line
local word, desc = line:match("^([^ ]+) +# (.*)$")
if word and desc then
local mt = matchtype
local w, d = line:match("^([^ ]+) +# (.*)$")
w = w or line
if w:sub(-1) == "\\" then
mt = "dir"
end
if w and d then
-- Include the description when available.
match = { match=word, description=desc }
match_builder:addmatch({ match=w, description=d }, mt)
else
match_builder:addmatch(w, mt)
end
match_builder:addmatch(match, matchtype)
end
f:close()
end
Expand Down

0 comments on commit 123baec

Please sign in to comment.