summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------3rd/EmmyLuaCodeStyle0
m---------3rd/bee.lua0
-rw-r--r--changelog.md8
-rw-r--r--locale/en-us/script.lua18
-rw-r--r--meta/template/basic.lua11
-rw-r--r--meta/whimsical/basic.lua14
-rw-r--r--meta/whimsical/builtin.lua110
-rw-r--r--meta/whimsical/rule.lua128
-rw-r--r--script/core/completion/completion.lua15
-rw-r--r--script/provider/provider.lua4
-rw-r--r--test/completion/common.lua6
-rw-r--r--test/plugins/ffi/test.lua7
12 files changed, 197 insertions, 124 deletions
diff --git a/3rd/EmmyLuaCodeStyle b/3rd/EmmyLuaCodeStyle
-Subproject 13b83a9465da6a45e5dae37a34e8fdccde48069
+Subproject 22c1310055fafeda6a331e924438f88d0608e6d
diff --git a/3rd/bee.lua b/3rd/bee.lua
-Subproject e7f8130cf48de894f08934fadbdb8e5ea76c299
+Subproject 6bddb34b4f076bcb6207c53454e65568c173ca1
diff --git a/changelog.md b/changelog.md
index 474625a8..3053ab25 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,14 @@
# changelog
+## 3.7.1
+* `FIX` [#2299]
+* `FIX` [#2335]
+
+[#2299]: https://github.com/LuaLS/lua-language-server/issues/2299
+[#2335]: https://github.com/LuaLS/lua-language-server/issues/2335
+
## 3.7.0
+`2023-8-24`
* `NEW` support `---@type` and `--[[@as]]` for return statement
* `NEW` commandline parameter `--force-accept-workspace`: allowing the use of the root directory or home directory as the workspace
* `NEW` diagnostic: `inject-field`
diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua
index 56e5fd87..20d858bb 100644
--- a/locale/en-us/script.lua
+++ b/locale/en-us/script.lua
@@ -1,7 +1,7 @@
DIAG_LINE_ONLY_SPACE =
'Line with spaces only.'
DIAG_LINE_POST_SPACE =
-'Line with postspace.'
+'Line with trailing space.'
DIAG_UNUSED_LOCAL =
'Unused local `{}`.'
DIAG_UNDEF_GLOBAL =
@@ -174,8 +174,8 @@ DIAG_INJECT_FIELD =
'Fields cannot be injected into the reference of `{class}` for `{field}`. {fix}'
DIAG_INJECT_FIELD_FIX_CLASS =
'To do so, use `---@class` for `{node}`.'
-DIAG_INJECT_FIELD_FIX_TABLE = -- TODO: need translate!
-'如要允许注入,请在定义中添加 `{fix}` 。'
+DIAG_INJECT_FIELD_FIX_TABLE =
+'To allow injection, add `{fix}` to the definition.'
MWS_NOT_SUPPORT =
'{} does not support multi workspace for now, I may need to restart to support the new workspace ...'
@@ -301,9 +301,9 @@ PARSER_INDEX_IN_FUNC_NAME =
'The `[name]` form cannot be used in the name of a named function.'
PARSER_UNKNOWN_ATTRIBUTE =
'Local attribute should be `const` or `close`'
-PARSER_AMBIGUOUS_SYNTAX = -- TODO: need translate!
+PARSER_AMBIGUOUS_SYNTAX =
'In Lua 5.1, the left brackets called by the function must be in the same line as the function.'
-PARSER_NEED_PAREN = -- TODO: need translate!
+PARSER_NEED_PAREN =
'Need to add a pair of parentheses.'
PARSER_NESTING_LONG_MARK =
'Nesting of `[[...]]` is not allowed in Lua 5.1 .'
@@ -454,9 +454,9 @@ ACTION_MARK_ASYNC =
'Mark current function as async.'
ACTION_ADD_DICT =
'Add \'{}\' to workspace dict'
-ACTION_FIX_ADD_PAREN = -- TODO: need translate!
+ACTION_FIX_ADD_PAREN =
'Add parentheses.'
-ACTION_AUTOREQUIRE = -- TODO: need translate!
+ACTION_AUTOREQUIRE =
"Import '{}' as {}"
COMMAND_DISABLE_DIAG =
@@ -1212,7 +1212,7 @@ setColor(colors.green)
LUADOC_DESC_SOURCE =
[=[
Provide a reference to some source code which lives in another file. When
-searching for the defintion of an item, its `@source` will be used.
+searching for the definition of an item, its `@source` will be used.
## Syntax
`@source <path>`
@@ -1260,7 +1260,7 @@ end
LUADOC_DESC_PRIVATE =
[=[
Mark a function as private to a @class. Private functions can be accessed only
-from within their class and are not accessable from child classes.
+from within their class and are not accessible from child classes.
## Syntax
`@private`
diff --git a/meta/template/basic.lua b/meta/template/basic.lua
index e646d3b8..4a9360fd 100644
--- a/meta/template/basic.lua
+++ b/meta/template/basic.lua
@@ -8,6 +8,7 @@ arg = {}
---@generic T
---@param v? T
---@param message? any
+---@param ... any
---@return T
---@return any ...
function assert(v, message, ...) end
@@ -30,6 +31,7 @@ function assert(v, message, ...) end
---#if VERSION >= 5.4 then
---#DES 'collectgarbage'
---@param opt? gcoptions
+---@param ... any
---@return any
function collectgarbage(opt, ...) end
---#else
@@ -136,6 +138,7 @@ function newproxy(proxy) end
---@version 5.1
---#DES 'module'
---@param name string
+---@param ... any
function module(name, ...) end
---#DES 'next'
@@ -161,12 +164,14 @@ function pairs(t) end
---@param f async fun(...):...
---#end
---@param arg1? any
+---@param ... any
---@return boolean success
---@return any result
---@return any ...
function pcall(f, arg1, ...) end
---#DES 'print'
+---@param ... any
function print(...) end
---#DES 'rawequal'
@@ -198,6 +203,7 @@ function rawset(table, index, value) end
---#DES 'select'
---@param index integer|"#"
+---@param ... any
---@return any
---@nodiscard
function select(index, ...) end
@@ -245,6 +251,9 @@ function setfenv(f, table) end
---#if VERSION == JIT or VERSION == 5.2 then
---@field __ipairs (fun(t):(fun(t,k,v):(integer|nil),any))|nil
---#end
+---#if VERSION >= 5.4 then
+---@field __close (fun(t,errobj):any)|nil
+---#end
---#DES 'setmetatable'
---@param table table
@@ -298,6 +307,7 @@ _VERSION = "Lua 5.4"
---@version >5.4
---#DES 'warn'
---@param message string
+---@param ... any
function warn(message, ...) end
---#if VERSION == 5.1 and not JIT then
@@ -313,6 +323,7 @@ function xpcall(f, err) end
---@param f async fun(...):...
---@param msgh function
---@param arg1? any
+---@param ... any
---@return boolean success
---@return any result
---@return any ...
diff --git a/meta/whimsical/basic.lua b/meta/whimsical/basic.lua
index 8f25d19f..9075a0e9 100644
--- a/meta/whimsical/basic.lua
+++ b/meta/whimsical/basic.lua
@@ -11,7 +11,7 @@ arg = {}
---@param ... any
---@return T
---@return any ... => args[reti + 1]
----@error => args[1].istruly
+---@throw => args[1].isFalsy
---@narrow v => args[1].truly
function assert(v, message, ...) end
@@ -36,3 +36,15 @@ function assert(v, message, ...) end
---@prototype
]]
function collectgarbage(...) end
+
+---#DES 'dofile'
+---@param filename? string
+---@return any
+---@custom dofile
+function dofile(filename) end
+
+---#DES 'error'
+---@param message any
+---@param level? integer
+---@throw
+function error(message, level) end
diff --git a/meta/whimsical/builtin.lua b/meta/whimsical/builtin.lua
index 6521bb4b..17905798 100644
--- a/meta/whimsical/builtin.lua
+++ b/meta/whimsical/builtin.lua
@@ -1,110 +1,13 @@
---@meta _
---[[@@@
----@inner class -> {
- self.istruly = true
- self.truly = self
- self.falsy = Class 'never'
- self.view = self.name
-}
----@inner integer -> {
- self.istruly = true
- self.truly = self
- self.falsy = Class 'never'
- self.view = tostring(self.value)
-}
----@inner string -> {
- self.istruly = true
- self.truly = self
- self.falsy = Class 'never'
- self.view = cat.util.viewString(self.value, self.quotation)
-}
----@inner union -> {
- self.istruly = function (subs)
- local istruly = subs[1].istruly
- if istruly == nil then
- return nil
- end
- if istruly == true then
- for i = 2, #subs do
- if subs[i].istruly ~= true then
- return nil
- end
- end
- return true
- else
- for i = 2, #subs do
- if subs[i].istruly ~= false then
- return nil
- end
- end
- return false
- end
- return nil
- end
- self.truly = function (subs)
- local union = Union()
- for i = 1, #subs do
- union:add(subs[i].truly)
- end
- if union:len() == 0 then
- return Class 'never'
- end
- if union:len() == 1 then
- return union:first()
- end
- return union
- end
- self.falsy = function (subs)
- local union = Union()
- for i = 1, #subs do
- union:add(subs[i].falsy)
- end
- if union:len() == 0 then
- return Class 'never'
- end
- if union:len() == 1 then
- return union:first()
- end
- return union
- end
- self.view = function (subs)
- local views = {}
- for i = 1, #subs do
- views[i] = subs[i].view
- end
- if #views == 0 then
- return 'never'
- end
- return table.concat(views, '|')
- end
-}
----@class nil -> {
- self.istruly = false
- self.truly = Class 'never'
- self.falsy = self
-}
----@class never -> {
- self.istruly = nil
-}
----@class true -> {
- self.istruly = true
- self.truly = self
- self.falsy = Class 'never'
-}
----@class false -> {
- self.istruly = false
- self.truly = Class 'never'
- self.falsy = self
-}
----@class any: { [unknown]: any } -> {
- self.istruly = nil
- self.truly = Class 'truly'
- self.falsy = Class 'false' | Class 'nil'
-}
+---@class nil
+---@class never
+---@class true
+---@class false
+---@class any: { [unknown]: any }
---@class truly: { [unknown]: any }
---@class unknown: truly | false
----@class boolean: true | false
+---@class boolean
---@class number
---@class thread
---@class table: { [unknown]: any }
@@ -113,4 +16,3 @@
---@class userdata: { [unknown]: any }
---@class lightuserdata
---@class function: fun(...): ...
-]]
diff --git a/meta/whimsical/rule.lua b/meta/whimsical/rule.lua
new file mode 100644
index 00000000..0715d78f
--- /dev/null
+++ b/meta/whimsical/rule.lua
@@ -0,0 +1,128 @@
+local cat
+
+cat.rule.default = function (self)
+ self.isTruly = true
+ self.truly = self
+ self.falsy = cat.class 'never'
+ self.view = self.name
+end
+
+cat.rule.never = function (self)
+ self.isTruly = nil
+end
+
+cat.rule.any = function (self)
+ self.isTruly = nil
+ self.truly = cat.class 'truly'
+ self.falsy = cat.boolean(false) | cat.class 'nil'
+end
+
+cat.rule['nil'] = function (self)
+ self.isTruly = false
+ self.truly = cat.class 'never'
+ self.falsy = self
+end
+
+cat.rule.boolean = function (self)
+ if self.value == true then
+ self.isTruly = true
+ self.truly = self
+ self.falsy = cat.class 'never'
+ elseif self.value == false then
+ self.isTruly = false
+ self.truly = cat.class 'never'
+ self.falsy = self
+ else
+ self.isTruly = nil
+ self.truly = cat.boolean(true)
+ self.falsy = cat.boolean(false)
+ end
+end
+
+cat.rule.number = function (self)
+ self.isTruly = true
+ self.truly = self
+ self.falsy = cat.class 'never'
+ self.view = tostring(self.value)
+end
+
+cat.rule.integer = function (self)
+ self.isTruly = true
+ self.truly = self
+ self.falsy = cat.class 'never'
+ self.view = tostring(self.value)
+end
+
+cat.rule.string = function (self)
+ self.isTruly = true
+ self.truly = self
+ self.falsy = cat.class 'never'
+ self.view = cat.util.viewString(self.value, self.quotation)
+end
+
+cat.rule.union = function (self)
+ self.isTruly = function (union)
+ local isTruly = union.subs[1].isTruly
+ if isTruly == nil then
+ return nil
+ end
+ if isTruly == true then
+ for i = 2, #union.subs do
+ if union.subs[i].isTruly ~= true then
+ return nil
+ end
+ end
+ return true
+ else
+ for i = 2, #union.subs do
+ if union.subs[i].isTruly ~= false then
+ return nil
+ end
+ end
+ return false
+ end
+ return nil
+ end
+ self.truly = function (union)
+ local new = cat.union()
+ for i = 1, #union.subs do
+ new:add(union.subs[i].truly)
+ end
+ if new:len() == 0 then
+ return cat.class 'never'
+ end
+ if new:len() == 1 then
+ return new[1]
+ end
+ return new
+ end
+ self.falsy = function (union)
+ local new = cat.union()
+ for i = 1, #union.subs do
+ new:add(union.subs[i].falsy)
+ end
+ if new:len() == 0 then
+ return cat.class 'never'
+ end
+ if new:len() == 1 then
+ return new[1]
+ end
+ return new
+ end
+ self.view = function (union)
+ local views = {}
+ for i = 1, #union.subs do
+ views[i] = union.subs[i].view
+ end
+ if #views == 0 then
+ return 'never'
+ end
+ return table.concat(views, '|')
+ end
+end
+
+cat.custom.dofile.onReturn = function (context)
+ local filename = context.args[1].asString
+ local file = cat.files[filename]
+ return file.returns[1]
+end
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 5a61919c..4462bf64 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -2158,7 +2158,7 @@ local function tryluaDocByErr(state, position, err, docState, results)
end
end
-local function buildluaDocOfFunction(func)
+local function buildluaDocOfFunction(func, pad)
local index = 1
local buf = {}
buf[#buf+1] = '${1:comment}'
@@ -2182,7 +2182,8 @@ local function buildluaDocOfFunction(func)
local funcArg = func.args[n]
if funcArg[1] and funcArg.type ~= 'self' then
index = index + 1
- buf[#buf+1] = ('---@param %s ${%d:%s}'):format(
+ buf[#buf+1] = ('---%s@param %s ${%d:%s}'):format(
+ pad and ' ' or '',
funcArg[1],
index,
arg
@@ -2200,7 +2201,7 @@ local function buildluaDocOfFunction(func)
return insertText
end
-local function tryluaDocOfFunction(doc, results)
+local function tryluaDocOfFunction(doc, results, pad)
if not doc.bindSource then
return
end
@@ -2222,7 +2223,7 @@ local function tryluaDocOfFunction(doc, results)
end
end
end
- local insertText = buildluaDocOfFunction(func)
+ local insertText = buildluaDocOfFunction(func, pad)
results[#results+1] = {
label = '@param;@return',
kind = define.CompletionItemKind.Snippet,
@@ -2240,9 +2241,9 @@ local function tryLuaDoc(state, position, results)
end
if doc.type == 'doc.comment' then
local line = doc.originalComment.text
- -- 尝试 ---$
- if line == '-' then
- tryluaDocOfFunction(doc, results)
+ -- 尝试 '---$' or '--- $'
+ if line == '-' or line == '- ' then
+ tryluaDocOfFunction(doc, results, line == '- ')
return
end
-- 尝试 ---@$
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index eccf562a..a791e980 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -712,11 +712,11 @@ m.register 'completionItem/resolve' {
--await.setPriority(1000)
local state = files.getState(uri)
if not state then
- return nil
+ return item
end
local resolved = core.resolve(id)
if not resolved then
- return nil
+ return item
end
item.detail = resolved.detail or item.detail
item.documentation = resolved.description and {
diff --git a/test/completion/common.lua b/test/completion/common.lua
index bd317259..7de1c325 100644
--- a/test/completion/common.lua
+++ b/test/completion/common.lua
@@ -3864,6 +3864,12 @@ local x = function (x, y) end
(EXISTS)
TEST [[
+--- <??>
+local x = function (x, y) end
+]]
+(EXISTS)
+
+TEST [[
local x = {
<??>
})
diff --git a/test/plugins/ffi/test.lua b/test/plugins/ffi/test.lua
index f07e71c6..93be2ff5 100644
--- a/test/plugins/ffi/test.lua
+++ b/test/plugins/ffi/test.lua
@@ -2,6 +2,7 @@ local lclient = require 'lclient'
local ws = require 'workspace'
local furi = require 'file-uri'
local files = require 'files'
+local diagnostic = require 'provider.diagnostic'
--TODO how to changed the runtime version?
local template = require 'config.template'
@@ -24,15 +25,19 @@ end
---@async
lclient():start(function (languageClient)
languageClient:registerFakers()
- local rootUri = furi.encode '/'
+ local rootUri = TESTURI
languageClient:initialize {
rootUri = rootUri,
}
+ diagnostic.pause()
+
ws.awaitReady(rootUri)
require 'plugins.ffi.cdef'
require 'plugins.ffi.parser'
require 'plugins.ffi.builder'
TestBuilder()
+
+ diagnostic.resume()
end)