diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-05 01:30:20 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-05 01:30:20 +0800 |
commit | b04ad0cbe77602f739cb35d7ba838a1f62d298dd (patch) | |
tree | 510d7222f64acb66bc133b94e72ae18a9d944fea | |
parent | 1938e690dae0aa2028f8fce6564486f02dd73c5f (diff) | |
download | lua-language-server-b04ad0cbe77602f739cb35d7ba838a1f62d298dd.zip |
update
-rw-r--r-- | script/vm/compiler.lua | 30 | ||||
-rw-r--r-- | test/hover/init.lua | 23 |
2 files changed, 37 insertions, 16 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 6f542367..1473b985 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -7,6 +7,8 @@ local signMgr = require 'vm.sign' local config = require 'config' local union = require 'vm.union' local genericMgr = require 'vm.generic' +local rpath = require 'workspace.require-path' +local files = require 'files' ---@class parser.object ---@field _compiledNodes boolean @@ -275,6 +277,26 @@ local function getReturn(func, index, args) end return getReturn(args[1], index - 1, newArgs) end + if func.special == 'require' then + local nameArg = args[1] + if not nameArg or nameArg.type ~= 'string' then + return nil + end + local name = nameArg[1] + if not name or type(name) ~= 'string' then + return nil + end + local uri = rpath.findUrisByRequirePath(guide.getUri(func), name)[1] + if not uri then + return nil + end + local state = files.getState(uri) + local ast = state and state.ast + if not ast then + return nil + end + return m.compileNode(ast) + end local node = m.compileNode(func) ---@type vm.node.union local result, hasCalled @@ -674,6 +696,14 @@ local compilerSwitch = util.switch() end end end) + : case 'main' + : call(function (source) + if source.returns then + for _, rtn in ipairs(source.returns) do + nodeMgr.setNode(source, m.compileNode(rtn[1])) + end + end + end) : case 'select' : call(function (source) local vararg = source.vararg diff --git a/test/hover/init.lua b/test/hover/init.lua index 258654d1..8ffb89fd 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -626,7 +626,7 @@ end local <?r?> = a(1) ]] [[ -local r: string +local r: string = "a" ]] TEST[[ @@ -636,7 +636,7 @@ end local _, <?r?> = pcall(a, 1) ]] [[ -local r: string +local r: string = "a" ]] TEST[[ @@ -646,15 +646,6 @@ local <?n?> = rawlen() local n: integer ]] --- TODO 暂未实现 ---TEST[[ ---local <?n?> = pairs() ---]] ---[[ ---function n<next>(table: table [, index: any]) --- -> key: any, value: any ---]] - TEST[[ local <?x?> = '\a' ]] @@ -698,8 +689,8 @@ end ]] [[ function f() - -> any - 2. any + -> nil + 2. nil ]] TEST [[ @@ -709,7 +700,7 @@ end local <?x?> = f() ]] [[ -local x: any +local x: nil ]] TEST [[ @@ -720,7 +711,7 @@ end ]] [[ function f() - -> integer + -> integer|nil ]] TEST [[ @@ -790,7 +781,7 @@ io.<?popen?>() [[ function io.popen(prog: string, mode?: "r"|"w") -> file*? - 2. errmsg?: string + 2. errmsg: string? ]] TEST [[ |