diff options
-rw-r--r-- | script/core/hover/description.lua | 16 | ||||
-rw-r--r-- | script/vm/compiler.lua | 3 | ||||
-rw-r--r-- | script/vm/infer.lua | 3 | ||||
-rw-r--r-- | test/crossfile/hover.lua | 18 | ||||
-rw-r--r-- | test/type_inference/init.lua | 9 |
5 files changed, 26 insertions, 23 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index d3d24a75..8fe2eb4f 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -125,24 +125,14 @@ end local function tryDocClassComment(source) for _, def in ipairs(vm.getDefs(source)) do - if def.type == 'doc.class.name' - or def.type == 'doc.alias.name' then - local class = noder.getDocState(def) - local comment = getBindComment(class, class.bindGroup, class) + if def.type == 'doc.class' + or def.type == 'doc.alias' then + local comment = getBindComment(def, def.bindGroup, def) if comment then return comment end end end - if source.bindDocs then - for _, doc in ipairs(source.bindDocs) do - if doc.type == 'doc.class' - or doc.type == 'doc.alias' then - local comment = getBindComment(doc, source.bindDocs, doc) - return comment - end - end - end end local function tryDocModule(source) diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index e244c6c3..8ee35ad4 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -720,7 +720,8 @@ local compilerSwitch = util.switch() compileByLocalID(source) local key = guide.getKeyName(source) m.compileByParentNode(source.node, key, function (src) - if src.type == 'doc.type.field' then + if src.type == 'doc.type.field' + or src.type == 'doc.field' then nodeMgr.setNode(source, m.compileNode(src)) end end) diff --git a/script/vm/infer.lua b/script/vm/infer.lua index e6ca14e2..853bd7de 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -81,6 +81,9 @@ local viewNodeSwitch = util.switch() : call(function (source, infer) if source.cate == 'type' then infer._hasClass = true + if source.name == 'number' then + infer._hasNumber = true + end return source.name end end) diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index 10124eb9..b0cc8c7d 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -825,7 +825,7 @@ local <?food?> }, hover = [[ ```lua -local food: any +local food: unknown ``` --- @@ -976,17 +976,17 @@ end }, hover = [[ ```lua -function f(p: a|b) +function f(p: "a"|"b") ``` --- ```lua -p: T - | a -- comment 1 - -- comment 2 - | b -- comment 3 - -- comment 4 +p: + | "a" -- comment 1 + -- comment 2 + | "b" -- comment 3 + -- comment 4 ```]]} --TEST {{ path = 'a.lua', content = '', }, { @@ -1044,13 +1044,13 @@ end for _, x in ipairs({} and {}) do - print(<?x?>) -- `x` is infered as `string` + print(<?x?>) -- `x` is infered as `string` (fixed bug) end ]], }, hover = [[ ```lua -local x: any +local x: unknown ```]] } diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index a6311e6e..5ac5bece 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -1381,3 +1381,12 @@ local t t.<?a?> ]] + +TEST 'integer' [[ +---@class A +---@field x integer + +---@type A +local t +t.<?x?> +]] |