summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/launch.json6
-rw-r--r--changelog.md11
-rw-r--r--meta/template/basic.lua48
-rw-r--r--script/cli/check.lua3
-rw-r--r--script/core/completion/keyword.lua35
-rw-r--r--script/core/diagnostics/incomplete-signature-doc.lua2
-rw-r--r--script/core/diagnostics/missing-local-export-doc.lua3
-rw-r--r--script/core/diagnostics/param-type-mismatch.lua18
-rw-r--r--script/parser/guide.lua2
-rw-r--r--script/plugins/ffi/c-parser/ctypes.lua5
-rw-r--r--script/plugins/ffi/cdefRerence.lua2
-rw-r--r--script/vm/compiler.lua6
-rw-r--r--test/completion/common.lua70
-rw-r--r--test/diagnostics/type-check.lua8
14 files changed, 171 insertions, 48 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index b80e7f49..efc6d602 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -9,12 +9,10 @@
"stopOnEntry": false,
"program": "${workspaceRoot}/test.lua",
"luaexe": "${workspaceFolder}/bin/lua-language-server",
- "cpath": null,
- "arg": [
- ],
"luaVersion": "5.4",
"sourceCoding": "utf8",
- "console": "internalConsole",
+ "console": "integratedTerminal",
+ "internalConsoleOptions": "openOnSessionStart",
"outputCapture": [
"print",
"stderr",
diff --git a/changelog.md b/changelog.md
index 35c4c301..2b570ab5 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,16 @@
# changelog
+## 3.6.22
+* `FIX` [#2038]
+* `FIX` [#2042]
+* `FIX` [#2062]
+* `FIX` [#2083]
+
+[#2038]: https://github.com/LuaLS/lua-language-server/issues/2038
+[#2042]: https://github.com/LuaLS/lua-language-server/issues/2042
+[#2062]: https://github.com/LuaLS/lua-language-server/issues/2062
+[#2083]: https://github.com/LuaLS/lua-language-server/issues/2083
+
## 3.6.21
`2023-5-24`
* `FIX` disable ffi plugin
diff --git a/meta/template/basic.lua b/meta/template/basic.lua
index 62ab999e..e646d3b8 100644
--- a/meta/template/basic.lua
+++ b/meta/template/basic.lua
@@ -213,37 +213,37 @@ function setfenv(f, table) end
---@class metatable
---@field __mode 'v'|'k'|'kv'|nil
---@field __metatable any|nil
----@field __tostring fun(t):string|nil
+---@field __tostring (fun(t):string)|nil
---@field __gc fun(t)|nil
----@field __add fun(t1,t2):any|nil
----@field __sub fun(t1,t2):any|nil
----@field __mul fun(t1,t2):any|nil
----@field __div fun(t1,t2):any|nil
----@field __mod fun(t1,t2):any|nil
----@field __pow fun(t1,t2):any|nil
----@field __unm fun(t):any|nil
+---@field __add (fun(t1,t2):any)|nil
+---@field __sub (fun(t1,t2):any)|nil
+---@field __mul (fun(t1,t2):any)|nil
+---@field __div (fun(t1,t2):any)|nil
+---@field __mod (fun(t1,t2):any)|nil
+---@field __pow (fun(t1,t2):any)|nil
+---@field __unm (fun(t):any)|nil
---#if VERSION >= 5.3 then
----@field __idiv fun(t1,t2):any|nil
----@field __band fun(t1,t2):any|nil
----@field __bor fun(t1,t2):any|nil
----@field __bxor fun(t1,t2):any|nil
----@field __bnot fun(t):any|nil
----@field __shl fun(t1,t2):any|nil
----@field __shr fun(t1,t2):any|nil
+---@field __idiv (fun(t1,t2):any)|nil
+---@field __band (fun(t1,t2):any)|nil
+---@field __bor (fun(t1,t2):any)|nil
+---@field __bxor (fun(t1,t2):any)|nil
+---@field __bnot (fun(t):any)|nil
+---@field __shl (fun(t1,t2):any)|nil
+---@field __shr (fun(t1,t2):any)|nil
---#end
----@field __concat fun(t1,t2):any|nil
----@field __len fun(t):integer|nil
----@field __eq fun(t1,t2):boolean|nil
----@field __lt fun(t1,t2):boolean|nil
----@field __le fun(t1,t2):boolean|nil
----@field __index table|fun(t,k)|nil
+---@field __concat (fun(t1,t2):any)|nil
+---@field __len (fun(t):integer)|nil
+---@field __eq (fun(t1,t2):boolean)|nil
+---@field __lt (fun(t1,t2):boolean)|nil
+---@field __le (fun(t1,t2):boolean)|nil
+---@field __index table|(fun(t,k):any)|nil
---@field __newindex table|fun(t,k,v)|nil
----@field __call fun(t,...)|nil
+---@field __call (fun(t,...):...)|nil
---#if VERSION > 5.1 or VERSION == JIT then
----@field __pairs fun(t):fun(t,k,v)|nil
+---@field __pairs (fun(t):(fun(t,k,v):any,any))|nil
---#end
---#if VERSION == JIT or VERSION == 5.2 then
----@field __ipairs fun(t):fun(t,k,v)|nil
+---@field __ipairs (fun(t):(fun(t,k,v):(integer|nil),any))|nil
---#end
---#DES 'setmetatable'
diff --git a/script/cli/check.lua b/script/cli/check.lua
index 94f34b2a..323ea74b 100644
--- a/script/cli/check.lua
+++ b/script/cli/check.lua
@@ -9,6 +9,7 @@ local lang = require 'language'
local define = require 'proto.define'
local config = require 'config.config'
local fs = require 'bee.filesystem'
+local provider = require 'provider'
require 'vm'
@@ -52,6 +53,8 @@ lclient():start(function (client)
io.write(lang.script('CLI_CHECK_INITING'))
+ provider.updateConfig(rootUri)
+
ws.awaitReady(rootUri)
local disables = util.arrayToHash(config.get(rootUri, 'Lua.diagnostics.disable'))
diff --git a/script/core/completion/keyword.lua b/script/core/completion/keyword.lua
index e6f50242..aa0e2148 100644
--- a/script/core/completion/keyword.lua
+++ b/script/core/completion/keyword.lua
@@ -3,6 +3,7 @@ local files = require 'files'
local guide = require 'parser.guide'
local config = require 'config'
local util = require 'utility'
+local lookback = require 'core.look-backward'
local keyWordMap = {
{ 'do', function(info, results)
@@ -372,17 +373,35 @@ end"
else
newText = '::continue::'
end
+ local additional = {}
+
+ local word = lookback.findWord(info.state.lua, guide.positionToOffset(info.state, info.start) - 1)
+ if word ~= 'goto' then
+ additional[#additional+1] = {
+ start = info.start,
+ finish = info.start,
+ newText = 'goto ',
+ }
+ end
+
+ local hasContinue = guide.eachSourceType(mostInsideBlock, 'label', function (src)
+ if src[1] == 'continue' then
+ return true
+ end
+ end)
+
+ if not hasContinue then
+ additional[#additional+1] = {
+ start = endPos,
+ finish = endPos,
+ newText = newText,
+ }
+ end
results[#results+1] = {
label = 'goto continue ..',
kind = define.CompletionItemKind.Snippet,
- insertText = "goto continue",
- additionalTextEdits = {
- {
- start = endPos,
- finish = endPos,
- newText = newText,
- }
- }
+ insertText = "continue",
+ additionalTextEdits = additional,
}
return true
end }
diff --git a/script/core/diagnostics/incomplete-signature-doc.lua b/script/core/diagnostics/incomplete-signature-doc.lua
index 91f2db74..c030e7ad 100644
--- a/script/core/diagnostics/incomplete-signature-doc.lua
+++ b/script/core/diagnostics/incomplete-signature-doc.lua
@@ -59,7 +59,7 @@ return function (uri, callback)
local functionName = source.parent[1]
- if #source.args > 0 then
+ if source.args and #source.args > 0 then
for _, arg in ipairs(source.args) do
local argName = arg[1]
if argName ~= 'self' then
diff --git a/script/core/diagnostics/missing-local-export-doc.lua b/script/core/diagnostics/missing-local-export-doc.lua
index 5825c115..f12e954f 100644
--- a/script/core/diagnostics/missing-local-export-doc.lua
+++ b/script/core/diagnostics/missing-local-export-doc.lua
@@ -10,6 +10,9 @@ local function findSetField(ast, name, callback)
await.delay()
if source.node[1] == name then
local funcPtr = source.value.node
+ if not funcPtr then
+ return
+ end
local func = funcPtr.value
if funcPtr.type == 'local' and func.type == 'function' then
helper.CheckFunction(func, callback, 'DIAG_MISSING_LOCAL_EXPORT_DOC_COMMENT', 'DIAG_MISSING_LOCAL_EXPORT_DOC_PARAM', 'DIAG_MISSING_LOCAL_EXPORT_DOC_RETURN')
diff --git a/script/core/diagnostics/param-type-mismatch.lua b/script/core/diagnostics/param-type-mismatch.lua
index da39c5e1..acbf9c8c 100644
--- a/script/core/diagnostics/param-type-mismatch.lua
+++ b/script/core/diagnostics/param-type-mismatch.lua
@@ -32,26 +32,28 @@ end
---@param funcNode vm.node
---@param i integer
+---@param uri uri
---@return vm.node?
-local function getDefNode(funcNode, i)
+local function getDefNode(funcNode, i, uri)
local defNode = vm.createNode()
- for f in funcNode:eachObject() do
- if f.type == 'function'
- or f.type == 'doc.type.function' then
- local param = f.args and f.args[i]
+ for src in funcNode:eachObject() do
+ if src.type == 'function'
+ or src.type == 'doc.type.function' then
+ local param = src.args and src.args[i]
if param then
defNode:merge(vm.compileNode(param))
if param[1] == '...' then
defNode:addOptional()
end
-
- expandGenerics(defNode)
end
end
end
if defNode:isEmpty() then
return nil
end
+
+ expandGenerics(defNode)
+
return defNode
end
@@ -91,7 +93,7 @@ return function (uri, callback)
if not refNode then
goto CONTINUE
end
- local defNode = getDefNode(funcNode, i)
+ local defNode = getDefNode(funcNode, i, uri)
if not defNode then
goto CONTINUE
end
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index e7eb3751..d7399b4d 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -720,7 +720,7 @@ end
--- 遍历所有指定类型的source
---@param ast parser.object
---@param type string
----@param callback fun(src: parser.object)
+---@param callback fun(src: parser.object): any
---@return any
function m.eachSourceType(ast, type, callback)
local cache = getSourceTypeCache(ast)
diff --git a/script/plugins/ffi/c-parser/ctypes.lua b/script/plugins/ffi/c-parser/ctypes.lua
index 81d0ccf6..115f78ab 100644
--- a/script/plugins/ffi/c-parser/ctypes.lua
+++ b/script/plugins/ffi/c-parser/ctypes.lua
@@ -149,7 +149,10 @@ end
local function add_to_fields(lst, field_src, fields)
if type(field_src) == "table" and not field_src.ids then
assert(field_src.type.type == "union")
- local subfields = get_fields(lst, field_src.type.fields)
+ local subfields, err = get_fields(lst, field_src.type.fields)
+ if not subfields then
+ return nil, err
+ end
for _, subfield in ipairs(subfields) do
table.insert(fields, subfield)
end
diff --git a/script/plugins/ffi/cdefRerence.lua b/script/plugins/ffi/cdefRerence.lua
index 14643f0f..54a8c2a7 100644
--- a/script/plugins/ffi/cdefRerence.lua
+++ b/script/plugins/ffi/cdefRerence.lua
@@ -20,7 +20,7 @@ end
return function ()
local ffi_state
for uri in files.eachFile() do
- if find(uri, "ffi.lua", 0, true) and find(uri, "lua-language-server", 0, true) then
+ if find(uri, "ffi.lua", 0, true) and find(uri, "meta", 0, true) then
ffi_state = files.getState(uri)
break
end
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 6b4636fc..cd114bd1 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -55,6 +55,9 @@ function vm.bindDocs(source)
vm.setNode(source, vm.compileNode(ast))
return true
end
+ if doc.type == 'doc.overload' then
+ vm.setNode(source, vm.compileNode(doc))
+ end
end
return false
end
@@ -1020,6 +1023,7 @@ local function compileLocal(source)
vm.setNode(source, vm.compileNode(source.value))
end
end
+
-- function x.y(self, ...) --> function x:y(...)
if source[1] == 'self'
and not hasMarkDoc
@@ -1031,6 +1035,7 @@ local function compileLocal(source)
vm.setNode(source, vm.compileNode(setfield.node))
end
end
+
if source.parent.type == 'funcargs' and not hasMarkDoc and not hasMarkParam then
local func = source.parent.parent
-- local call ---@type fun(f: fun(x: number));call(function (x) end) --> x -> number
@@ -1055,6 +1060,7 @@ local function compileLocal(source)
vm.setNode(source, vm.declareGlobal('type', 'any'))
end
end
+
-- for x in ... do
if source.parent.type == 'in' then
compileForVars(source.parent, source)
diff --git a/test/completion/common.lua b/test/completion/common.lua
index 8d23822a..8d53b89a 100644
--- a/test/completion/common.lua
+++ b/test/completion/common.lua
@@ -4114,3 +4114,73 @@ f({
kind = define.CompletionItemKind.Text,
},
}
+
+TEST [[
+while true do
+ continue<??>
+end
+]]
+{
+ {
+ label = 'continue',
+ kind = define.CompletionItemKind.Keyword,
+ },
+ {
+ label = 'goto continue ..',
+ kind = define.CompletionItemKind.Snippet,
+ additionalTextEdits = {
+ {
+ start = 10004,
+ finish = 10004,
+ newText = 'goto ',
+ },
+ {
+ start = 20000,
+ finish = 20000,
+ newText = ' ::continue::\n',
+ },
+ }
+ },
+}
+
+TEST [[
+while true do
+ goto continue<??>
+end
+]]
+{
+ {
+ label = 'continue',
+ kind = define.CompletionItemKind.Keyword,
+ },
+ {
+ label = 'goto continue ..',
+ kind = define.CompletionItemKind.Snippet,
+ additionalTextEdits = {
+ {
+ start = 20000,
+ finish = 20000,
+ newText = ' ::continue::\n',
+ }
+ }
+ },
+}
+
+TEST [[
+while true do
+ goto continue<??>
+ ::continue::
+end
+]]
+{
+ {
+ label = 'continue',
+ kind = define.CompletionItemKind.Keyword,
+ },
+ {
+ label = 'goto continue ..',
+ kind = define.CompletionItemKind.Snippet,
+ additionalTextEdits = {
+ }
+ },
+}
diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua
index 18e7190d..dd9d1198 100644
--- a/test/diagnostics/type-check.lua
+++ b/test/diagnostics/type-check.lua
@@ -1255,6 +1255,14 @@ local var
func(var)
]]
+TEST [[
+---@class MyClass
+---@overload fun(x : string) : MyClass
+local MyClass = {}
+
+local w = MyClass(<!1!>)
+]]
+
config.remove(nil, 'Lua.diagnostics.disable', 'unused-local')
config.remove(nil, 'Lua.diagnostics.disable', 'unused-function')
config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global')