diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/core/completion.lua | 8 | ||||
-rw-r--r-- | script/core/hover/description.lua | 32 | ||||
-rw-r--r-- | script/core/hover/init.lua | 1 | ||||
-rw-r--r-- | script/provider/markdown.lua | 22 |
4 files changed, 51 insertions, 12 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua index d65f4b3a..fe6ff2ef 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -245,12 +245,10 @@ local function buildDesc(source) local hover = getHover.get(source) local md = markdown() md:add('lua', hover.label) + md:splitLine() md:add('md', hover.description) - local snip = getSnip(source) - if snip then - md:add('md', '-------------') - md:add('lua', snip) - end + md:splitLine() + md:add('lua', getSnip(source)) return md:string() end diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 75c3ea9c..7c2af81f 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -104,6 +104,9 @@ local function getBindComment(source, docGroup, base) break else continue = false + if doc.type == 'doc.field' then + lines = nil + end end end if source.comment then @@ -266,19 +269,33 @@ local function getFunctionComment(source) return md:string() end +local function tryDocClassComment(source) + for _, def in ipairs(vm.getDefs(source, 0)) do + if def.type == 'doc.class.name' then + local class = guide.getDocState(def) + local comment = getBindComment(class, class.bindGroup, class) + if comment then + return comment + end + end + end + if source.bindDocs then + for _, doc in ipairs(source.bindDocs) do + if doc.type == 'doc.class' then + local comment = getBindComment(doc, source.bindDocs, doc) + return comment + end + end + end +end + local function tryDocComment(source) if not source.bindDocs then return end if not isFunction(source) then local comment = getBindComment(source, source.bindDocs) - if not comment then - return - end - local md = markdown() - md:add('md', "---") - md:add('md', comment) - return md:string() + return comment end return getFunctionComment(source) end @@ -334,4 +351,5 @@ return function (source) or tryDocFieldUpComment(source) or tyrDocParamComment(source) or tryDocComment(source) + or tryDocClassComment(source) end diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua index 28aef3e6..80c4db1e 100644 --- a/script/core/hover/init.lua +++ b/script/core/hover/init.lua @@ -6,6 +6,7 @@ local getDesc = require 'core.hover.description' local util = require 'utility' local findSource = require 'core.find-source' local lang = require 'language' +local markdown = require 'provider.markdown' local function eachFunctionAndOverload(value, callback) callback(value) diff --git a/script/provider/markdown.lua b/script/provider/markdown.lua index ca76ec89..ceaedfdb 100644 --- a/script/provider/markdown.lua +++ b/script/provider/markdown.lua @@ -2,10 +2,27 @@ local mt = {} mt.__index = mt mt.__name = 'markdown' +mt._splitLine = false + +local function checkSplitLine(self) + if not self._splitLine then + return + end + self._splitLine = nil + if #self == 0 then + return + end + + self[#self+1] = '---' +end + function mt:add(language, text) if not text or #text == 0 then return end + + checkSplitLine(self) + if language == 'md' then if self._last == 'md' then self[#self+1] = '' @@ -14,6 +31,7 @@ function mt:add(language, text) else self[#self+1] = ('```%s\n%s\n```'):format(language, text) end + self._last = language end @@ -21,6 +39,10 @@ function mt:string() return table.concat(self, '\n') end +function mt:splitLine() + self._splitLine = true +end + return function () return setmetatable({}, mt) end |