diff options
-rw-r--r-- | changelog.md | 9 | ||||
-rw-r--r-- | script/files.lua | 10 | ||||
-rw-r--r-- | script/parser/compile.lua | 37 | ||||
-rw-r--r-- | test/type_inference/init.lua | 15 |
4 files changed, 62 insertions, 9 deletions
diff --git a/changelog.md b/changelog.md index 73604c78..f6546af8 100644 --- a/changelog.md +++ b/changelog.md @@ -105,6 +105,14 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`. ``` * `CHG` find reference: respect `includeDeclaration` (although I don't know how to turn off this option in VSCode) * `CHG` [#1344] improve `---@see` +* `CHG` [#1484] setting `runtime.special` supports fields + ```jsonc + { + "runtime.special": { + "sandbox.require": "require" + } + } + ``` * `FIX` [#1567] * `FIX` [#1593] * `FIX` [#1595] @@ -122,6 +130,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`. [#1332]: https://github.com/sumneko/lua-language-server/issues/1332 [#1344]: https://github.com/sumneko/lua-language-server/issues/1344 [#1458]: https://github.com/sumneko/lua-language-server/issues/1458 +[#1484]: https://github.com/sumneko/lua-language-server/issues/1484 [#1557]: https://github.com/sumneko/lua-language-server/issues/1557 [#1558]: https://github.com/sumneko/lua-language-server/issues/1558 [#1561]: https://github.com/sumneko/lua-language-server/issues/1561 diff --git a/script/files.lua b/script/files.lua index 353030a4..c0bcbb20 100644 --- a/script/files.lua +++ b/script/files.lua @@ -392,6 +392,16 @@ function m.getOriginText(uri) return file.originText end +---@param uri uri +---@param text string +function m.setOriginText(uri, text) + local file = m.fileMap[uri] + if not file then + return + end + file.originText = text +end + --- 获取文件原始行表 ---@param uri uri ---@return integer[] diff --git a/script/parser/compile.lua b/script/parser/compile.lua index 5575664c..8b8a7770 100644 --- a/script/parser/compile.lua +++ b/script/parser/compile.lua @@ -1721,7 +1721,23 @@ local function checkAmbiguityCall(call, parenPos) } end +local function bindSpecial(source, name) + if Specials[name] then + addSpecial(name, source) + else + local ospeicals = State.options.special + if ospeicals and ospeicals[name] then + addSpecial(ospeicals[name], source) + end + end +end + local function parseSimple(node, funcName) + local currentName + if node.type == 'getglobal' + or node.type == 'getlocal' then + currentName = node[1] + end local lastMethod while true do if lastMethod and node.node == lastMethod then @@ -1752,6 +1768,16 @@ local function parseSimple(node, funcName) if field then field.parent = getfield field.type = 'field' + if currentName then + if node.type == 'getlocal' + or node.type == 'getglobal' + or node.type == 'getfield' then + currentName = currentName .. '.' .. field[1] + bindSpecial(getfield, currentName) + else + currentName = nil + end + end else pushError { type = 'MISS_FIELD', @@ -2019,7 +2045,7 @@ local function resolveName(node) if not node then return nil end - local loc = getLocal(node[1], node.start) + local loc = getLocal(node[1], node.start) if loc then node.type = 'getlocal' node.node = loc @@ -2042,14 +2068,7 @@ local function resolveName(node) end end local name = node[1] - if Specials[name] then - addSpecial(name, node) - else - local ospeicals = State.options.special - if ospeicals and ospeicals[name] then - addSpecial(ospeicals[name], node) - end - end + bindSpecial(node, name) return node end diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 0419ed9b..7f8e8e4f 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3876,3 +3876,18 @@ local t = { f = function (<?x?>) end } ]] + +config.set(nil, 'Lua.runtime.special', { + ['xx.assert'] = 'assert' +}) + +TEST 'number' [[ +---@type number? +local t + +xx.assert(t) + +print(<?t?>) +]] + +config.set(nil, 'Lua.runtime.special', nil) |