diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/core/hover/label.lua | 3 | ||||
-rw-r--r-- | script/core/infer.lua | 5 | ||||
-rw-r--r-- | script/core/noder.lua | 3 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 2 | ||||
-rw-r--r-- | script/parser/newparser.lua | 16 | ||||
-rw-r--r-- | test/hover/init.lua | 15 | ||||
-rw-r--r-- | test/type_inference/init.lua | 7 |
8 files changed, 39 insertions, 13 deletions
diff --git a/changelog.md b/changelog.md index 7d46a108..8d897903 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ + `Lua.completion.requireSeparator` * `NEW` diagnostics: + `different-requires` +* `NEW` supports `---@CustomClass<string, number>` * `CHG` hover: improve showing multi defines * `CHG` hover: improve showing multi comments at enums * `CHG` hint: `Lua.hint.paramName` now supports `Disable`, `Literal` and `All` diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index a29cf672..3322e0d3 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -50,8 +50,7 @@ local function asValue(source, title) local literal = infer.searchAndViewLiterals(source) local cont if not infer.hasType(source, 'string') - and not type:find('%[%]$') - and not type:find('%w%<') then + and not type:find('%[%]$') then if #vm.getRefs(source, '*') > 0 or infer.hasType(source, 'table') then cont = buildTable(source) diff --git a/script/core/infer.lua b/script/core/infer.lua index d6784c67..2915f7f5 100644 --- a/script/core/infer.lua +++ b/script/core/infer.lua @@ -371,9 +371,10 @@ function m.getDocName(doc) return nodeName .. '[]' end if doc.type == 'doc.type.table' then - local key = m.viewDocName(doc.tkey) or '?' + local node = m.viewDocName(doc.node) or '?' + local key = m.viewDocName(doc.tkey) or '?' local value = m.viewDocName(doc.tvalue) or '?' - return ('table<%s, %s>'):format(key, value) + return ('%s<%s, %s>'):format(node, key, value) end if doc.type == 'doc.type.function' then return m.viewDocFunction(doc) diff --git a/script/core/noder.lua b/script/core/noder.lua index 927f3c6d..f364f458 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -905,6 +905,9 @@ compileNodeMap = util.switch() end) : case 'doc.type.table' : call(function (noders, id, source) + if source.node then + pushForward(noders, id, getID(source.node), INFO_CLASS_TO_EXNTENDS) + end if source.tkey then local keyID = id .. TABLE_KEY pushForward(noders, keyID, getID(source.tkey)) diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 4a431e68..56da32f2 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -324,7 +324,7 @@ local function parseTypeUnitTable(parent, node) end nextSymbolOrError('>') - node.parent = result; + node.parent = result result.finish = getFinish() result.tkey = key result.tvalue = value diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index ee2c5e62..8469b68d 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -374,6 +374,12 @@ local function fastForwardToken(offset) or myOffset >= offset then break end + local token = Tokens[Index + 1] + if NLMap[token] then + Line = Line + 1 + LineOffset = Tokens[Index] + #token + State.lines[Line] = LineOffset + end Index = Index + 2 end end @@ -390,14 +396,8 @@ local function resolveLongString(finishMark) local stringResult = ssub(Lua, start, finishOffset - 1) local lastLN = stringResult:find '[\r\n][^\r\n]*$' if lastLN then - local result, count = stringResult - : gsub('\r\n', '\n') - : gsub('[\r\n]', '\n') - LineOffset = lastLN + start - for i = Line + 1, Line + count do - State.lines[i] = LineOffset - end - Line = Line + count + local result = stringResult + : gsub('\r\n?', '\n') stringResult = result end fastForwardToken(finishOffset + #finishMark) diff --git a/test/hover/init.lua b/test/hover/init.lua index c16e466d..8058317d 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -1699,3 +1699,18 @@ print(b.<?x?>) [[ field A.x: any ]] + +TEST [[ +---@class A +---@field x number +---@field y number + +---@type A<string, number> +local <?t?> +]] +[[ +local t: A<string, number> { + x: number, + y: number, +} +]] diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 286d47cb..23ebf54e 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -353,6 +353,13 @@ TEST 'table<string, number>' [[ local <?x?> ]] +TEST 'A<string, number>' [[ +---@class A + +---@type A<string, number> +local <?x?> +]] + TEST 'table' [[ self.<?t?>[#self.t+1] = {} ]] |