diff options
-rw-r--r-- | script-beta/core/document-symbol.lua | 15 | ||||
-rw-r--r-- | test-beta/document_symbol/init.lua | 19 |
2 files changed, 30 insertions, 4 deletions
diff --git a/script-beta/core/document-symbol.lua b/script-beta/core/document-symbol.lua index 8c606723..d7eb59ea 100644 --- a/script-beta/core/document-symbol.lua +++ b/script-beta/core/document-symbol.lua @@ -176,14 +176,23 @@ local function buildSet(source, text, used, symbols) end end -local function buildAnonymousFunction(source, used, symbols) +local function buildAnonymousFunction(source, text, used, symbols) if used[source] then return end used[source] = true + local head = '' + local parent = source.parent + if parent.type == 'return' then + head = 'return ' + elseif parent.type == 'callargs' then + local call = parent.parent + local node = call.node + head = buildName(node, text) .. ' -> ' + end symbols[#symbols+1] = { name = '', - detail = 'function ()', + detail = ('%sfunction (%s)'):format(head, buildFunctionParams(source)), kind = define.SymbolKind.Function, range = { source.start, source.finish }, selectionRange = { source.start, source.start }, @@ -202,7 +211,7 @@ local function buildSource(source, text, used, symbols) buildSet(source, text, used, symbols) elseif source.type == 'function' then await.delay() - buildAnonymousFunction(source, used, symbols) + buildAnonymousFunction(source, text, used, symbols) end end diff --git a/test-beta/document_symbol/init.lua b/test-beta/document_symbol/init.lua index 26928145..d9f1bec3 100644 --- a/test-beta/document_symbol/init.lua +++ b/test-beta/document_symbol/init.lua @@ -105,7 +105,7 @@ end { [1] = { name = '', - detail = 'function ()', + detail = 'return function ()', kind = define.SymbolKind.Function, range = {8, 22}, selectionRange = {8, 8}, @@ -611,3 +611,20 @@ local a = f { } } } + +TEST [[ +table.sort(t, function (a, b) + return false +end) +]] +{ + [1] = { + name = '', + detail = 'table.sort -> function (a, b)', + kind = define.SymbolKind.Function, + range = {15, 50}, + selectionRange = {15, 15}, + valueRange = {15, 50}, + children = EXISTS, + } +} |