summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-25 03:48:33 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-25 03:48:33 +0800
commitfa7375775e97d68ce7507b0c7e50eced84bab2ac (patch)
tree6e54e79cc4f8b4b1cdf6e97c8bad09db09673902 /script
parent711c5d44484366ac80d02ff42fc8fab908b10739 (diff)
downloadlua-language-server-fa7375775e97d68ce7507b0c7e50eced84bab2ac.zip
add 2 type related settings
`type.castNumberToInteger` and `type.weakUnionCheck`
Diffstat (limited to 'script')
-rw-r--r--script/config/template.lua4
-rw-r--r--script/vm/type.lua37
2 files changed, 31 insertions, 10 deletions
diff --git a/script/config/template.lua b/script/config/template.lua
index 672bad21..9ede5e96 100644
--- a/script/config/template.lua
+++ b/script/config/template.lua
@@ -330,7 +330,7 @@ local template = {
['Lua.hover.viewString'] = Type.Boolean >> true,
['Lua.hover.viewStringMax'] = Type.Integer >> 1000,
['Lua.hover.viewNumber'] = Type.Boolean >> true,
- ['Lua.hover.previewFields'] = Type.Integer >> 30,
+ ['Lua.hover.previewFields'] = Type.Integer >> 50,
['Lua.hover.enumsLimit'] = Type.Integer >> 5,
['Lua.hover.expandAlias'] = Type.Boolean >> true,
['Lua.semantic.enable'] = Type.Boolean >> true,
@@ -359,6 +359,8 @@ local template = {
['Lua.spell.dict'] = Type.Array(Type.String),
['Lua.telemetry.enable'] = Type.Or(Type.Boolean >> false, Type.Nil) >> nil,
['Lua.misc.parameters'] = Type.Array(Type.String),
+ ['Lua.type.castNumberToInteger'] = Type.Boolean >> false,
+ ['Lua.type.weakUnionCheck'] = Type.Boolean >> false,
-- VSCode
['files.associations'] = Type.Hash(Type.String, Type.String),
diff --git a/script/vm/type.lua b/script/vm/type.lua
index 5211c3cb..d132619c 100644
--- a/script/vm/type.lua
+++ b/script/vm/type.lua
@@ -1,6 +1,7 @@
---@class vm
local vm = require 'vm.vm'
local guide = require 'parser.guide'
+local config = require 'config.config'
---@param object vm.node.object
---@return string?
@@ -53,18 +54,33 @@ function vm.isSubType(uri, child, parent, mark)
end
child = global
elseif child.type == 'vm.node' then
- for n in child:eachObject() do
- if getNodeName(n)
- and not vm.isSubType(uri, n, parent, mark) then
- return false
+ if config.get(uri, 'Lua.type.weakUnionCheck') then
+ for n in child:eachObject() do
+ if getNodeName(n)
+ and vm.isSubType(uri, n, parent, mark) then
+ return true
+ end
end
- end
- if child:isOptional() then
- if not vm.isSubType(uri, 'nil', parent, mark) then
- return false
+ if child:isOptional() then
+ if vm.isSubType(uri, 'nil', parent, mark) then
+ return true
+ end
end
+ return false
+ else
+ for n in child:eachObject() do
+ if getNodeName(n)
+ and not vm.isSubType(uri, n, parent, mark) then
+ return false
+ end
+ end
+ if child:isOptional() then
+ if not vm.isSubType(uri, 'nil', parent, mark) then
+ return false
+ end
+ end
+ return true
end
- return true
end
if type(parent) == 'string' then
@@ -110,6 +126,9 @@ function vm.isSubType(uri, child, parent, mark)
end
if parentName == 'integer' and childName == 'number' then
+ if config.get(uri, 'Lua.type.castNumberToInteger') then
+ return true
+ end
if child.type == 'number'
and child[1]
and not math.tointeger(child[1]) then