diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/core/infer.lua | 74 | ||||
-rw-r--r-- | test/completion/common.lua | 21 | ||||
-rw-r--r-- | test/signature/init.lua | 2 | ||||
-rw-r--r-- | test/type_inference/init.lua | 44 |
5 files changed, 2 insertions, 140 deletions
diff --git a/changelog.md b/changelog.md index 73fb8878..6dd5f965 100644 --- a/changelog.md +++ b/changelog.md @@ -14,6 +14,7 @@ * `CHG` hover: improve showing multi comments at enums * `CHG` hint: `Lua.hint.paramName` now supports `Disable`, `Literal` and `All` * `CHG` only search first file by `require` +* `CHG` no longer infer by usage * `CHG` no longer ignore file names case in Windows * `CHG` watching library changes * `CHG` completion: improve misspelling results diff --git a/script/core/infer.lua b/script/core/infer.lua index 2915f7f5..7ad35643 100644 --- a/script/core/infer.lua +++ b/script/core/infer.lua @@ -4,9 +4,7 @@ local noder = require 'core.noder' local util = require 'utility' local vm = require "vm.vm" -local STRING_OR_TABLE = {'STRING_OR_TABLE'} local BE_RETURN = {'BE_RETURN'} -local BE_CONNACT = {'BE_CONNACT'} local CLASS = {'CLASS'} local TABLE = {'TABLE'} @@ -234,23 +232,6 @@ local function cleanInfers(infers) if infers['stringlib'] and infers['string'] then infers['stringlib'] = nil end - -- 如果是通过 .. 来推测的,且结果里没有 number 与 integer,则推测为string - if infers[BE_CONNACT] then - infers[BE_CONNACT] = nil - if not infers['number'] and not infers['integer'] then - infers['string'] = true - end - end - -- 如果是通过 # 来推测的,且结果里没有其他的 table 与 string,则加入这2个类型 - if infers[STRING_OR_TABLE] then - infers[STRING_OR_TABLE] = nil - if not infers['table'] - and not infers['string'] - and not infers[CLASS] then - infers['table'] = true - infers['string'] = true - end - end -- 如果有doc标记,则先移除table类型 if infers[CLASS] then infers[CLASS] = nil @@ -443,61 +424,6 @@ local function searchInfer(source, infers, mark) infers[TABLE] = true end end - if source.parent.type == 'unary' then - local op = source.parent.op.type - -- # XX -> string | table - if op == '#' then - infers[STRING_OR_TABLE] = true - return - end - if op == '-' then - infers['number'] = true - return - end - if op == '~' then - infers['integer'] = true - return - end - return - end - if source.parent.type == 'binary' then - local op = source.parent.op.type - if op == '+' - or op == '-' - or op == '*' - or op == '/' - or op == '//' - or op == '^' - or op == '%' then - infers['number'] = true - return - end - if op == '<<' - or op == '>>' - or op == '~' - or op == '|' - or op == '&' then - infers['integer'] = true - return - end - if op == '..' then - infers[BE_CONNACT] = true - return - end - end - -- X.a -> table - if source.next and source.next.node == source then - if source.next.type == 'setfield' - or source.next.type == 'setindex' - or source.next.type == 'setmethod' - or source.next.type == 'getfield' - or source.next.type == 'getindex' then - infers['table'] = true - end - if source.next.type == 'getmethod' then - infers[STRING_OR_TABLE] = true - end - end -- return XX if source.parent.type == 'return' then infers[BE_RETURN] = true diff --git a/test/completion/common.lua b/test/completion/common.lua index 33cbdf4d..c5740e15 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -1870,27 +1870,6 @@ end", }, } -TEST [[ ----<??> -local function f(a, b, c) - return a + 1, b .. '', c[1] -end -]] -{ - { - label = '@param;@return', - kind = define.CompletionItemKind.Snippet, - insertText = "\z -${1:comment}\ ----@param a ${2:number}\ ----@param b ${3:string}\ ----@param c ${4:table}\ ----@return ${5:number}\ ----@return ${6:string}\ ----@return ${7:any}", - }, -} - Cared['insertText'] = nil TEST [[ diff --git a/test/signature/init.lua b/test/signature/init.lua index 43bce29e..f1057ae0 100644 --- a/test/signature/init.lua +++ b/test/signature/init.lua @@ -164,7 +164,7 @@ end m.f(<??>) ]] -'function m.f(<!self: table!>)' +'function m.f(<!self: any!>)' TEST [[ ---@alias nnn table<number, string> diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 23ebf54e..ba3ca304 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -92,10 +92,6 @@ TEST 'any' [[ <?x?>() ]] -TEST 'table' [[ -<?t?>.x = 1 -]] - TEST 'boolean' [[ <?x?> = not y ]] @@ -230,20 +226,6 @@ end _, <?y?> = xpcall(x) ]] -TEST 'string|table' [[ -local y = #<?x?> -]] - -TEST 'integer' [[ -local y = <?x?> << 0 -]] - -TEST 'integer' [[ -local function f(<?a?>, b) - return a << b -end -]] - TEST 'A' [[ ---@class A @@ -360,10 +342,6 @@ TEST 'A<string, number>' [[ local <?x?> ]] -TEST 'table' [[ -self.<?t?>[#self.t+1] = {} -]] - TEST 'string' [[ ---@class string @@ -382,28 +360,6 @@ local <?y?> = x[1] ]] TEST 'table' [[ -local <?t?> -print(t.sub()) -]] - -TEST 'string|table' [[ -local <?t?> -print(t:sub()) -]] - -TEST 'string' [[ -local <?t?> -print(t:sub()) -print(t .. 'a') -]] - -TEST 'string' [[ -local <?t?> -print(#t) -print(t .. 'a') -]] - -TEST 'table' [[ local t = {} local <?v?> = setmetatable(t) ]] |