diff options
-rw-r--r-- | script-beta/core/hover/name.lua | 11 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 11 | ||||
-rw-r--r-- | script-beta/vm/eachField.lua | 3 | ||||
-rw-r--r-- | test-beta/hover/init.lua | 24 |
4 files changed, 42 insertions, 7 deletions
diff --git a/script-beta/core/hover/name.lua b/script-beta/core/hover/name.lua index 0711461d..83b779db 100644 --- a/script-beta/core/hover/name.lua +++ b/script-beta/core/hover/name.lua @@ -2,7 +2,16 @@ local guide = require 'parser.guide' local vm = require 'vm' local function asLocal(source) - return guide.getName(source) + local name = guide.getName(source) + if not source.attrs then + return name + end + local label = {} + label[#label+1] = name + for _, attr in ipairs(source.attrs) do + label[#label+1] = ('<%s>'):format(attr[1]) + end + return table.concat(label, ' ') end local function asMethod(source) diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index b756ff61..31e2b9d8 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -2042,6 +2042,7 @@ function m.mergeTypes(types) local results = {} local mark = {} local hasAny + -- 这里把 any 去掉 for i = 1, #types do local tp = types[i] if tp == 'any' then @@ -2055,6 +2056,7 @@ function m.mergeTypes(types) if #results == 0 then return 'any' end + -- 只有显性的 nil 与 any 时,取 any if #results == 1 then if results[1] == 'nil' and hasAny then return 'any' @@ -2062,6 +2064,15 @@ function m.mergeTypes(types) return results[1] end end + -- 同时包含 number 与 integer 时,去掉 integer + if mark['number'] and mark['integer'] then + for i = 1, #results do + if results[i] == 'integer' then + tableRemove(results, i) + break + end + end + end tableSort(results, function (a, b) local sa = TypeSort[a] or 100 local sb = TypeSort[b] or 100 diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua index b49abcad..632cf211 100644 --- a/script-beta/vm/eachField.lua +++ b/script-beta/vm/eachField.lua @@ -64,6 +64,9 @@ end function vm.eachField(source, callback) local results = vm.getFields(source) + if not results then + return + end for i = 1, #results do callback(results[i]) end diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua index 37495fb6..2d0d7b1c 100644 --- a/test-beta/hover/init.lua +++ b/test-beta/hover/init.lua @@ -818,6 +818,24 @@ global _G: _G { } ]] +TEST [[ +local x +x = 1 +x = 1.0 + +print(<?x?>) +]] +[[ +local x: number = 1 +]] + +TEST [[ +local <?x?> <close> = 1 +]] +[[ +local x <close>: integer = 1 +]] + --TEST[[ -----@class Class --local <?x?> = class() @@ -1180,12 +1198,6 @@ global _G: _G { --local x: any --]] -- ---TEST [[ ---local <?x?> <close> <const> = 1 ---]] ---[[ ---local x <close> <const>: number = 1 ---]] -- --TEST [[ -----@param x number {optional = 'after'} |