summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-09 20:00:05 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-09 20:00:05 +0800
commitd99c23af4bf8be944f58b374141dbfb81d48b5f5 (patch)
tree185e92fac5c0e28a80e772a9fdad5b0a6a4bbfd8
parentbc92c4dcefc0c87420c7d4b239c1eb4b9d14588c (diff)
downloadlua-language-server-d99c23af4bf8be944f58b374141dbfb81d48b5f5.zip
#1061 completion for `doc.type.code`
-rw-r--r--changelog.md9
-rw-r--r--script/core/completion/completion.lua12
-rw-r--r--script/core/hover/description.lua3
-rw-r--r--script/parser/guide.lua1
-rw-r--r--test/completion/common.lua34
5 files changed, 58 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md
index 1ff7e2cb..0f71fab5 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,14 @@
# changelog
+## 3.3.0
+* `NEW` `LuaDoc` supports `` `CODE` ``
+ ```lua
+ ---@type `CONST.X` | `CONST.Y`
+ local x
+
+ if x == -- suggest `CONST.X` and `CONST.Y` here
+ ```
+
## 3.2.5
`2022-6-9`
* `NEW` provide config docs in `LUA_LANGUAGE_SERVER/doc/`
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 009b4297..d7c210c6 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1136,6 +1136,12 @@ local function checkTypingEnum(state, position, defs, str, results)
description = def.comment and def.comment.text,
kind = define.CompletionItemKind.EnumMember,
}
+ elseif def.type == 'doc.type.code' then
+ enums[#enums+1] = {
+ label = def[1],
+ description = def.comment and def.comment.text,
+ kind = define.CompletionItemKind.EnumMember,
+ }
end
end
cleanEnums(enums, str)
@@ -1425,6 +1431,12 @@ local function tryCallArg(state, position, results)
description = src.comment,
kind = define.CompletionItemKind.EnumMember,
}
+ elseif src.type == 'doc.type.code' then
+ enums[#enums+1] = {
+ label = src[1],
+ description = src.comment,
+ kind = define.CompletionItemKind.EnumMember,
+ }
end
if src.type == 'doc.type.function' then
local insertText = buildInsertDocFunction(src)
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index e3c3f412..3fef1a21 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -155,7 +155,8 @@ local function buildEnumChunk(docType, name)
types[#types+1] = vm.getInfer(tp):view(guide.getUri(docType))
if tp.type == 'doc.type.string'
or tp.type == 'doc.type.integer'
- or tp.type == 'doc.type.boolean' then
+ or tp.type == 'doc.type.boolean'
+ or tp.type == 'doc.type.code' then
enums[#enums+1] = tp
end
local comment = tryDocClassComment(tp)
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 2bd9066b..83321bac 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -252,6 +252,7 @@ function m.isLiteral(obj)
or tp == 'doc.type.string'
or tp == 'doc.type.integer'
or tp == 'doc.type.boolean'
+ or tp == 'doc.type.code'
end
--- 获取字面量
diff --git a/test/completion/common.lua b/test/completion/common.lua
index 613f9b0c..1cdff803 100644
--- a/test/completion/common.lua
+++ b/test/completion/common.lua
@@ -3348,3 +3348,37 @@ local xyz
kind = define.CompletionItemKind.Variable,
}
}
+
+TEST [[
+---@type `CONST.X` | `CONST.Y`
+local x
+
+if x == <??>
+]]
+{
+ {
+ label = 'CONST.X',
+ kind = define.CompletionItemKind.EnumMember,
+ },
+ {
+ label = 'CONST.Y',
+ kind = define.CompletionItemKind.EnumMember,
+ },
+}
+
+TEST [[
+---@param x `CONST.X` | `CONST.Y`
+local function f(x) end
+
+f(<??>)
+]]
+{
+ {
+ label = 'CONST.X',
+ kind = define.CompletionItemKind.EnumMember,
+ },
+ {
+ label = 'CONST.Y',
+ kind = define.CompletionItemKind.EnumMember,
+ },
+}