summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.lua1
-rw-r--r--script/core/command/solve.lua1
-rw-r--r--script/core/definition.lua4
-rw-r--r--script/core/diagnostics/ambiguity-1.lua1
-rw-r--r--script/core/diagnostics/close-non-object.lua1
-rw-r--r--script/core/diagnostics/count-down-loop.lua6
-rw-r--r--script/core/document-symbol.lua3
-rw-r--r--script/core/highlight.lua3
-rw-r--r--script/core/hover/init.lua2
-rw-r--r--script/core/hover/label.lua3
-rw-r--r--script/core/hover/table.lua2
-rw-r--r--script/core/noder.lua60
-rw-r--r--script/core/rename.lua3
-rw-r--r--script/core/searcher.lua3
-rw-r--r--script/parser/ast.lua2
-rw-r--r--script/parser/guide.lua10
-rw-r--r--test.lua2
-rw-r--r--test/type_inference/init.lua50
18 files changed, 136 insertions, 21 deletions
diff --git a/main.lua b/main.lua
index 9bd70a0e..0c130493 100644
--- a/main.lua
+++ b/main.lua
@@ -18,6 +18,7 @@ end
local function loadArgs()
for _, v in ipairs(arg) do
+ ---@type string
local key, value = v:match '^%-%-([%w_]+)%=(.+)'
if not key then
goto CONTINUE
diff --git a/script/core/command/solve.lua b/script/core/command/solve.lua
index 348c2646..a493de24 100644
--- a/script/core/command/solve.lua
+++ b/script/core/command/solve.lua
@@ -20,6 +20,7 @@ local opMap = {
local literalMap = {
['number'] = true,
+ ['integer'] = true,
['boolean'] = true,
['string'] = true,
['table'] = true,
diff --git a/script/core/definition.lua b/script/core/definition.lua
index 589e4d79..593f8f34 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -44,6 +44,7 @@ local accept = {
['string'] = true,
['boolean'] = true,
['number'] = true,
+ ['integer'] = true,
['...'] = true,
['doc.type.name'] = true,
@@ -87,7 +88,8 @@ local function convertIndex(source)
end
if source.type == 'string'
or source.type == 'boolean'
- or source.type == 'number' then
+ or source.type == 'number'
+ or source.type == 'integer' then
local parent = source.parent
if not parent then
return
diff --git a/script/core/diagnostics/ambiguity-1.lua b/script/core/diagnostics/ambiguity-1.lua
index bae39a03..68e88e22 100644
--- a/script/core/diagnostics/ambiguity-1.lua
+++ b/script/core/diagnostics/ambiguity-1.lua
@@ -19,6 +19,7 @@ local opMap = {
local literalMap = {
['number'] = true,
+ ['integer'] = true,
['boolean'] = true,
['string'] = true,
['table'] = true,
diff --git a/script/core/diagnostics/close-non-object.lua b/script/core/diagnostics/close-non-object.lua
index afd259d0..b9d3c485 100644
--- a/script/core/diagnostics/close-non-object.lua
+++ b/script/core/diagnostics/close-non-object.lua
@@ -25,6 +25,7 @@ return function (uri, callback)
end
if source.value.type == 'nil'
or source.value.type == 'number'
+ or source.value.type == 'integer'
or source.value.type == 'boolean'
or source.value.type == 'table'
or source.value.type == 'function' then
diff --git a/script/core/diagnostics/count-down-loop.lua b/script/core/diagnostics/count-down-loop.lua
index a16811ab..1a7dcf7d 100644
--- a/script/core/diagnostics/count-down-loop.lua
+++ b/script/core/diagnostics/count-down-loop.lua
@@ -13,11 +13,11 @@ return function (uri, callback)
if not source.loc or not source.loc.value then
return
end
- local maxNumer = source.max and source.max.type == 'number' and tonumber(source.max[1])
+ local maxNumer = source.max and tonumber(source.max[1])
if maxNumer ~= 1 then
return
end
- local minNumber = source.loc and source.loc.value and source.loc.value.type == 'number' and tonumber(source.loc.value[1])
+ local minNumber = source.loc and source.loc.value and tonumber(source.loc.value[1])
if minNumber and minNumber <= 1 then
return
end
@@ -28,7 +28,7 @@ return function (uri, callback)
message = lang.script('DIAG_COUNT_DOWN_LOOP', ('%s, %s'):format(text:sub(source.loc.value.start, source.max.finish), '-1'))
}
else
- local stepNumber = source.step.type == 'number' and tonumber(source.step[1])
+ local stepNumber = tonumber(source.step[1])
if stepNumber and stepNumber > 0 then
callback {
start = source.loc.value.start,
diff --git a/script/core/document-symbol.lua b/script/core/document-symbol.lua
index 03169cfd..86d95a59 100644
--- a/script/core/document-symbol.lua
+++ b/script/core/document-symbol.lua
@@ -147,7 +147,8 @@ local function buildValue(source, text, symbols)
details[3] = ' = '
details[4] = util.viewLiteral(source.value[1])
end
- elseif source.value.type == 'number' then
+ elseif source.value.type == 'number'
+ or source.value.type == 'integer' then
details[2] = ' number'
if literal ~= nil then
details[3] = ' = '
diff --git a/script/core/highlight.lua b/script/core/highlight.lua
index 759029c3..74025ca9 100644
--- a/script/core/highlight.lua
+++ b/script/core/highlight.lua
@@ -48,6 +48,7 @@ local function find(source, uri, callback)
elseif source.type == 'string'
or source.type == 'boolean'
or source.type == 'number'
+ or source.type == 'integer'
or source.type == 'nil' then
callback(source)
end
@@ -222,6 +223,7 @@ local accept = {
['string'] = true,
['boolean'] = true,
['number'] = true,
+ ['integer'] = true,
['nil'] = true,
}
@@ -325,6 +327,7 @@ return function (uri, offset)
elseif target.type == 'string'
or target.type == 'boolean'
or target.type == 'number'
+ or target.type == 'integer'
or target.type == 'nil' then
kind = define.DocumentHighlightKind.Text
else
diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua
index 06c84c86..c6c2d92e 100644
--- a/script/core/hover/init.lua
+++ b/script/core/hover/init.lua
@@ -70,6 +70,7 @@ local function getHoverAsFunction(source)
elseif def.type == 'table'
or def.type == 'boolean'
or def.type == 'string'
+ or def.type == 'integer'
or def.type == 'number' then
other = other + 1
desc = desc or getDesc(def)
@@ -151,6 +152,7 @@ local accept = {
['method'] = true,
['string'] = true,
['number'] = true,
+ ['integer'] = true,
['doc.type.name'] = true,
['function'] = true,
}
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua
index 71cbef43..d3715a35 100644
--- a/script/core/hover/label.lua
+++ b/script/core/hover/label.lua
@@ -196,7 +196,8 @@ return function (source, oop)
return asField(source)
elseif source.type == 'string' then
return asString(source)
- elseif source.type == 'number' then
+ elseif source.type == 'number'
+ or source.type == 'integer' then
return asNumber(source)
elseif source.type == 'doc.type.function' then
return asDocFunction(source)
diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua
index 8bcce0ae..eb5faa9f 100644
--- a/script/core/hover/table.lua
+++ b/script/core/hover/table.lua
@@ -68,7 +68,7 @@ local function getKeyMap(fields)
for _, field in ipairs(fields) do
local key = vm.getKeyName(field)
local tp = vm.getKeyType(field)
- if tp == 'number' then
+ if tp == 'number' or tp == 'integer' then
key = tonumber(key)
elseif tp == 'boolean' then
key = key == 'true'
diff --git a/script/core/noder.lua b/script/core/noder.lua
index 0b132509..9fcdd7d9 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -88,6 +88,7 @@ local function getKey(source)
end
if index.type == 'string'
or index.type == 'boolean'
+ or index.type == 'integer'
or index.type == 'number' then
return ('%q'):format(index[1] or ''), source.node
else
@@ -203,11 +204,17 @@ local function checkMode(source)
if source.type == 'string' then
return 'str:'
end
- if source.type == 'number'
- or source.type == 'integer'
- or source.type == 'boolean'
- or source.type == 'nil' then
- return 'i:'
+ if source.type == 'number' then
+ return 'num:'
+ end
+ if source.type == 'integer' then
+ return 'int:'
+ end
+ if source.type == 'boolean' then
+ return 'bool:'
+ end
+ if source.type == 'nil' then
+ return 'nil:'
end
if source.type == 'call' then
return 'c:'
@@ -606,6 +613,18 @@ function m.compileNode(noders, source)
if source.type == 'string' then
pushForward(noders, id, 'str:')
end
+ if source.type == 'boolean' then
+ pushForward(noders, id, 'dn:boolean')
+ end
+ if source.type == 'number' then
+ pushForward(noders, id, 'dn:number')
+ end
+ if source.type == 'integer' then
+ pushForward(noders, id, 'dn:integer')
+ end
+ if source.type == 'nil' then
+ pushForward(noders, id, 'dn:nil')
+ end
-- self -> mt:xx
if source.type == 'local' and source[1] == 'self' then
local func = guide.getParentFunction(source)
@@ -873,13 +892,30 @@ function m.compileNode(noders, source)
end
end
if source.type == 'table' then
- if #source == 1 and source[1].type == 'varargs' then
- source.array = source[1]
- local nodeID = ('%s%s'):format(
- id,
- ANY_FIELD
- )
- pushForward(noders, nodeID, getID(source[1]))
+ local keyID = ('%s%s'):format(
+ id,
+ TABLE_KEY
+ )
+ local valueID = ('%s%s'):format(
+ id,
+ ANY_FIELD
+ )
+ local firstField = source[1]
+ if firstField then
+ if firstField.type == 'varargs' then
+ source.array = firstField
+ pushForward(noders, keyID, 'dn:integer')
+ pushForward(noders, valueID, getID(firstField))
+ elseif firstField.type == 'tablefield' then
+ pushForward(noders, keyID, 'dn:string')
+ pushForward(noders, valueID, getID(firstField.value))
+ elseif firstField.type == 'tableindex' then
+ pushForward(noders, keyID, getID(firstField.index))
+ pushForward(noders, valueID, getID(firstField.value))
+ else
+ pushForward(noders, keyID, 'dn:integer')
+ pushForward(noders, valueID, getID(firstField))
+ end
end
end
if source.type == 'main' then
diff --git a/script/core/rename.lua b/script/core/rename.lua
index bc85ac14..cefdbdf6 100644
--- a/script/core/rename.lua
+++ b/script/core/rename.lua
@@ -369,6 +369,7 @@ local function rename(source, newname, callback)
return ofDocParamName(source, newname, callback)
elseif source.type == 'string'
or source.type == 'number'
+ or source.type == 'integer'
or source.type == 'boolean' then
local parent = source.parent
if not parent then
@@ -401,6 +402,7 @@ local function prepareRename(source)
return source, source[1]
elseif source.type == 'string'
or source.type == 'number'
+ or source.type == 'integer'
or source.type == 'boolean' then
local parent = source.parent
if not parent then
@@ -430,6 +432,7 @@ local accept = {
['string'] = true,
['boolean'] = true,
['number'] = true,
+ ['integer'] = true,
['doc.class.name'] = true,
['doc.type.name'] = true,
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index ef1090e9..8e984843 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -102,6 +102,7 @@ function m.pushResult(status, mode, source, force)
or source.type == 'string'
or source.type == 'boolean'
or source.type == 'number'
+ or source.type == 'integer'
or source.type == 'nil'
or source.type == 'doc.class.name'
or source.type == 'doc.type.name'
@@ -475,6 +476,8 @@ function m.searchRefsByID(status, uri, expect, mode)
or id == 'dn:string' then
if field or mode == 'field' then
searchID('dn:stringlib', field)
+ else
+ searchID('dn:string', field)
end
end
end
diff --git a/script/parser/ast.lua b/script/parser/ast.lua
index 40b5788e..bd8a66cf 100644
--- a/script/parser/ast.lua
+++ b/script/parser/ast.lua
@@ -547,7 +547,7 @@ local Defs = {
local n = tonumber(number)
if n then
State.LastNumber = {
- type = 'number',
+ type = mathType(n) == 'integer' and 'integer' or 'number',
start = start,
finish = finish - 1,
[1] = n,
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 1c6b9e81..e6501f12 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -183,6 +183,7 @@ function m.isLiteral(obj)
or tp == 'boolean'
or tp == 'string'
or tp == 'number'
+ or tp == 'integer'
or tp == 'table'
or tp == 'function'
end
@@ -198,6 +199,8 @@ function m.getLiteral(obj)
return obj[1]
elseif tp == 'number' then
return obj[1]
+ elseif tp == 'integer' then
+ return obj[1]
end
return nil
end
@@ -818,6 +821,11 @@ function m.getKeyNameOfLiteral(obj)
if n then
return ('%s'):format(formatNumber(obj[1]))
end
+ elseif tp == 'integer' then
+ local n = obj[1]
+ if n then
+ return ('%s'):format(formatNumber(obj[1]))
+ end
elseif tp == 'boolean' then
local b = obj[1]
if b then
@@ -883,6 +891,8 @@ function m.getKeyTypeOfLiteral(obj)
return 'string'
elseif tp == 'number' then
return 'number'
+ elseif tp == 'integer' then
+ return 'integer'
elseif tp == 'boolean' then
return 'boolean'
end
diff --git a/test.lua b/test.lua
index 3f2cf2cd..b7f99590 100644
--- a/test.lua
+++ b/test.lua
@@ -10,7 +10,7 @@ ROOT = fs.path(rootPath)
TEST = true
DEVELOP = true
FOOTPRINT = true
---TRACE = true
+TRACE = true
LOGPATH = LOGPATH or (ROOT .. '/log')
METAPATH = METAPATH or (ROOT .. '/meta')
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index c23d12f5..0ea6b96c 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -772,3 +772,53 @@ TEST 'string|fun():string' [[
---@type string | fun(): string
local <?t?>
]]
+
+TEST 'string' [[
+local valids = {
+ ['Lua 5.1'] = false,
+ ['Lua 5.2'] = false,
+ ['Lua 5.3'] = false,
+ ['Lua 5.4'] = false,
+ ['LuaJIT'] = false,
+}
+
+for <?k?>, v in pairs(valids) do
+end
+]]
+
+TEST 'boolean' [[
+local valids = {
+ ['Lua 5.1'] = false,
+ ['Lua 5.2'] = false,
+ ['Lua 5.3'] = false,
+ ['Lua 5.4'] = false,
+ ['LuaJIT'] = false,
+}
+
+for k, <?v?> in pairs(valids) do
+end
+]]
+
+TEST 'string' [[
+local t = {
+ a = 1,
+ b = 1,
+}
+
+for <?k?>, v in pairs(t) do
+end
+]]
+
+TEST 'integer' [[
+local t = {'a', 'b'}
+
+for <?k?>, v in pairs(t) do
+end
+]]
+
+TEST 'string' [[
+local t = {'a', 'b'}
+
+for k, <?v?> in pairs(t) do
+end
+]]