summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-15 18:04:16 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-15 18:04:16 +0800
commit82d716ccaa8ebab931fd2328faa4f4c5a76eb99a (patch)
treeaaebc8675ed44c172283b9979817bf023c29675e /script/core
parentac3235f4e9b800b0726a2e90555b109d5b58abfb (diff)
downloadlua-language-server-82d716ccaa8ebab931fd2328faa4f4c5a76eb99a.zip
resolve #1224 show comments for `doc.field`
Diffstat (limited to 'script/core')
-rw-r--r--script/core/hover/description.lua32
1 files changed, 22 insertions, 10 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index 5f5c50f6..32a0a798 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -125,7 +125,11 @@ local function getBindComment(source)
return table.concat(lines, '\n')
end
-local function lookUpDocComments(source, docGroup)
+local function lookUpDocComments(source)
+ local docGroup = source.bindDocs
+ if not docGroup then
+ return
+ end
if source.type == 'setlocal'
or source.type == 'getlocal' then
source = source.node
@@ -282,6 +286,9 @@ end
local function getFunctionComment(source)
local docGroup = source.bindDocs
+ if not docGroup then
+ return
+ end
local hasReturnComment = false
for _, doc in ipairs(source.bindDocs) do
@@ -329,23 +336,28 @@ local function getFunctionComment(source)
elseif doc.type == 'doc.overload' then
md:splitLine()
end
- ::CONTINUE::
end
local enums = getBindEnums(source, docGroup)
md:add('lua', enums)
- return md
+
+ local comment = md:string()
+ if comment == '' then
+ return nil
+ end
+ return comment
end
local function tryDocComment(source)
- if not source.bindDocs then
- return
- end
- if source.type ~= 'function' then
- local comment = lookUpDocComments(source, source.bindDocs)
- return comment
+ if source.type == 'function' then
+ local comment = getFunctionComment(source)
+ if comment then
+ return comment
+ end
+ source = source.parent
end
- return getFunctionComment(source)
+ local comment = lookUpDocComments(source)
+ return comment
end
local function tryDocOverloadToComment(source)