@@ -1199,6 +1199,17 @@ local function insertDocEnum(state, pos, doc, enums)
11991199 return enums
12001200end
12011201
1202+ local function buildInsertDocFunction (doc )
1203+ local args = {}
1204+ for i , arg in ipairs (doc .args ) do
1205+ args [i ] = (' ${%d:%s}' ):format (i , arg .name [1 ])
1206+ end
1207+ return (" \z
1208+ function (%s)\
1209+ \t $0\
1210+ end" ):format (table.concat (args , ' , ' ))
1211+ end
1212+
12021213--- @param state parser.state
12031214--- @param pos integer
12041215--- @param src vm.node.object
@@ -1220,6 +1231,26 @@ local function insertEnum(state, pos, src, enums, isInArray)
12201231 description = src .comment ,
12211232 kind = define .CompletionItemKind .EnumMember ,
12221233 }
1234+ elseif src .type == ' doc.type.function' then
1235+ --- @cast src parser.object
1236+ local insertText = buildInsertDocFunction (src )
1237+ local description
1238+ if src .comment then
1239+ description = src .comment
1240+ else
1241+ local descText = insertText :gsub (' %$%{%d+:([^}]+)%}' , function (val )
1242+ return val
1243+ end ):gsub (' %$%{?%d+%}?' , ' ' )
1244+ description = markdown ()
1245+ : add (' lua' , descText )
1246+ : string ()
1247+ end
1248+ enums [# enums + 1 ] = {
1249+ label = vm .getInfer (src ):view (state .uri ),
1250+ description = description ,
1251+ kind = define .CompletionItemKind .Function ,
1252+ insertText = insertText ,
1253+ }
12231254 elseif isInArray and src .type == ' doc.type.array' then
12241255 for i , d in ipairs (vm .getDefs (src .node )) do
12251256 insertEnum (state , pos , d , enums , isInArray )
@@ -1433,17 +1464,6 @@ local function trySymbol(state, position, results)
14331464 end
14341465end
14351466
1436- local function buildInsertDocFunction (doc )
1437- local args = {}
1438- for i , arg in ipairs (doc .args ) do
1439- args [i ] = (' ${%d:%s}' ):format (i , arg .name [1 ])
1440- end
1441- return (" \z
1442- function (%s)\
1443- \t $0\
1444- end" ):format (table.concat (args , ' , ' ))
1445- end
1446-
14471467local function findCall (state , position )
14481468 local call
14491469 guide .eachSourceContain (state .ast , position , function (src )
@@ -1534,27 +1554,6 @@ local function tryCallArg(state, position, results)
15341554 local enums = {}
15351555 for src in node :eachObject () do
15361556 insertEnum (state , position , src , enums , arg and arg .type == ' table' )
1537- if src .type == ' doc.type.function' then
1538- --- @cast src parser.object
1539- local insertText = buildInsertDocFunction (src )
1540- local description
1541- if src .comment then
1542- description = src .comment
1543- else
1544- local descText = insertText :gsub (' %$%{%d+:([^}]+)%}' , function (val )
1545- return val
1546- end ):gsub (' %$%{?%d+%}?' , ' ' )
1547- description = markdown ()
1548- : add (' lua' , descText )
1549- : string ()
1550- end
1551- enums [# enums + 1 ] = {
1552- label = vm .getInfer (src ):view (state .uri ),
1553- description = description ,
1554- kind = define .CompletionItemKind .Function ,
1555- insertText = insertText ,
1556- }
1557- end
15581557 end
15591558 cleanEnums (enums , arg )
15601559 for _ , enum in ipairs (enums ) do
0 commit comments