diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-20 15:36:09 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-20 15:36:09 +0800 |
commit | a6ed5f5845d3a859bd88c72f47bc4fa9d120b2df (patch) | |
tree | c4afeffe23e1a1b17197982186747b72bb77dd8e | |
parent | f86c80cf43729d09f816c2ae7c13a26d80ed1179 (diff) | |
download | lua-language-server-a6ed5f5845d3a859bd88c72f47bc4fa9d120b2df.zip |
update
-rw-r--r-- | script/core/type-formatting.lua | 2 | ||||
-rw-r--r-- | script/files.lua | 1 | ||||
-rw-r--r-- | script/progress.lua | 4 | ||||
-rw-r--r-- | script/provider/provider.lua | 2 | ||||
-rw-r--r-- | script/vm/compiler.lua | 15 | ||||
-rw-r--r-- | script/vm/doc.lua | 2 | ||||
-rw-r--r-- | test/type_inference/init.lua | 14 |
7 files changed, 25 insertions, 15 deletions
diff --git a/script/core/type-formatting.lua b/script/core/type-formatting.lua index cc305982..24b4dde4 100644 --- a/script/core/type-formatting.lua +++ b/script/core/type-formatting.lua @@ -48,7 +48,7 @@ local function checkSplitOneLine(results, uri, position, ch) end local fPosition, fSymbol = findForward(uri, position, 'end', '}') - if not fPosition then + if not fPosition or not fSymbol then return end local bPosition = findBackward(uri, position, 'then', 'do', ')', '{') diff --git a/script/files.lua b/script/files.lua index afbd64cb..252a6ee5 100644 --- a/script/files.lua +++ b/script/files.lua @@ -20,7 +20,6 @@ local m = {} m.watchList = {} m.notifyCache = {} m.assocVersion = -1 -m.assocMatcher = nil function m.reset() m.openMap = {} diff --git a/script/progress.lua b/script/progress.lua index b43ed05b..f1f371f5 100644 --- a/script/progress.lua +++ b/script/progress.lua @@ -11,10 +11,10 @@ local m = {} m.map = {} ---@class progress ----@field _uri uri +---@field _uri uri +---@field _token integer local mt = {} mt.__index = mt -mt._token = nil mt._title = nil mt._message = nil mt._removed = false diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 205be08c..44805130 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -317,7 +317,7 @@ m.register 'textDocument/hover' { end local pos = converter.unpackPosition(uri, params.position) local hover, source = core.byUri(uri, pos) - if not hover then + if not hover or not source then return nil end return { diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index c47c41a2..3e601943 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -639,7 +639,7 @@ local function compileByLocalID(source) end if not hasMarkDoc then for _, src in ipairs(sources) do - if src.value and src.value.type ~= 'nil' then + if src.value then local valueNode = vm.compileNode(src.value) if valueNode:hasType 'unknown' then vm.setNode(source, valueNode:copy():remove 'unknown') @@ -684,21 +684,22 @@ local function selectNode(source, list, index) end end if not exp then - return nil + vm.setNode(source, vm.getGlobal('type', 'nil')) + return vm.getNode(source) end ---@type vm.node? local result if exp.type == 'call' then result = getReturn(exp.node, index, exp.args) if not result then - vm.setNode(source, vm.declareGlobal('type', 'unknown')) + vm.setNode(source, vm.getGlobal('type', 'unknown')) return vm.getNode(source) end else ---@type vm.node result = vm.compileNode(exp) if result and exp.type == 'varargs' and result:isEmpty() then - result:merge(vm.declareGlobal('type', 'unknown')) + result:merge(vm.getGlobal('type', 'unknown')) end end if source.type == 'function.return' then @@ -1367,7 +1368,7 @@ local compilerSwitch = util.switch() if not hasMarkDoc or guide.isLiteral(source.value) then if source.value.type == 'table' then vm.setNode(source, source.value) - elseif source.value.type ~= 'nil' then + else vm.setNode(source, vm.compileNode(source.value)) end end @@ -1778,9 +1779,7 @@ local function compileByGlobal(source) for _, set in ipairs(global:getSets(uri)) do if set.value then if not hasMarkDoc or guide.isLiteral(set.value) then - if set.value.type ~= 'nil' then - globalNode:merge(vm.compileNode(set.value)) - end + globalNode:merge(vm.compileNode(set.value)) end end vm.setNode(set, globalNode) diff --git a/script/vm/doc.lua b/script/vm/doc.lua index e2b383b6..6ee00192 100644 --- a/script/vm/doc.lua +++ b/script/vm/doc.lua @@ -101,7 +101,7 @@ local function getDeprecated(value) return doc elseif doc.type == 'doc.version' then local valids = vm.getValidVersions(doc) - if not valids[config.get(guide.getUri(value), 'Lua.runtime.version')] then + if valids and not valids[config.get(guide.getUri(value), 'Lua.runtime.version')] then value._deprecated = doc return doc end diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 74f149e0..3a7b1227 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -296,7 +296,7 @@ end <?y?> = x() ]] -TEST 'unknown' [[ +TEST 'unknown|nil' [[ local function x() return nil return f() @@ -2707,3 +2707,15 @@ end local <?n?> = f() ]] + +TEST 'integer|nil' [[ +local function f() + if x then + return + else + return 1 + end +end + +local <?n?> = f() +]] |