Skip to content

Commit b04dee9

Browse files
committed
setting runtime.special supports fields
#1484
1 parent bb192b1 commit b04dee9

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

changelog.md

+9
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
105105
```
106106
* `CHG` find reference: respect `includeDeclaration` (although I don't know how to turn off this option in VSCode)
107107
* `CHG` [#1344] improve `---@see`
108+
* `CHG` [#1484] setting `runtime.special` supports fields
109+
```jsonc
110+
{
111+
"runtime.special": {
112+
"sandbox.require": "require"
113+
}
114+
}
115+
```
108116
* `FIX` [#1567]
109117
* `FIX` [#1593]
110118
* `FIX` [#1595]
@@ -122,6 +130,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
122130
[#1332]: https://github.com./sumneko/lua-language-server/issues/1332
123131
[#1344]: https://github.com./sumneko/lua-language-server/issues/1344
124132
[#1458]: https://github.com./sumneko/lua-language-server/issues/1458
133+
[#1484]: https://github.com./sumneko/lua-language-server/issues/1484
125134
[#1557]: https://github.com./sumneko/lua-language-server/issues/1557
126135
[#1558]: https://github.com./sumneko/lua-language-server/issues/1558
127136
[#1561]: https://github.com./sumneko/lua-language-server/issues/1561

script/files.lua

+10
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,16 @@ function m.getOriginText(uri)
392392
return file.originText
393393
end
394394

395+
---@param uri uri
396+
---@param text string
397+
function m.setOriginText(uri, text)
398+
local file = m.fileMap[uri]
399+
if not file then
400+
return
401+
end
402+
file.originText = text
403+
end
404+
395405
--- 获取文件原始行表
396406
---@param uri uri
397407
---@return integer[]

script/parser/compile.lua

+28-9
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,23 @@ local function checkAmbiguityCall(call, parenPos)
17211721
}
17221722
end
17231723

1724+
local function bindSpecial(source, name)
1725+
if Specials[name] then
1726+
addSpecial(name, source)
1727+
else
1728+
local ospeicals = State.options.special
1729+
if ospeicals and ospeicals[name] then
1730+
addSpecial(ospeicals[name], source)
1731+
end
1732+
end
1733+
end
1734+
17241735
local function parseSimple(node, funcName)
1736+
local currentName
1737+
if node.type == 'getglobal'
1738+
or node.type == 'getlocal' then
1739+
currentName = node[1]
1740+
end
17251741
local lastMethod
17261742
while true do
17271743
if lastMethod and node.node == lastMethod then
@@ -1752,6 +1768,16 @@ local function parseSimple(node, funcName)
17521768
if field then
17531769
field.parent = getfield
17541770
field.type = 'field'
1771+
if currentName then
1772+
if node.type == 'getlocal'
1773+
or node.type == 'getglobal'
1774+
or node.type == 'getfield' then
1775+
currentName = currentName .. '.' .. field[1]
1776+
bindSpecial(getfield, currentName)
1777+
else
1778+
currentName = nil
1779+
end
1780+
end
17551781
else
17561782
pushError {
17571783
type = 'MISS_FIELD',
@@ -2019,7 +2045,7 @@ local function resolveName(node)
20192045
if not node then
20202046
return nil
20212047
end
2022-
local loc = getLocal(node[1], node.start)
2048+
local loc = getLocal(node[1], node.start)
20232049
if loc then
20242050
node.type = 'getlocal'
20252051
node.node = loc
@@ -2042,14 +2068,7 @@ local function resolveName(node)
20422068
end
20432069
end
20442070
local name = node[1]
2045-
if Specials[name] then
2046-
addSpecial(name, node)
2047-
else
2048-
local ospeicals = State.options.special
2049-
if ospeicals and ospeicals[name] then
2050-
addSpecial(ospeicals[name], node)
2051-
end
2052-
end
2071+
bindSpecial(node, name)
20532072
return node
20542073
end
20552074

test/type_inference/init.lua

+15
Original file line numberDiff line numberDiff line change
@@ -3876,3 +3876,18 @@ local t = {
38763876
f = function (<?x?>) end
38773877
}
38783878
]]
3879+
3880+
config.set(nil, 'Lua.runtime.special', {
3881+
['xx.assert'] = 'assert'
3882+
})
3883+
3884+
TEST 'number' [[
3885+
---@type number?
3886+
local t
3887+
3888+
xx.assert(t)
3889+
3890+
print(<?t?>)
3891+
]]
3892+
3893+
config.set(nil, 'Lua.runtime.special', nil)

0 commit comments

Comments
 (0)