summaryrefslogtreecommitdiff
path: root/script/core/hover
diff options
context:
space:
mode:
authorCppCXY <812125110@qq.com>2024-02-22 20:29:13 +0800
committerCppCXY <812125110@qq.com>2024-02-22 20:29:13 +0800
commit9b6df71d97a70ee7179949ef9f15368cbf29dcbd (patch)
treebf7a7e62ed7c164a12bdce437c17262a5235bcec /script/core/hover
parent483fe246b6ae8c25d433aa15e43f04f0e71a74d5 (diff)
parent3e6fd3ce1f2f0528336ded939d776a29bbfaf2eb (diff)
downloadlua-language-server-9b6df71d97a70ee7179949ef9f15368cbf29dcbd.zip
Merge branch 'master' of github.com:CppCXY/lua-language-server
Diffstat (limited to 'script/core/hover')
-rw-r--r--script/core/hover/description.lua87
-rw-r--r--script/core/hover/label.lua10
2 files changed, 60 insertions, 37 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index f5890b21..75189b06 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -336,7 +336,7 @@ local function tryDocFieldComment(source)
end
end
-local function getFunctionComment(source)
+local function getFunctionComment(source, raw)
local docGroup = source.bindDocs
if not docGroup then
return
@@ -356,14 +356,14 @@ local function getFunctionComment(source)
if doc.type == 'doc.comment' then
local comment = normalizeComment(doc.comment.text, uri)
md:add('md', comment)
- elseif doc.type == 'doc.param' then
+ elseif doc.type == 'doc.param' and not raw then
if doc.comment then
md:add('md', ('@*param* `%s` — %s'):format(
doc.param[1],
doc.comment.text
))
end
- elseif doc.type == 'doc.return' then
+ elseif doc.type == 'doc.return' and not raw then
if hasReturnComment then
local name = {}
for _, rtn in ipairs(doc.returns) do
@@ -401,13 +401,13 @@ local function getFunctionComment(source)
end
---@async
-local function tryDocComment(source)
+local function tryDocComment(source, raw)
local md = markdown()
if source.value and source.value.type == 'function' then
source = source.value
end
if source.type == 'function' then
- local comment = getFunctionComment(source)
+ local comment = getFunctionComment(source, raw)
md:add('md', comment)
source = source.parent
end
@@ -429,7 +429,7 @@ local function tryDocComment(source)
end
---@async
-local function tryDocOverloadToComment(source)
+local function tryDocOverloadToComment(source, raw)
if source.type ~= 'doc.type.function' then
return
end
@@ -438,7 +438,7 @@ local function tryDocOverloadToComment(source)
or not doc.bindSource then
return
end
- local md = tryDocComment(doc.bindSource)
+ local md = tryDocComment(doc.bindSource, raw)
if md then
return md
end
@@ -477,38 +477,59 @@ local function tryDocEnum(source)
if not tbl then
return
end
- local md = markdown()
- md:add('lua', '{')
- for _, field in ipairs(tbl) do
- if field.type == 'tablefield'
- or field.type == 'tableindex' then
- if not field.value then
- goto CONTINUE
- end
- local key = guide.getKeyName(field)
- if not key then
- goto CONTINUE
- end
- if field.value.type == 'integer'
- or field.value.type == 'string' then
- md:add('lua', (' %s: %s = %s,'):format(key, field.value.type, field.value[1]))
+ if vm.docHasAttr(source, 'key') then
+ local md = markdown()
+ local keys = {}
+ for _, field in ipairs(tbl) do
+ if field.type == 'tablefield'
+ or field.type == 'tableindex' then
+ if not field.value then
+ goto CONTINUE
+ end
+ local key = guide.getKeyName(field)
+ if not key then
+ goto CONTINUE
+ end
+ keys[#keys+1] = ('%q'):format(key)
+ ::CONTINUE::
end
- if field.value.type == 'binary'
- or field.value.type == 'unary' then
- local number = vm.getNumber(field.value)
- if number then
- md:add('lua', (' %s: %s = %s,'):format(key, math.tointeger(number) and 'integer' or 'number', number))
+ end
+ md:add('lua', table.concat(keys, ' | '))
+ return md:string()
+ else
+ local md = markdown()
+ md:add('lua', '{')
+ for _, field in ipairs(tbl) do
+ if field.type == 'tablefield'
+ or field.type == 'tableindex' then
+ if not field.value then
+ goto CONTINUE
+ end
+ local key = guide.getKeyName(field)
+ if not key then
+ goto CONTINUE
+ end
+ if field.value.type == 'integer'
+ or field.value.type == 'string' then
+ md:add('lua', (' %s: %s = %s,'):format(key, field.value.type, field.value[1]))
+ end
+ if field.value.type == 'binary'
+ or field.value.type == 'unary' then
+ local number = vm.getNumber(field.value)
+ if number then
+ md:add('lua', (' %s: %s = %s,'):format(key, math.tointeger(number) and 'integer' or 'number', number))
+ end
end
+ ::CONTINUE::
end
- ::CONTINUE::
end
+ md:add('lua', '}')
+ return md:string()
end
- md:add('lua', '}')
- return md:string()
end
---@async
-return function (source)
+return function (source, raw)
if source.type == 'string' then
return asString(source)
end
@@ -518,10 +539,10 @@ return function (source)
if source.type == 'field' then
source = source.parent
end
- return tryDocOverloadToComment(source)
+ return tryDocOverloadToComment(source, raw)
or tryDocFieldComment(source)
or tyrDocParamComment(source)
- or tryDocComment(source)
+ or tryDocComment(source, raw)
or tryDocClassComment(source)
or tryDocModule(source)
or tryDocEnum(source)
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua
index 6ce4dde9..62e51927 100644
--- a/script/core/hover/label.lua
+++ b/script/core/hover/label.lua
@@ -134,7 +134,7 @@ local function asField(source)
end
local function asDocFieldName(source)
- local name = source.field[1]
+ local name = vm.viewKey(source, guide.getUri(source)) or '?'
local class
for _, doc in ipairs(source.bindGroup) do
if doc.type == 'doc.class' then
@@ -143,10 +143,12 @@ local function asDocFieldName(source)
end
end
local view = vm.getInfer(source.extends):view(guide.getUri(source))
- if not class then
- return ('(field) ?.%s: %s'):format(name, view)
+ local className = class and class.class[1] or '?'
+ if name:match(guide.namePatternFull) then
+ return ('(field) %s.%s: %s'):format(className, name, view)
+ else
+ return ('(field) %s%s: %s'):format(className, name, view)
end
- return ('(field) %s.%s: %s'):format(class.class[1], name, view)
end
local function asString(source)