From bb22719db1a29096a58fb7ea1a1db00a5ccfce2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 16 Nov 2021 15:51:00 +0800 Subject: `Lua.IntelliSense.traceReturn` --- script/config/config.lua | 1 + script/core/noder.lua | 4 +++- script/core/searcher.lua | 17 +++++++++++++++++ test/references/all.lua | 5 ++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/script/config/config.lua b/script/config/config.lua index 07b8b77c..c118e6f2 100644 --- a/script/config/config.lua +++ b/script/config/config.lua @@ -203,6 +203,7 @@ local Template = { ['Lua.window.statusBar'] = Type.Boolean >> true, ['Lua.window.progressBar'] = Type.Boolean >> true, ['Lua.IntelliSense.localSet'] = Type.Boolean >> false, + ['Lua.IntelliSense.traceReturn'] = Type.Boolean >> false, ['Lua.telemetry.enable'] = Type.Or(Type.Boolean >> false, Type.Nil), ['files.associations'] = Type.Hash(Type.String, Type.String), ['files.exclude'] = Type.Hash(Type.String, Type.Boolean), diff --git a/script/core/noder.lua b/script/core/noder.lua index 999b797e..81a5b8b1 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -1280,7 +1280,9 @@ compileNodeMap = util.switch() , index ) pushForward(noders, returnID, getID(rtnObj)) - pushBackward(noders, getID(rtnObj), returnID, INFO_DEEP_AND_DONT_CROSS) + if config.get 'Lua.IntelliSense.traceReturn' then + pushBackward(noders, getID(rtnObj), returnID, INFO_DEEP_AND_DONT_CROSS) + end end end end diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 3c210b1b..f2b9b291 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -17,6 +17,7 @@ local next = next local error = error local type = type local setmetatable = setmetatable +local ipairs = ipairs local tconcat = table.concat local ssub = string.sub local sfind = string.find @@ -975,6 +976,22 @@ local function prepareSearch(source) end local uri = getUri(source) local id = getID(source) + -- return function + if source.type == 'function' and source.parent.type == 'return' then + local func = guide.getParentFunction(source) + if func.type == 'function' then + for index, rtn in ipairs(source.parent) do + if rtn == source then + id = sformat('%s%s%s' + , getID(func) + , RETURN_INDEX + , index + ) + break + end + end + end + end return uri, id end diff --git a/test/references/all.lua b/test/references/all.lua index 5229c54b..cbe8ebb5 100644 --- a/test/references/all.lua +++ b/test/references/all.lua @@ -1,3 +1,5 @@ +local config = require 'config' + TEST [[ ---@class A local a = {} @@ -76,6 +78,7 @@ end local _, = f() ]] +config.set('Lua.IntelliSense.traceReturn', true) TEST [[ local local function f() @@ -93,7 +96,7 @@ local function f() end local = f()() ]] - +config.set('Lua.IntelliSense.traceReturn', false) TEST [[ ---@class A -- cgit v1.2.3