From 839ba68e3adbc0c95ea308b8d6e130944a5bbf07 Mon Sep 17 00:00:00 2001 From: goncharov_oi Date: Thu, 19 Oct 2017 17:05:53 +0300 Subject: [PATCH] Add context completion for Operations in Services. --- complete.lua | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/complete.lua b/complete.lua index 759051f..2cf8bb9 100644 --- a/complete.lua +++ b/complete.lua @@ -77,7 +77,27 @@ function completion(word, line, startpos, endpos) 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 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 + + local function service_add_ops(serv) + local res = {} + local mt = getmetatable(serv) + + for name,_ in pairs(mt) do res[#res+1] = name end + for _,op in ipairs(serv:getOperationNames()) do res[#res+1] = op end + + for _,op in ipairs(utils.table_unique(res)) do + local typ, ar = nil + if serv:hasOperation(op) then _,typ,ar = serv:getOperationInfo(op) end if not ar or ar ~= 0 then -- unknown lua function or multiple arguments: add(op..'(') @@ -148,8 +168,9 @@ function completion(word, line, startpos, endpos) end elseif sep == ':' then if t == 'TaskContext' then taskcontext_add_ops(v) + elseif t == 'Service' then service_add_ops(v) elseif t == 'InputPort' or t=='OutputPort' or t=='Variable' or - t=='EEHook' or t=='Operation' or t=='SendHandle' or t=='Service' or + t=='EEHook' or t=='Operation' or t=='SendHandle' or t=='ServiceRequester' then callable_rtt_obj_add_ops(v) else