From a7f8ea05eae4bc555b156525641bcf5689e95404 Mon Sep 17 00:00:00 2001 From: Peter Soetens Date: Fri, 9 Nov 2012 23:22:32 +0100 Subject: [PATCH 2/2] complete: slightly more intelligent If the operation is known and is a zero-arity, when can already close the parentheses. Signed-off-by: Peter Soetens --- complete.lua | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/complete.lua b/complete.lua index 2ab25f0..759051f 100644 --- a/complete.lua +++ b/complete.lua @@ -75,7 +75,17 @@ function completion(word, line, startpos, endpos) for name,_ in pairs(mt) do res[#res+1] = name end for _,op in ipairs(tc:getOps()) do res[#res+1] = op end - for _,op in ipairs(utils.table_unique(res)) do add(op .. '(') end + for _,op in ipairs(utils.table_unique(res)) do + local typ, ar = nil + if tc:hasOperation(op) then typ,ar = tc:getOpInfo(op) end + if not ar or ar ~= 0 then + -- unknown lua function or multiple arguments: + add(op..'(') + else + -- known that this op takes no arguments: + add(op..'()') + end + end end -- This function makes a guess of the next character following an identifier, @@ -131,7 +141,7 @@ function completion(word, line, startpos, endpos) utils.table_has(parts, "size") and utils.table_has(parts, "capacity") then return else - for k,v in pairs(parts) do add(v) end + for k,v2 in pairs(parts) do add(v2) end end else return -- 1.7.5.4